Today, the MERGE operation is based on two large tables about 10 Gb per table, update, the server uses a PCI-E flash disk, the speed is still quite fast, probably the statement
Today, the MERGE operation is based on two large tables about 10 Gb per table, update, the server uses a PCI-E flash disk, the speed is still quite fast, probably the statement
Today, the MERGE operation is based on two large tables about 10 Gb per table, update, the server uses a PCI-E flash disk, the speed is still quite fast, probably the statement is as follows:
Merge into TEST_EVENT
Using
TEST_EVENT_1 B
On (a. MAIN_TARGET = B. MAIN_TARGET and a. EVENT_TYPE = B. EVENT_TYPE)
When matched then
Update
Set
A. CARD_NO = B. CARD_NO, a. EVENT_ACCOUNT = B. EVENT_ACCOUNT, a. EXTEND_PROPERTIES = B. EXTEND_PROPERTIES
Where
B. EVENT_NAME = 'withhdraw' AND B. EVENT_TYPE IN ('synchronize ', 'asynchronize ')
AND
B. raw_add_time> = to_date ('1970-01-01 ', 'yyyy-mm-dd ')
AND
B. raw_add_time
There are two problems:
1. Unstable merge connections
Error
ORA-30926: unable to get a set of stable rows in the source table
MERGE is a deterministic statement. You therefore need to evaluate the data returned
The USING clause to ensure that there are no duplicate values in the join. Modify
The merge statement to include a deterministic where clause.
Example
SQL> select * from testmerg;
ID NAME
-------------------------------
1 gaopeng
2 gaopeng
3 gaopeng
SQL> select * from testmerg2;
ID NAME
-------------------------------
1 yanlei
2 yanlei
2 yanlei1
SQL>
SQL> merge into testmerg
2 using testmerg2 B
3 on (a. id = B. id)
4 when matched then update
5 set a. name = B. name;
Merge into testmerg
Using testmerg2 B
On (a. id = B. id)
When matched then update
Set a. name = B. name
ORA-30926: unable to get a set of stable rows in the source table
We can see that we connect by ID (. id = B. but the source table id has two rows whose ID is 2. Therefore, MERGE does not know how to modify the row ID = 2 gaopeng to yanlei, or yanlei1?
Therefore, MERGE should pay attention to this. If this condition cannot be met, MERGE cannot.
2. merge temporary tablespace is too large, and a large number of direct path read temp wait events occur.
Explanation:
================
We might consume more temp space on disk only when the build side (the smaller
Side in hash join) can't be fit in memory entirely. If it fits in memory, we
Don't need any buffering for the probe side (the rightside ).
If the staging table (smaller table participant ipating in the hash join)
Is too big to fit into the build side (in memory ),
The right hand side's hash partitions need to be buffered, and thus
Huge temp segments requirement.
If the hash area size is large enough to accomodate the build side in memory, you
Shocould not see this type of consumption.
As explained above,
SQL> select SQL _ID, BLOCKS * 8/1024/1024, SEGTYPE from v $ sort_usage;
SQL _ID BLOCKS * 8/1024/1024 SEGTYPE
----------------------------------------
08mh0r0xsj3h6 0.0009765625 DATA
08mh0r0xsj3h6 0.0009765625 LOB_DATA
08mh0r0xsj3h6 0.0009765625 INDEX
Dyk4dprp70d74 7.0634765625 HASH
As shown below, the HASH type is about 7 GB, And the execution plan is displayed.
PLAN_TABLE_OUTPUT
------------------------------------------------------------
Plan hash value: 3625956359
------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------
| 0 | merge statement | 2680K | 7953M |
| 1 | MERGE | SYN_EVENT |
| 2 | VIEW |
| * 3 | hash join | 2680K | 4605M |
| 4 | table access full | SYN_EVENT_1 | 2680K | 2259M |
| 5 | table access full | SYN_EVENT | 21M | 18g |
------------------------------------------------------------
We can see that the increase in the temporary tablespace comes from hash jion. In fact, hash jion is not the only one of MERGE.
Link Method. Because hash jion cannot use an index, the following prompt is displayed if you want to use USE_NL for an index:
Merge/* + leading (B) use_nl (a B) */into SYN_EVENT
Using SYN_EVENT_1 B
On (a. id = B. id)
When matched then
Update
Set a. CARD_NO = B. CARD_NO,
A. EVENT_ACCOUNT = B. EVENT_ACCOUNT,
A. EXTEND_PROPERTIES = B. EXTEND_PROPERTIES
Where B. EVENT_NAME = 'withraw'
AND B. EVENT_TYPE IN ('synchronize ', 'asynchronize ')
AND B. raw_add_time> = to_date ('1970-01-01 ', 'yyyy-mm-dd ')
AND B. raw_add_time <to_date ('1970-01-01 ', 'yyyy-mm-dd ');
However, we only use nest loop to replace hash jion. The drive table of nest loop can use indexes. We can test that TEMPSPACE is actually from hash jion.
Test syn_event on my machine. The syn_event data volume is about 750 GB, And the SYN_EVENT_1 data volume is about GB. The data contains the CLOB field for update. It takes about S to change the execution plan.