Search notes:

Oracle SQL Plan operation MERGE JOIN

begin
   dbms_random.seed(42);
end;
/

create table tq84_A (id number(5) not null, dat varchar2(2) not null, val number(4,1) not null);
create table tq84_B (id number(5) not null, dat varchar2(2) not null, val number(4,1) not null);

insert into tq84_A
select
   level                               as id,
   dbms_random.string('u', 2)          as dat,
   round(dbms_random.value(1, 100), 1) as val
from dual
connect by level <= 10000;

insert into tq84_B
select
   level                               as id,
   dbms_random.string('u', 2)         as dat,
   round(dbms_random.value(1, 100), 1) as val
from dual
connect by level <= 10000;

begin
   dbms_stats.gather_table_stats(user, 'tq84_A');
   dbms_stats.gather_table_stats(user, 'tq84_B');
end;
/


delete plan_table;
explain plan for
select
   a.id  id_a,
   b.id  id_b,
   a.val val_a,
   b.val val_b
from
   tq84_A a                 join
   tq84_B b on a.id < b.id
where
   a.dat = 'TQ' and
   b.dat = 'XY';

select * from plan_table;
   
select * from table(dbms_xplan.display(format => 'basic'));
--
-- --------------------------------------
-- | Id  | Operation           | Name   |
-- --------------------------------------
-- |   0 | SELECT STATEMENT    |        |
-- |   1 |  MERGE JOIN         |        |
-- |   2 |   SORT JOIN         |        |
-- |   3 |    TABLE ACCESS FULL| TQ84_B |
-- |   4 |   SORT JOIN         |        |
-- |   5 |    TABLE ACCESS FULL| TQ84_A |
-- --------------------------------------

drop table tq84_A;
drop table tq84_B;

See also

MERGE JOIN (CARTESIAN).
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...', 1758199816, '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/merge-join/index(99): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78