Search notes:

Oracle SQL Plan operation: Nested NESTED LOOPS

Nested nested-loops is a technique designed to optimize an «ordinary» nested loop. Some sources seem to refer to nested nested-loops as «nested join loop batching».
create table tq84_P (
   id         number,
   val_1      varchar2(  10),
   val_2      varchar2(1000),
   --
   constraint tq84_P_pk primary key(id)
);


create table tq84_C (
   col_1      number,
   col_2      varchar2(20),
   id_p       not null,
   --
   constraint tq84_C_fk foreign key (id_p) references tq84_P
);


begin
   dbms_random.seed(42);
end;
/


insert into tq84_P
select
   mod(773*level, 1009), -- 773 and 1009 are primes
   dbms_random.string('a', 10),
   rpad('x', 1000, 'x')
from
   dual connect by level <= 1009;


insert into tq84_C
select
   round(dbms_random.value(1,1000), 1),
   dbms_random.string('a', 20),
   trunc(dbms_random.value(100, 105))
from
   dual connect by level <= 100*1000;


create index tq84_C_ix on tq84_C(col_1);


begin
   dbms_stats.gather_table_stats(user, 'tq84_P');
   dbms_stats.gather_table_stats(user, 'tq84_C');
end;
/


explain plan for
select
   c.col_2,
   p.val_1
from
   tq84_C  c                          join
   tq84_P  p  on c.id_p = p.id
where
   c.col_1 = 12.3;


select * from table(dbms_xplan.display(format => 'basic +note'));
--
-- -----------------------------------------------------------
-- | Id  | Operation                             | Name      |
-- -----------------------------------------------------------
-- |   0 | SELECT STATEMENT                      |           |
-- |   1 |  NESTED LOOPS                         |           |
-- |   2 |   NESTED LOOPS                        |           |
-- |   3 |    TABLE ACCESS BY INDEX ROWID BATCHED| TQ84_C    |
-- |   4 |     INDEX RANGE SCAN                  | TQ84_C_IX |
-- |   5 |    INDEX UNIQUE SCAN                  | TQ84_P_PK |
-- |   6 |   TABLE ACCESS BY INDEX ROWID         | TQ84_P    |
-- -----------------------------------------------------------
--
-- Note
-- -----
--    - this is an adaptive plan


drop   table tq84_C;
drop   table tq84_P;

See also

The no_nlj_batching(tab) hint instructs to not join tab with a nested nested-loop.
Oracle: SQL statement execution plan operations

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758203862, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/statement/execution/plan/operations/nested-loops/nested/index(125): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78