Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deep dive in a SQL query

Deep dive in a SQL query

Jesús Espino

March 19, 2024
Tweet

More Decks by Jesús Espino

Other Decks in Programming

Transcript

  1. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  2. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  3. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  4. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  5. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  6. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  7. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  8. ( {SELECT :distinctClause <> :intoClause <> :targetList ( {RESTARGET :name

    <> :indirection <> :val {COLUMNREF :fields ( {A_STAR} ) } } ) :fromClause ( {RANGEVAR :schemaname <> :relname foo :relpersistence p :alias <> } ) :whereClause {AEXPR :name ("=") :lexpr {COLUMNREF :fields ("bar") } :rexpr {A_CONST :val 42} } :groupClause <> :havingClause <> :windowClause <> :valuesLists <> :sortClause ( {SORTBY :node {COLUMNREF :fields ("id") } :sortby_dir 2 :sortby_nulls 0 :useOp <> } ) :limitOffset <> :limitCount {A_CONST :val 23 } :lockingClause <> :withClause <> :op 0 :all false :larg <> :rarg <> } ) SELECT * FROM foo WHERE bar = 42 ORDER BY id DESC LIMIT 23;
  9. • Dependientes del catálogo de la BBDD • Desambiguación de

    tipos • Añade información de tipos Transformaciones src/backend/rewrite/rewriteHandler.c:3621
  10. El sistema de reglas CREATE VIEW myview AS SELECT *

    FROM mytab; CREATE TABLE myview (same COLUMN list AS mytab); CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD SELECT * FROM mytab; src/backend/rewrite/rewriteHandler.c:1986
  11. EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 100 AND

    unique2 > 9000; QUERY PLAN ------------------------------------------------------------------- ------------------ Bitmap Heap Scan ON tenk1 (cost=25.08..60.21 ROWS=10 width=244) Recheck Cond: ((unique1 < 100) AND (unique2 > 9000)) -> BitmapAnd (cost=25.08..25.08 ROWS=10 width=0) -> Bitmap INDEX Scan ON tenk1_unique1 (cost=0.00..5.04 ROWS=101 width=0) INDEX Cond: (unique1 < 100) -> Bitmap INDEX Scan ON tenk1_unique2 (cost=0.00..19.78 ROWS=999 width=0) INDEX Cond: (unique2 > 9000) src/include/optimizer/nodes/plannodes.h:120
  12. • Scan Methods • Merge Methods • Join Order El

    Optimizador src/backend/optimizer/plan/planner.c:273
  13. Scan Methods Sequential Scan sakila=# EXPLAIN SELECT * FROM film;

    QUERY PLAN ---------------------------------------------------------- Seq Scan ON film (cost=0.00..74.00 ROWS=1000 width=390) src/backend/executor/nodeSeqscan.c
  14. Scan Methods Sequential Scan film_id | title ---------+---------------------- 854 |

    STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 81 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE 488 | JOON NORTHWEST 985 | WONDERLAND CHRISTMAS 840 | STAMPEDE DISTURBING 399 | HAPPINESS UNITED 984 | WONDERFUL DROP 149 | CHRISTMAS MOONSHINE 988 | WORKER TARZAN 135 | CHANCE RESURRECTION →
  15. Scan Methods Sequential Scan film_id | title ---------+---------------------- 854 |

    STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 81 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE 488 | JOON NORTHWEST 985 | WONDERLAND CHRISTMAS 840 | STAMPEDE DISTURBING 399 | HAPPINESS UNITED 984 | WONDERFUL DROP 149 | CHRISTMAS MOONSHINE 988 | WORKER TARZAN 135 | CHANCE RESURRECTION →
  16. Scan Methods Sequential Scan film_id | title ---------+---------------------- 854 |

    STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 81 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE 488 | JOON NORTHWEST 985 | WONDERLAND CHRISTMAS 840 | STAMPEDE DISTURBING 399 | HAPPINESS UNITED 984 | WONDERFUL DROP 149 | CHRISTMAS MOONSHINE 988 | WORKER TARZAN 135 | CHANCE RESURRECTION →
  17. Scan Methods Sequential Scan film_id | title ---------+---------------------- 854 |

    STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 81 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE 488 | JOON NORTHWEST 985 | WONDERLAND CHRISTMAS 840 | STAMPEDE DISTURBING 399 | HAPPINESS UNITED 984 | WONDERFUL DROP 149 | CHRISTMAS MOONSHINE 988 | WORKER TARZAN 135 | CHANCE RESURRECTION →
  18. Scan Methods Index Scan sakila=# EXPLAIN SELECT * FROM film

    WHERE film_id=31; QUERY PLAN ------------------------------------------------------------------------ INDEX Scan USING film_pkey ON film (cost=0.28..8.29 ROWS=1 width=390) INDEX Cond: (film_id = 31) src/backend/executor/nodeIndexscan.c
  19. Scan Methods Index Scan film_id | title ---------+---------------------- 854 |

    STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE 488 | JOON NORTHWEST 985 | WONDERLAND CHRISTMAS 840 | STAMPEDE DISTURBING 399 | HAPPINESS UNITED 984 | WONDERFUL DROP 149 | CHRISTMAS MOONSHINE 988 | WORKER TARZAN 135 | CHANCE RESURRECTION →
  20. Scan Methods Bitmap Index Scan sakila=# EXPLAIN SELECT * FROM

    film WHERE film_id > 30 and film_id < 60; QUERY PLAN ------------------------------------------------------------------------- Bitmap Heap Scan on film (cost=4.57..56.92 rows=29 width=390) Recheck Cond: ((film_id > 30) AND (film_id < 60)) -> Bitmap Index Scan on film_pkey (cost=0.00..4.57 rows=29 width=0) Index Cond: ((film_id > 30) AND (film_id < 60)) src/backend/executor/nodeBitmapIndexscan.c
  21. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  22. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  23. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  24. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  25. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 0 0 1 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  26. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 0 0 1 0 | 0 0 0 0 | 0 0 0 0 | 1 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  27. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 1 0 1 0 | 0 0 0 0 | 0 0 0 0 | 1 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  28. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 1 0 1 0 | 0 0 0 0 | 0 1 0 0 | 1 0 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  29. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 0 0 0 0 | 1 0 1 0 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  30. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 1 0 0 0 | 1 0 1 0 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  31. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 0] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  32. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  33. Scan Methods Bitmap Index Scan [0 0 0 0 |

    0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
  34. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+----------------------
  35. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+----------------------
  36. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+----------------------
  37. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+----------------------
  38. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI
  39. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI
  40. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL
  41. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN
  42. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN
  43. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN
  44. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN
  45. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS
  46. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS
  47. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR
  48. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE
  49. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE
  50. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE
  51. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE
  52. Scan Methods Bitmap Index Scan Heap Scan [0 0 0

    0 | 0 0 0 0 | 1 0 0 0 | 1 0 1 1 | 0 0 0 0 | 0 1 0 0 | 1 1 0 0 | 0 0 0 0 | 0 0 0 0 | 0 0 0 1] page1 page2 page3 page4 page5 page6 page7 page8 page9 page10 film_id | title ---------+---------------------- 854 | STRANGERS GRAFFITI 967 | WEEKEND PERSONAL 789 | SHOCK CABIN 31 | BLINDNESS GUN 600 | MOTIONS DETAILS 144 | CHINATOWN GLADIATOR 835 | SPY MILE 488 | JOON NORTHWEST
  53. Nested Loop sakila=# EXPLAIN SELECT * FROM film JOIN LANGUAGE

    ON LANGUAGE.language_id = film.language_id WHERE LANGUAGE.language_id =2; QUERY PLAN --------------------------------------------------------------------------------------- Nested Loop (cost=0.15..5.25 ROWS=1 width=423) -> Seq Scan ON LANGUAGE (cost=0.00..1.07 ROWS=1 width=33) FILTER: (language_id = 2) -> Seq Scan ON film (cost=0.00..76.50 ROWS=1000 width=390) FILTER: (language_id = 2) src/backend/executor/nodeNestloop.c
  54. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE
  55. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE →
  56. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE →
  57. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE →
  58. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE →
  59. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE →
  60. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI
  61. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI
  62. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI
  63. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI
  64. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI
  65. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI
  66. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI 835 | 2 | SPY MILE
  67. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI 835 | 2 | SPY MILE
  68. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI 835 | 2 | SPY MILE
  69. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI 835 | 2 | SPY MILE
  70. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI 835 | 2 | SPY MILE
  71. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → → 854 | 2 | STRANGERS GRAFFITI 835 | 2 | SPY MILE
  72. Nested Loop language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 1 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE → 854 | 2 | STRANGERS GRAFFITI 835 | 2 | SPY MILE
  73. Hash Join sakila=# EXPLAIN SELECT * FROM film JOIN LANGUAGE

    ON LANGUAGE.language_id = film.language_id WHERE LANGUAGE.language_id > 3; QUERY PLAN --------------------------------------------------------------------- Hash Join (cost=1.12..79.61 rows=667 width=423) Hash Cond: (film.language_id = language.language_id) -> Seq Scan on film (cost=0.00..74.00 rows=1000 width=390) -> Hash (cost=1.07..1.07 rows=4 width=33) -> Seq Scan on language (cost=0.00..1.07 rows=4 width=33) Filter: (language_id > 3) src/backend/executor/nodeHashjoin.c
  74. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | h1 | h2 | h3 | hash(x) ⇒
  75. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | h1 | h2 | h3 | 5 hash(x) ⇒ →
  76. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | h1 | h2 | h3 | 5 hash(x) ⇒ →
  77. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | h1 | h2 | h3 | 5,6 hash(x) ⇒ →
  78. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | 4 h1 | h2 | h3 | 5,6 hash(x) ⇒ →
  79. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | 4 h1 | h2 | h3 | 5,6 hash(x) ⇒ →
  80. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | 4 h1 | h2 | h3 | 5,6 hash(x) ⇒ →
  81. Hash Join language_id | name -------------+---------------------- 5 | French 1

    | English 6 | German 4 | Mandarin 2 | Italian 3 | Japanese Hash | rows -------------+---------------------- h0 | 4 h1 | h2 | h3 | 5,6 hash(x) ⇒
  82. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x)
  83. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) →
  84. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) →
  85. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) →
  86. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) →
  87. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) →
  88. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) →
  89. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → →
  90. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → →
  91. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → → 144 | 6 | CHINATOWN GLADIATOR
  92. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR
  93. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR
  94. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR
  95. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR →
  96. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING →
  97. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING →
  98. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING
  99. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING
  100. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING →
  101. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING 984 | 4 | WONDERFUL DROP →
  102. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING 984 | 4 | WONDERFUL DROP →
  103. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE
  104. Hash Join Hash | rows -------------+---------------------- h0 | 4 h1

    | h2 | h3 | 5,6 film_id | language_id | title ---------+-------------+-------------------- 854 | 2 | STRANGERS GRAFFITI 967 | 3 | WEEKEND PERSONAL 789 | 1 | SHOCK CABIN 81 | 3 | BLINDNESS GUN 600 | 1 | MOTIONS DETAILS 144 | 6 | CHINATOWN GLADIATOR 835 | 2 | SPY MILE 488 | 1 | JOON NORTHWEST 840 | 5 | STAMPEDE DISTURBING 399 | 1 | HAPPINESS UNITED 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE ⇐ hash(x) → → 144 | 6 | CHINATOWN GLADIATOR 840 | 5 | STAMPEDE DISTURBING 984 | 4 | WONDERFUL DROP 149 | 5 | CHRISTMAS MOONSHINE
  105. Merge Join src/backend/executor/nodeMergejoin.c sakila=# EXPLAIN SELECT * FROM film JOIN

    LANGUAGE ON LANGUAGE.language_id = film.language_id WHERE LANGUAGE.language_id > 3; QUERY PLAN --------------------------------------------------------------------------------------- Merge Join (cost=0.85..3.66 rows=99 width=338) Merge Cond: (film.language_id = language.language_id) -> Index Scan using idx_film_language_id on film (cost=0.42..2.45 rows=99 width=324) Index Cond: (language_id > 3) -> Index Only Scan using pk_language on language (cost=0.42..0.84 rows=12 width=18) Index Cond: (language_id > 3)
  106. Merge Join → 1 2 3 4 5 6 1

    4 5 5 6 6 Mismo orden
  107. Merge Join → → film_id | language_id | title ---------+-------------+--------------------

    984 | 4 | WONDERFUL DROP 840 | 5 | STAMPEDE DISTURBING 1 2 3 4 5 6 1 4 5 5 6 6
  108. Merge Join → → film_id | language_id | title ---------+-------------+--------------------

    984 | 4 | WONDERFUL DROP 840 | 5 | STAMPEDE DISTURBING 149 | 5 | CHRISTMAS MOONSHINE 1 2 3 4 5 6 1 4 5 5 6 6
  109. Merge Join → → film_id | language_id | title ---------+-------------+--------------------

    984 | 4 | WONDERFUL DROP 840 | 5 | STAMPEDE DISTURBING 149 | 5 | CHRISTMAS MOONSHINE 1 2 3 4 5 6 1 4 5 5 6 6
  110. Merge Join → → film_id | language_id | title ---------+-------------+--------------------

    984 | 4 | WONDERFUL DROP 840 | 5 | STAMPEDE DISTURBING 149 | 5 | CHRISTMAS MOONSHINE 399 | 6 | HAPPINESS UNITED 1 2 3 4 5 6 1 4 5 5 6 6
  111. Merge Join → → film_id | language_id | title ---------+-------------+--------------------

    984 | 4 | WONDERFUL DROP 840 | 5 | STAMPEDE DISTURBING 149 | 5 | CHRISTMAS MOONSHINE 399 | 6 | HAPPINESS UNITED 967 | 6 | WEEKEND PERSONAL 1 2 3 4 5 6 1 4 5 5 6 6
  112. El ejecutor • Ejecuta el Query Plan • Lo hace

    en orden recursivo • Devuelve las filas una a una src/backend/executor/execMain.c:302
  113. References • Explaining the Postgres Query Optimizer: https://youtu.be/wLpcVM9qxV0?si=pMmq2nHiHlV_37kf • Overview

    of PostgreSQL Internals: https://www.postgresql.org/docs/current/overview.html • Using EXPLAIN: https://www.postgresql.org/docs/current/using-explain.html • The Rule System: https://www.postgresql.org/docs/current/rules.html • Database System Research Group at the University of Tübingen: https://www.youtube.com/playlist?list=PL1XF9qjV8kH0ghGRGo3_f-FWqWvAbv1dh • PostgreSQL 14 Internals (book): https://postgrespro.com/community/books/internals
  114. CREDITS: This presentation template was created by Slidesgo, including icons

    by Flaticon and infographics & images by Freepik ¡Gracias! Mantengamos el contacto Please keep this slide for attribution jespinog jesus-espino jespino