EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER WHERE S_ACCTBAL = 100;
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 59 | 25 (0)| 00:00:01
|* 1 | TABLE ACCESS FULL| SUPPLIER | 1 | 59 | 25 (0)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("S_ACCTBAL"=100)
EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER WHERE S_SUPPKEY = 007;
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 57 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | SUPPLIER | 1 | 57 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SUPPLIER_PKEY| 1 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
2 - access("S_SUPPKEY"=007)
EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER WHERE S_SUPPKEY >= 7;
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2995 | 157K | 25 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| SUPPLIER | 2995 | 157K | 25 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("S_SUPPKEY">=7)
EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER WHERE S_SUPPKEY >= 7777;
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 54 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED | SUPPLIER | 1 | 54 | 3 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | SUPPLIER_PKEY| 1 | | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
2 - access("S_SUPPKEY">=7777)
EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER WHERE S_ACCTBAL = 0 AND S_PHONE = 1234567;
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 71 | 25 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| SUPPLIER | 1 | 71 | 25 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("S_ACCTBAL"=0 AND TO_NUMBER("S_PHONE")=1234567)
CREATE INDEX IDX1 ON SUPPLIER(S_ACCTBAL);
EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER WHERE S_ACCTBAL = 0 AND S_PHONE = 1234567;
------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 71 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID BATCHED | SUPPLIER | 1 | 71 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX1 | 1 | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
1 - filter(TO_NUMBER("S_PHONE")=1234567)
2 - access("S_ACCTBAL"=0)
EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER;
----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3000 | 149K| 25 (0)| 00:00:01 | | 1 | TABLE ACCESS FULL| SUPPLIER | 3000 | 149K| 25 (0)| 00:00:01 | -----------------------------------------------------------------------------
CREATE INDEX IDX3 ON SUPPLIER(S_NAME, S_ADDRESS);
EXPLAIN PLAN FOR SELECT S_NAME, S_ADDRESS FROM SUPPLIER;
--------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3000 | 149K | 9 (0) | 00:00:01 | | 1 | INDEX FAST FULL SCAN| IDX3 | 3000 | 149K | 9 (0) | 00:00:01 | ---------------------------------------------------------------------------
EXPLAIN PLAN FOR SELECT DISTINCT S_NATIONKEY FROM SUPPLIER;
------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 25 | 50 | 25 (0)| 00:00:01 | | 1 | HASH UNIQUE | | 25 | 50 | 25 (0)| 00:00:01 | | 2 | TABLE ACCESS FULL| SUPPLIER | 3000 | 6000 | 25 (0)| 00:00:01 | ------------------------------------------------------------------------------
for each block br ∈ r do
get(br);
for each block bs ∈ s do
get(bs);
use a condition φ to join all rows in br with all rows in bs
EXPLAIN PLAN FOR SELECT /*+ USE_NL(CUSTOMER ORDERS) */ * FROM ORDERS JOIN CUSTOMER ON ORDERS.O_TOTALPRICE = CUSTOMER.C_ACCTBAL WHERE O_TOTALPRICE < 5000;
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3807 | 996K | 1063K (1)| 00:00:42 |
| 1 | NESTED LOOPS | | 3807 | 996K | 1063K (1)| 00:00:42 |
|* 2 | TABLE ACCESS FULL| ORDERS | 3786 | 403K | 1949 (1)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| CUSTOMER | 1 | 159 | 280 (0)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
2 - filter("ORDERS"."O_TOTALPRICE"<5000)
3 - filter("ORDERS"."O_TOTALPRICE"="CUSTOMER"."C_ACCTBAL" AND
"CUSTOMER"."C_ACCTBAL"<5000 AND "CUSTOMER"."C_ACCTBAL">=0)
for each block br ∈ r do
get(br ); /* Assume that a relational table r fits in transient memory */
for each block bs ∈ s do
get(bs );
use a condition φ to join all rows in br with all rows in bs
for each block br ∈ r do
get(br ); /* Assume that relational table s is indexed on join attribute */
for each row t ∈ br do
traverse an index on s with a value of join attribute from t;
access table s and get all rows is selected through index scan;
use a condition φ to join a row t with all rows ∈ is;
EXPLAIN PLAN FOR SELECT /*+ ORDERED USE_NL(CUSTOMER) */ * FROM ORDERS JOIN CUSTOMER ON ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY;
----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 450K | 109M | 452K (1)| 00:00:18 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 450K | 109M | 452K (1)| 00:00:18 |
|* 3 | TABLE ACCESS FULL | ORDERS | 450K | 43M | 1950 (1)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | CUSTOMER_PKEY | 1 | | 0 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| CUSTOMER | 1 | 153 | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
3 - filter("ORDERS"."O_CUSTKEY">=0)
4 - access("ORDERS"."O_CUSTKEY"="CUSTOMER"."C_CUSTKEY")
sort table r over the attributes involved in join condition;
sort table s over the attributes involved in join condition;
merge sorted r and sorted s over a join condition;
EXPLAIN PLAN FOR
SELECT /*+ USE_MERGE(ORDERS,CUSTOMER) */ *
FROM ORDERS JOIN CUSTOMER
ON ORDERS.O_TOTALPRICE = CUSTOMER.C_ACCTBAL;
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 41034 | 10M | | 14724 (1)| 00:00:01 |
| 1 | MERGE JOIN | | 41034 | 10M | | 14724 (1)| 00:00:01 |
| 2 | SORT JOIN | | 40910 | 6352K | 14M| 1715 (1)| 00:00:01 |
|* 3 | TABLE ACCESS FULL | CUSTOMER| 40910 | 6352K | | 283 (1)| 00:00:01 |
|* 4 | SORT JOIN | | 450K | 46M | 115M| 13009 (1)| 00:00:01 |
| 5 | TABLE ACCESS FULL | ORDERS | 450K | 46M | | 1950 (1)| 00:00:01 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
3 - filter("CUSTOMER"."C_ACCTBAL">=0)
4 - access("ORDERS"."O_TOTALPRICE"="CUSTOMER"."C_ACCTBAL")
filter("ORDERS"."O_TOTALPRICE"="CUSTOMER"."C_ACCTBAL")
apply a hash function h to a join attribute in a table r to produce the hashed buckets bckr1, ... , bckrn from a table r;
apply a hash function h to a join attribute in a table s to produce the hashed buckets bcks1, ... , bcksn from a table s;
compute bckr1⨝ bcks1 , ... , bckrn⨝ bcksn
EXPLAIN PLAN FOR SELECT * FROM ORDERS JOIN CUSTOMER ON ORDERS.O_TOTALPRICE = CUSTOMER.C_ACCTBAL;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 41034 | 10M | | 5140 (1)| 00:00:01 |
|* 1 | HASH JOIN | | 41034 | 10M | 6832K | 5140 (1)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| CUSTOMER| 40910 | 6352K | | 283 (1)| 00:00:01 |
| 3 | TABLE ACCESS FULL| ORDERS | 450K | 46M | | 1950 (1)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("ORDERS"."O_TOTALPRICE"="CUSTOMER"."C_ACCTBAL")
2 - filter("CUSTOMER"."C_ACCTBAL">=0)
logically split table r into two partitions r1 and r2
for each partition p ∈ {r1, r2} do
apply a hash function h to join attribute in a table r to produce the hashed buckets bckp1 , ... , bckpn of a partition p;
for each block bs ∈ s do
apply a hash function h to join attribute in each row v ∈ bs to find a number of bucket j
compute v ⨝ bckpj;
apply a hash function h to entire rows in a table r to produce the hashed buckets bckr1 , ... , bckrn from a table r;
apply a hash function h to entire rows in a table s to produce the hashed buckets bcks1 , ... , bcksn from a table s;
compute bckr1 ∪ bcks1 , … , bckrn ∪ bcksn
EXPLAIN PLAN FOR SELECT O_TOTALPRICE FROM ORDERS WHERE O_TOTALPRICE > 100 UNION SELECT O_TOTALPRICE FROM ORDERS WHERE O_TOTALPRICE < 10;
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 450K| 2636K| | 5356 (37)| 00:00:01 |
| 1 | SORT UNIQUE | | 450K| 2636K| 5304K| 5356 (37)| 00:00:01 |
| 2 | UNION-ALL | | | | | | |
|* 3 | TABLE ACCESS FULL| ORDERS| 450K| 2636K| | 1949 (1)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| ORDERS| 1 | 6 | | 1949 (1)| 00:00:01 |
-----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("O_TOTALPRICE">100)
4 - filter("O_TOTALPRICE"<10)
apply a hash function h to entire rows in a table r to produce the hashed buckets bckr1 , ... , bckrn from a table r;
apply a hash function h to entire rows in a table s to produce the hashed buckets bcks1 , … , bcksn from a table s;
compute bckr1 - bcks1 , ... , bckrn - bcksn
EXPLAIN PLAN FOR SELECT O_TOTALPRICE FROM ORDERS WHERE O_TOTALPRICE < 100 MINUS SELECT O_TOTALPRICE FROM ORDERS WHERE O_TOTALPRICE > 10;
------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2636K| | 5356 (64)| 00:00:01 |
| 1 | MINUS | | | | | | |
| 2 | SORT UNIQUE | | 1 | 6 | | 1949 (1)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| ORDERS | 1 | 6 | | 1949 (1)| 00:00:01 |
| 4 | SORT UNIQUE | | 450K| 2636K| 5304K| 3407 (1)| 00:00:01 |
|* 5 | TABLE ACCESS FULL| ORDERS | 450K| 2636K| | 1949 (1)| 00:00:01 |
------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("O_TOTALPRICE"<100)
5 - filter("O_TOTALPRICE">10)
apply a hash function h to entire rows in a table r to produce the hashed buckets bckr1, ... , bckrn from a table r;
apply a hash function h to entire rows in a table s to produce the hashed buckets bcks1, ... , bcksn from a table s;
compute bckr1 ∩ bcks1 , ... , bckrn ∩ bcksn
EXPLAIN PLAN FOR SELECT O_TOTALPRICE FROM ORDERS WHERE O_TOTALPRICE < 100 INTERSECT SELECT O_TOTALPRICE FROM ORDERS WHERE O_TOTALPRICE > 10;
------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2636K| | 5356 (64)| 00:00:01 |
| 1 | INTERSECTION | | | | | | |
| 2 | SORT UNIQUE | | 1 | 6 | | 1949 (1)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| ORDERS | 1 | 6 | | 1949 (1)| 00:00:01 |
| 4 | SORT UNIQUE | | 450K| 2636K| 5304K| 3407 (1)| 00:00:01 |
|* 5 | TABLE ACCESS FULL| ORDERS | 450K| 2636K| | 1949 (1)| 00:00:01 |
------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("O_TOTALPRICE"<100)
5 - filter("O_TOTALPRICE">10)
apply a hash function h to a antijoin attribute in a table r to produce the hashed buckets bckr1, ... , bckrn from a table r;
apply a hash function h to antijoin attribute in a table s to produce the hashed buckets bcks1, ... , bcksn from a table s;
compute bckr1 ~φ bcks1 , ... , bckrn ~φ bcksn
EXPLAIN PLAN FOR
SELECT *
FROM CUSTOMER
WHERE C_CUSTKEY NOT IN (SELECT O_CUSTKEY
FROM ORDERS);
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes| TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14838 | 2376K| | 2960 (1)| 00:00:01 |
|* 1 | HASH JOIN RIGHT ANTI | | 14838 | 2376K| 7472K| 2960 (1)| 00:00:01 |
|* 2 | TABLE ACCESS FULL | ORDERS | 450K| 2197K| | 1949 (1)| 00:00:01 |
| 3 | TABLE ACCESS FULL | CUSTOMER | 45000 | 6987K| | 283 (1)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("C_CUSTKEY"="O_CUSTKEY")
2 - filter("O_CUSTKEY">=0)
for each block br ∈ r do
get(br);
for each block bs ∈ s do
get(bs);
conctenate all rows in br with all rows in bs
EXPLAIN PLAN FOR SELECT * FROM CUSTOMER CROSS JOIN ORDERS;
------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes| Cost (%CPU)| Time | ------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 20G| 5054G| 87M (1)| 00:57:05 | | 1 | MERGE JOIN CARTESIAN | | 20G| 5054G| 87M (1)| 00:57:05 | | 2 | TABLE ACCESS FULL | CUSTOMER| 45000| 6987K| 283 (1)| 00:00:01 | | 3 | BUFFER SORT | | 450K| 46M| 87M (1)| 00:57:05 | | 4 | TABLE ACCESS FULL | ORDERS | 450K| 46M| 1948 (1)| 00:00:01 | -------------------------------------------------------------------------------