Platform environment: suk: linuxas4oracle9201primary: windowsxporacle10.2.0.3 first create test data on the primary database. SQLcreatetabletestasselect * fromdba_objects; Tablecreated. SQLinsertintotestselect * fromtest; 9873rowscreated. SQ
Platform environment: suk: linux as4 oracle 9201 primary: windows xp oracle 10.2.0.3 first create test data on the primary database. SQL create table test as select * from dba_objects; Table created. SQL insert into test select * from test; 9873 rows created. SQ
Platform environment:
Suk: linux as4 + oracle 9201
Primary: windows xp + oracle 10.2.0.3
First, create test data on the primary database.
SQL> create table test as select * from dba_objects;
Table created.
SQL> insert into test select * from test;
9873 rows created.
SQL>/
19746 rows created.
SQL>/
39492 rows created.
SQL>/
78984 rows created.
SQL>/
157968 rows created.
SQL>/
315936 rows created.
SQL> commit;
Commit complete.
The following operations are performed on the suk database:
I. Example 1: first look at the two tables at the (Same) remote end.
Suk @ ORACLE9I> select owner, count (1) fromtest @ primary, dual @ primary group by owner;
Eight rows have been selected.
Used time: 00: 00: 00.87
Execution Plan
----------------------------------------------------------
0 select statement (REMOTE) Optimizer = ALL_ROWS (Cost = 1824 Card
= 670910 Bytes = 11405470)
1 0 HASH (group by) (Cost = 1824 Card = 670910 Bytes = 11405470)
2 1 nested loops (Cost = 1758 Card = 670910 Bytes = 11405470)
3 2 fast dual (Cost = 2 Card = 1)
4 2 table access (FULL) OF 'test' (TABLE) (Cost = 1756 Card = PRIMARY
670910 Bytes = 11405470)
Suk @ ORACLE9I> select/* + rule */owner, count (1) fromtest @ primary, dual @ primary group by owner;
Eight rows have been selected.
Used time: 00: 00: 00.89
Execution Plan
----------------------------------------------------------
0 select statement (REMOTE) Optimizer = HINT: RULE
1 0 SORT (group)
2 1 NESTED LOOPS
3 2 FAST DUAL
4 2 table access (FULL) OF 'test' (TABLE) PRIMARY
The preceding two examples show that, whether it is CBO or RBO, if the tables involved in SQL are all remote, the statement is executed remotely and the call end is returned after the result is obtained.
This can be seen from the select statement (REMOTE) of the Execution Plan.
Q: If the two tables in this example come from two different remote databases, where will the table join operation take place for the two tables? Is the local database that submits the SQL statement [tend to this], or one of two different remote databases?
Note: select statement (REMOTE) is the root operation of all operations in the preceding execution plan, that is, the first operation initiated by this execution plan. Subsequent operations are produced by this plan, it is a programmatic source operation. The REMOTE in select statement (REMOTE) of the source operation indicates that the execution plan of the source operation is from the REMOTE database, rather than the execution plan executed on the local database. The absence of REMOTE in the select statement of the source operation indicates that the execution plan of the source operation is from the local database, not the execution plan executed on the REMOTE database.
2. Example 2: Two Queries that contain local and remote tables
Then let's look at two queries that contain local and remote tables:
Suk @ ORACLE9I> select owner, count (1) fromtest @ primary, dual group by owner;
Eight rows have been selected.
Used time: 00: 00: 03.92
Execution Plan
----------------------------------------------------------
0 select statement Optimizer = CHOOSE
1 0 SORT (group)
2 1 NESTED LOOPS
3 2 table access (FULL) OF 'dual'
4 2 REMOTE * PRIMARY
4 SERIAL_FROM_REMOTE SELECT "OWNER" FROM "TEST" "TEST"
Suk @ ORACLE9I> select/* + rule */owner, count (1) fromtest @ primary, dual group by owner;
Eight rows have been selected.
Used time: 00: 00: 03.45
Execution Plan
----------------------------------------------------------
0 select statement Optimizer = HINT: RULE
1 0 SORT (group)
2 1 NESTED LOOPS
3 2 table access (FULL) OF 'dual'
4 2 REMOTE * PRIMARY
4 SERIAL_FROM_REMOTE SELECT "OWNER" FROM "TEST" "TEST"
From the preceding two execution results, we can see that both CBO and RBO queries contain local and remote tables, oracle always first transmits data from the remote table to the SQL initiator through the network, and then associates the data with the local table to obtain the final result.
From select statement and SERIAL_FROM_REMOTE SELECT "OWNER" FROM "TEST" "TEST", we can see that SQL is executed locally after obtaining remote data.
Question: If two tables perform the union all operation, oracle always first transfers data from the remote table to the SQL initiator through the network, do I perform the union all operation with the local table to get the final result?
At the same time, pay attention to the following phenomenon: if all the tables involved in SQL are at the remote end, it takes less than 1 second for SQL. If a table is at the local end and a table is at the remote end, it takes more than 3 seconds to return the same result SQL.
Note that in such distributed transactions, it is meaningless to check the resource consumption statistics of the execution plan, because it is local (the SQL initiator) the resource consumption of the remote database is unknown. This sentence isExample 2: Two Queries that contain local and remote tablesFor exampleExample 1: first, both tables are at the (Same) remote end.The Resource Consumption Statistics Section of the execution plan is meaningful, because the execution plan comes from the remote database, so you naturally know the resource consumption of the remote database.
Iii. hint: Application of driving_site to Distributed Query Optimization
At this point, many people may think: if the local table is small, the remote table (which is an accurate data source) is large, and the returned results are small, the remote table (large table) transferring to a local device will cause a large amount of resource consumption.
Obviously, to solve this problem, it is best to transmit the local table data to the remote end, and then let the SQL statement be executed remotely. After the result is obtained, it is returned to the SQL initiator.
Fortunately, oracle provides an hint to handle this situation: driving_site
Next we will use this hint to test it:
Suk @ ORACLE9I> select/* + driving_site (test) */owner, count (1) fromtest @ primary, dual group by owner;
Eight rows have been selected.
Used time: 00: 00: 01.25
Execution Plan
----------------------------------------------------------
0 select statement (REMOTE) Optimizer = ALL_ROWS (Cost = 8404591 C
Ard = 5479992102 Bytes = 93159865734)
1 0 HASH (group by) (Cost = 8404591 Card = 5479992102 Bytes = 931598
65734)
2 1 merge join (CARTESIAN) (Cost = 7524913 Card = 5479992102 Byt
Es = 93159865734)
3 2 table access (FULL) OF 'test' (TABLE) (Cost = 1756 Card = PRIMARY
670910 Bytes = 11405470)
4 2 BUFFER (SORT) (Cost = 8402834 Card = 8168)
5 4 REMOTE * OF 'dual' (REMOTE) (Cost = 11 Card = 8168 )!
5 SERIAL_FROM_REMOTE SELECT 0 FROM "SYS". "DUAL" "A1"
Suk @ ORACLE9I> select/* + rule driving_site (test) */owner, count (1) fromtest @ primary, dual group by o
Wner;
Eight rows have been selected.
Used time: 00: 00: 00.71
Execution Plan
----------------------------------------------------------
0 select statement (REMOTE) Optimizer = HINT: RULE
1 0 SORT (group)
2 1 NESTED LOOPS
3 2 REMOTE * OF 'dual' (REMOTE )!
4 2 table access (FULL) OF 'test' (TABLE) PRIMARY
3 SERIAL_FROM_REMOTE SELECT 0 FROM "SYS". "DUAL" "A1"
Note the changes in select statement (REMOTE) and SERIAL_FROM_REMOTE SELECT 0 FROM "SYS". "DUAL" "A1" with previous test examples.
From the above two examples, we can see that after driving_site is used, oracle will execute SQL statements on the database specified by the hint, and then return the results to the SQL initiator. This HINT applies to both CBO and RBO.
Summary:
1. Whether it is CBO or RBO, if the tables involved in SQL are all remote, the statement is executed remotely and the call end is returned after the result is obtained.
2. Whether it is CBO or RBO, when querying a query that contains a local table or a remote table, oracle always first transfers data from the remote table to the SQL initiator through the network, associate with the local table to obtain the final result.
3. You can use the hint driving_site to execute the SQL statement at that end. This hints is very useful for Distributed Query Optimization under certain conditions.