用merge into进行性能优化
有时候开发组有这么一个需求,一个表和它的备份表,把备份表中的某些字段替换到原表中,当数据量非常大的时候就很很慢,这个时候
有时候开发组有这么一个需求,一个表和它的备份表,把备份表中的某些字段替换到原表中,当数据量非常大的时候就很很慢,这个时候如果我们用merge into往往会提高几倍的性能,下面我们来做个实验:
SQL> drop table test1 purge;
表已删除。
SQL> drop table test2 purge;
表已删除。
SQL> create table test1 as select * from dba_objects;
表已创建。
SQL> alter table test1 nologging;
表已更改。
SQL> begin
2 for i in 1 .. 5 loop
3 insert /*+append*/
4 into test1
5 select * from dba_objects;
6 commit;
7 end loop;
8 end;
9 /
PL/SQL 过程已成功完成。
SQL> update test1 set object_id = rownum;
已更新303258行。
SQL> commit;
提交完成。
SQL> create table test2 as select * from test1;
表已创建。
SQL> select count(*) from test1;
COUNT(*)
----------
303258
SQL> select count(*) from test2;
COUNT(*)
----------
303258
SQL> create index ind_object_id1 on test1(object_id) nologging;
索引已创建。
SQL> create index ind_object_id2 on test2(object_id) nologging;
索引已创建。
SQL> exec dbms_stats.gather_table_stats(user,'test1');
PL/SQL 过程已成功完成。
SQL> exec dbms_stats.gather_table_stats(user,'test2');
PL/SQL 过程已成功完成。
SQL> set timing on
SQL> set autotrace traceonly
SQL> update test1 t1
2 set t1.object_type = (select object_type
3 from test2 t2
4 where t1.object_id = t2.object_id);
已更新303258行。
已用时间: 00: 00: 13.07
执行计划
----------------------------------------------------------
Plan hash value: 2560893763
-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT | | 303K| 4146K| 949 (2)| 00:00:12 |
| 1 | UPDATE | TEST1 | | | | |
| 2 | TABLE ACCESS FULL | TEST1 | 303K| 4146K| 949 (2)| 00:00:12 |
| 3 | TABLE ACCESS BY INDEX ROWID| TEST2 | 1 | 14 | 4 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | IND_OBJECT_ID2 | 1 | | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("T2"."OBJECT_ID"=:B1)
统计信息
----------------------------------------------------------
330 recursive calls
338515 db block gets
1250542 consistent gets
1 physical reads
107333692 redo size
673 bytes sent via SQL*Net to client
701 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
303258 rows processed
SQL> commit;
提交完成。
已用时间: 00: 00: 00.00
SQL> merge into test1 t1
2 using test2 t2
3 on (t1.object_id = t2.object_id)
4 when matched then
5 update set t1.object_type = t2.object_type;
303258 行已合并。
已用时间: 00: 00: 03.87
执行计划
----------------------------------------------------------
Plan hash value: 520388833
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | MERGE STATEMENT | | 303K| 5923K| | 4947 (2)| 00:01:00 |
| 1 | MERGE | TEST1 | | | | | |
| 2 | VIEW | | | | | | |
|* 3 | HASH JOIN | | 303K| 53M| 30M| 4947 (2)| 00:01:00 |
| 4 | TABLE ACCESS FULL| TEST2 | 303K| 26M| | 957 (3)| 00:00:12 |
| 5 | TABLE ACCESS FULL| TEST1 | 303K| 26M| | 957 (3)| 00:00:12 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
统计信息
----------------------------------------------------------
378 recursive calls
310584 db block gets
8547 consistent gets
3751 physical reads
76712320 redo size
678 bytes sent via SQL*Net to client
671 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
303258 rows processed
SQL> commit;
提交完成。
更多

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

PrimeFactor−Innumbertheory,theprimefactorsofapositiveintegeraretheprimenumbersthatdividethatintegerexactly.Theprocessoffindingthesenumbersiscalledintegerfactorization,orprimefactorization.Example−Primefactorsof288are:288=2x2x2x2x2

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

This article recommends ten digital currency trading apps: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Poloniex. When choosing a platform, you need to consider factors such as security, liquidity, transaction fees, currency selection, user interface, customer service support and regulatory compliance, and carefully evaluate risks and never blindly follow the trend.

This article provides Android and Apple mobile APP download methods for mainstream digital currency trading platforms such as Binance, OKX, Gate.io, Huobi Global, Coinbase, KuCoin, Kraken and Bitfinex. Whether it is an Android user or an Apple user, you can easily find the official APP download link for the corresponding platform and complete the installation according to the steps. The article provides detailed guidance on searching and downloading on their respective official websites or app stores, and provides instructions on the special steps for installing APK files on Android, so that users can download and use them quickly and easily.

Reliable digital currency platforms include: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini. These exchanges have their own characteristics. Users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

The rankings of the top ten virtual currency trading platforms are: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Gemini. The ranking is based on comprehensive considerations such as platform liquidity, currency selection, security, user experience, handling fees and compliance, but is for reference only. Investment should be cautious and at your own risk.
