Oracle Plan Operation FILTER for Uncorrelated Subqueries
Create two demonstration tables and fille them with some dummy data:
create table tq84_A (id integer, tx varchar2(10));
create table tq84_B (id integer, val number);
begin
insert into tq84_A values(1, 'A');
insert into tq84_A values(2, 'B');
insert into tq84_A values(3, 'C');
insert into tq84_B values(10, 5 );
insert into tq84_B values(20, 2 );
insert into tq84_B values(30, 4 );
end;
/
explain plan for
select
*
from
tq84_A
where
exists (
select
null
from
tq84_B
where
val = 6
);
select * from table(dbms_xplan.display(format=>'basic'));
--
-- -------------------------------------
-- | Id | Operation | Name |
-- -------------------------------------
-- | 0 | SELECT STATEMENT | |
-- | 1 | FILTER | |
-- | 2 | TABLE ACCESS FULL| TQ84_A |
-- | 3 | TABLE ACCESS FULL| TQ84_B |
-- -------------------------------------
Run the query and show if a row source was started. Because the subquery does not return a record, the SQL executor does not have run («start») the full table access on tq84_A:
Run a version of the query where the subquery returns a row and thus makes the outer query return all records of tq84_A (the corresponding full table access is «started»):