Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enable all join operators for all joins for n rels if there is no join hint for n rels #208

Open
wants to merge 2 commits into
base: PG16
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions expected/pg_hint_plan.out
Original file line number Diff line number Diff line change
Expand Up @@ -852,17 +852,17 @@ error hint:
QUERY PLAN
--------------------------------------------------
Nested Loop
-> Nested Loop
-> Merge Join
Merge Cond: (t3.id = t1.id)
-> Merge Join
Merge Cond: (t3.id = t4.id)
-> Index Scan using t3_pkey on t3
-> Sort
Sort Key: t4.id
-> Seq Scan on t4
-> Index Scan using t2_pkey on t2
Index Cond: (id = t3.id)
-> Index Scan using t1_pkey on t1
Index Cond: (id = t2.id)
-> Index Scan using t1_pkey on t1
-> Index Scan using t2_pkey on t2
Index Cond: (id = t1.id)
(12 rows)

/*+Leading(t3 t4 t1)*/
Expand Down Expand Up @@ -5680,18 +5680,19 @@ not used hint:
duplication hint:
error hint:

QUERY PLAN
--------------------------------------------
Nested Loop
Join Filter: (t2.val = t3.val)
-> Hash Join
Hash Cond: (t1.id = t2.id)
-> Index Scan using t1_pkey on t1
Index Cond: (id < 10)
-> Hash
-> Seq Scan on t2
QUERY PLAN
--------------------------------------------------
Hash Join
Hash Cond: (t3.val = t2.val)
-> Seq Scan on t3
(9 rows)
-> Hash
-> Hash Join
Hash Cond: (t1.id = t2.id)
-> Index Scan using t1_pkey on t1
Index Cond: (id < 10)
-> Hash
-> Seq Scan on t2
(10 rows)

/*+Leading((t1 t2 t3))*/
EXPLAIN (COSTS false) SELECT * FROM t1, t2, t3 WHERE t1.id = t2.id AND t2.val = t3.val AND t1.id < 10;
Expand Down Expand Up @@ -6183,7 +6184,6 @@ error hint:
QUERY PLAN
--------------------------------------------------
Nested Loop
Join Filter: (t3.id = t4.id)
-> Nested Loop
Join Filter: (t1.val = t3.val)
-> Hash Join
Expand All @@ -6193,7 +6193,8 @@ error hint:
-> Hash
-> Seq Scan on t2
-> Seq Scan on t3
-> Seq Scan on t4
-> Index Scan using t4_pkey on t4
Index Cond: (id = t3.id)
(12 rows)

/*+Leading(((t1 t2) t3)) MergeJoin(t1 t2 t3 t4)*/
Expand Down Expand Up @@ -9226,7 +9227,8 @@ error hint:

QUERY PLAN
-------------------------------------------------
Nested Loop
Merge Join
Merge Cond: (t1.id = t3.id)
-> Merge Join
Merge Cond: (t2.id = t1.id)
-> Index Scan using t2_pkey on t2
Expand All @@ -9235,7 +9237,8 @@ error hint:
-> Gather
Workers Planned: 8
-> Parallel Seq Scan on t1
-> Index Scan using t3_pkey on t3
Index Cond: (id = t1.id)
(11 rows)
-> Sort
Sort Key: t3.id
-> Seq Scan on t3
(13 rows)

21 changes: 11 additions & 10 deletions expected/ut-L.out
Original file line number Diff line number Diff line change
Expand Up @@ -4278,18 +4278,19 @@ error hint:
QUERY PLAN
------------------------------------------------
Nested Loop
Join Filter: (t1.c1 = t4.c1)
-> Nested Loop
Join Filter: (t1.c1 = t2.c1)
-> Nested Loop
-> Index Scan using t2_i1 on t2
-> Index Scan using t3_i1 on t3
Index Cond: (c1 = t2.c1)
-> Merge Join
Merge Cond: (t1.c1 = t2.c1)
-> Index Scan using t1_i1 on t1
Index Cond: (c1 = t3.c1)
-> Sort
Sort Key: t2.c1
-> Hash Join
Hash Cond: (t2.c1 = t3.c1)
-> Seq Scan on t2
-> Hash
-> Seq Scan on t3
-> Index Scan using t4_i1 on t4
Index Cond: (c1 = t3.c1)
(12 rows)
Index Cond: (c1 = t1.c1)
(13 rows)

-- No. L-3-6-3
/*+Leading((t2 t3 t4))*/
Expand Down
151 changes: 72 additions & 79 deletions expected/ut-R.out
Original file line number Diff line number Diff line change
Expand Up @@ -2582,8 +2582,8 @@ error hint:
\! sql/maskout.sh results/ut-R.tmpout
QUERY PLAN
----------------
Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt2.c1)
Merge Join (cost=xxx..xxx rows=10 width=xxx)
Merge Cond: (bmt1.c1 = bmt2.c1)
InitPlan 1 (returns $0)
-> Merge Join (cost=xxx..xxx rows=100 width=xxx)
Merge Cond: (b2t1.c1 = b2t2.c1)
Expand All @@ -2598,7 +2598,7 @@ error hint:
-> Sort (cost=xxx..xxx rows=100 width=xxx)
Sort Key: b3t2.c1
-> Seq Scan on t2 b3t2 (cost=xxx..xxx rows=100 width=xxx)
-> Nested Loop (cost={inf}..{inf} rows=100 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=100 width=xxx)
-> Merge Join (cost=xxx..xxx rows=100 width=xxx)
Merge Cond: (b1t1.c1 = b1t2.c1)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1000 width=xxx)
Expand All @@ -2608,8 +2608,9 @@ error hint:
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t1.c1)
Filter: (c1 <> $1)
-> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t1.c1)
-> Sort (cost=xxx..xxx rows=100 width=xxx)
Sort Key: bmt2.c1
-> Seq Scan on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)

\o results/ut-R.tmpout
/*+
Expand Down Expand Up @@ -2665,8 +2666,8 @@ error hint:
\! sql/maskout.sh results/ut-R.tmpout
QUERY PLAN
----------------
Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt2.c1)
Merge Join (cost=xxx..xxx rows=10 width=xxx)
Merge Cond: (bmt1.c1 = bmt2.c1)
InitPlan 1 (returns $0)
-> Merge Join (cost=xxx..xxx rows=1 width=xxx)
Merge Cond: (b2t1.c1 = b2t2.c1)
Expand All @@ -2681,7 +2682,7 @@ error hint:
-> Sort (cost=xxx..xxx rows=100 width=xxx)
Sort Key: b3t2.c1
-> Seq Scan on t2 b3t2 (cost=xxx..xxx rows=100 width=xxx)
-> Nested Loop (cost={inf}..{inf} rows=100 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=100 width=xxx)
-> Merge Join (cost=xxx..xxx rows=1 width=xxx)
Merge Cond: (b1t1.c1 = b1t2.c1)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1000 width=xxx)
Expand All @@ -2691,8 +2692,9 @@ error hint:
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t1.c1)
Filter: (c1 <> $1)
-> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t1.c1)
-> Sort (cost=xxx..xxx rows=100 width=xxx)
Sort Key: bmt2.c1
-> Seq Scan on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)

-- No. R-2-2-3
\o results/ut-R.tmpout
Expand Down Expand Up @@ -2753,8 +2755,8 @@ error hint:
\! sql/maskout.sh results/ut-R.tmpout
QUERY PLAN
----------------
Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt4.c1)
Merge Join (cost=xxx..xxx rows=10 width=xxx)
Merge Cond: (bmt1.c1 = bmt2.c1)
InitPlan 1 (returns $1)
-> Merge Join (cost=xxx..xxx rows=100 width=xxx)
Merge Cond: (b2t1.c1 = b2t2.c1)
Expand Down Expand Up @@ -2783,12 +2785,9 @@ error hint:
-> Seq Scan on t4 b3t4 (cost=xxx..xxx rows=1130 width=xxx)
-> Index Only Scan using t2_i1 on t2 b3t2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b3t3.c1)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt3.c1)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt2.c1)
-> Nested Loop (cost={inf}..{inf} rows=100 width=xxx)
Join Filter: (bmt1.c1 = b1t1.c1)
-> Nested Loop (cost=xxx..xxx rows=100 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=88 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=88 width=xxx)
-> Merge Join (cost=xxx..xxx rows=100 width=xxx)
Merge Cond: (b1t1.c1 = b1t2.c1)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1000 width=xxx)
Expand All @@ -2802,15 +2801,16 @@ error hint:
-> Seq Scan on t4 b1t4 (cost=xxx..xxx rows=1130 width=xxx)
-> Index Only Scan using t2_i1 on t2 b1t2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
Filter: (c1 <> $3)
-> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Index Only Scan using t3_i1 on t3 bmt3 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Index Only Scan using t4_i1 on t4 bmt4 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = bmt3.c1)
-> Index Only Scan using t3_i1 on t3 bmt3 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t1.c1)
-> Index Only Scan using t4_i1 on t4 bmt4 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = bmt3.c1)
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = bmt3.c1)
Filter: (c1 <> $3)
-> Sort (cost=xxx..xxx rows=100 width=xxx)
Sort Key: bmt2.c1
-> Seq Scan on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)

\o results/ut-R.tmpout
/*+
Expand Down Expand Up @@ -2897,7 +2897,6 @@ error hint:
QUERY PLAN
----------------
Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt4.c1)
InitPlan 1 (returns $1)
-> Merge Join (cost=xxx..xxx rows=1 width=xxx)
Merge Cond: (b2t1.c1 = b2t2.c1)
Expand Down Expand Up @@ -2927,11 +2926,9 @@ error hint:
-> Index Only Scan using t2_i1 on t2 b3t2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b3t3.c1)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt3.c1)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt2.c1)
-> Nested Loop (cost={inf}..{inf} rows=100 width=xxx)
Join Filter: (bmt1.c1 = b1t1.c1)
-> Merge Join (cost=xxx..xxx rows=10 width=xxx)
Merge Cond: (bmt1.c1 = bmt2.c1)
-> Nested Loop (cost=xxx..xxx rows=100 width=xxx)
-> Merge Join (cost=xxx..xxx rows=1 width=xxx)
Merge Cond: (b1t1.c1 = b1t2.c1)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1000 width=xxx)
Expand All @@ -2946,14 +2943,15 @@ error hint:
-> Index Only Scan using t2_i1 on t2 b1t2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
Index Cond: (c1 = b1t1.c1)
Filter: (c1 <> $3)
-> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Sort (cost=xxx..xxx rows=100 width=xxx)
Sort Key: bmt2.c1
-> Seq Scan on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)
-> Index Only Scan using t3_i1 on t3 bmt3 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
Index Cond: (c1 = bmt1.c1)
-> Index Only Scan using t4_i1 on t4 bmt4 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = bmt3.c1)
Index Cond: (c1 = bmt1.c1)

-- No. R-2-2-4
\o results/ut-R.tmpout
Expand Down Expand Up @@ -2999,22 +2997,20 @@ error hint:
QUERY PLAN
----------------
Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt4.c1)
InitPlan 1 (returns $0)
-> Index Only Scan using t1_i1 on t1 b2t1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = 1)
InitPlan 2 (returns $1)
-> Seq Scan on t1 b3t1 (cost=xxx..xxx rows=1000 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt3.c1)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt2.c1)
-> Nested Loop (cost={inf}..{inf} rows=100 width=xxx)
Join Filter: (bmt2.c1 = b1t1.c1)
-> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)
-> Materialize (cost=xxx..xxx rows=100 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=100 width=xxx)
Join Filter: (b1t1.c1 = b1t2.c1)
-> Merge Join (cost=xxx..xxx rows=10 width=xxx)
Merge Cond: (bmt2.c1 = bmt1.c1)
-> Merge Join (cost=xxx..xxx rows=100 width=xxx)
Merge Cond: (b1t1.c1 = bmt2.c1)
-> Nested Loop (cost=xxx..xxx rows=100 width=xxx)
Join Filter: (b1t1.c1 = b1t2.c1)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1000 width=xxx)
-> Materialize (cost=xxx..xxx rows=100 width=xxx)
-> Hash Join (cost=xxx..xxx rows=100 width=xxx)
Hash Cond: (b1t3.c1 = b1t2.c1)
-> Merge Join (cost=xxx..xxx rows=1130 width=xxx)
Expand All @@ -3023,15 +3019,15 @@ error hint:
-> Index Only Scan using t4_i1 on t4 b1t4 (cost=xxx..xxx rows=1130 width=xxx)
-> Hash (cost=xxx..xxx rows=100 width=xxx)
-> Seq Scan on t2 b1t2 (cost=xxx..xxx rows=100 width=xxx)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Sort (cost=xxx..xxx rows=100 width=xxx)
Sort Key: bmt2.c1
-> Seq Scan on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=999 width=xxx)
Filter: (c1 <> $1)
-> Index Only Scan using t3_i1 on t3 bmt3 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
Index Cond: (c1 = bmt1.c1)
-> Index Only Scan using t4_i1 on t4 bmt4 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = bmt3.c1)
Index Cond: (c1 = bmt1.c1)

\o results/ut-R.tmpout
/*+
Expand Down Expand Up @@ -3090,39 +3086,36 @@ error hint:
QUERY PLAN
----------------
Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt4.c1)
InitPlan 1 (returns $0)
-> Index Only Scan using t1_i1 on t1 b2t1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = 1)
InitPlan 2 (returns $1)
-> Seq Scan on t1 b3t1 (cost=xxx..xxx rows=1000 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt3.c1)
-> Nested Loop (cost=xxx..xxx rows=10 width=xxx)
Join Filter: (bmt1.c1 = bmt2.c1)
-> Nested Loop (cost={inf}..{inf} rows=100 width=xxx)
Join Filter: (bmt2.c1 = b1t1.c1)
-> Index Only Scan using t2_i1 on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)
-> Materialize (cost=xxx..xxx rows=1 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=1 width=xxx)
Join Filter: (b1t1.c1 = b1t2.c1)
-> Hash Join (cost=xxx..xxx rows=1 width=xxx)
Hash Cond: (b1t3.c1 = b1t2.c1)
-> Merge Join (cost=xxx..xxx rows=1 width=xxx)
Merge Cond: (b1t3.c1 = b1t4.c1)
-> Index Only Scan using t3_i1 on t3 b1t3 (cost=xxx..xxx rows=1130 width=xxx)
-> Index Only Scan using t4_i1 on t4 b1t4 (cost=xxx..xxx rows=1130 width=xxx)
-> Hash (cost=xxx..xxx rows=100 width=xxx)
-> Seq Scan on t2 b1t2 (cost=xxx..xxx rows=100 width=xxx)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
Filter: (c1 <> $1)
-> Hash Join (cost=xxx..xxx rows=10 width=xxx)
Hash Cond: (bmt1.c1 = bmt2.c1)
-> Nested Loop (cost=xxx..xxx rows=100 width=xxx)
-> Nested Loop (cost=xxx..xxx rows=1 width=xxx)
Join Filter: (b1t1.c1 = b1t2.c1)
-> Hash Join (cost=xxx..xxx rows=1 width=xxx)
Hash Cond: (b1t3.c1 = b1t2.c1)
-> Merge Join (cost=xxx..xxx rows=1 width=xxx)
Merge Cond: (b1t3.c1 = b1t4.c1)
-> Index Only Scan using t3_i1 on t3 b1t3 (cost=xxx..xxx rows=1130 width=xxx)
-> Index Only Scan using t4_i1 on t4 b1t4 (cost=xxx..xxx rows=1130 width=xxx)
-> Hash (cost=xxx..xxx rows=100 width=xxx)
-> Seq Scan on t2 b1t2 (cost=xxx..xxx rows=100 width=xxx)
-> Index Only Scan using t1_i1 on t1 b1t1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
-> Index Only Scan using t1_i1 on t1 bmt1 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t1.c1)
Filter: (c1 <> $1)
-> Hash (cost=xxx..xxx rows=100 width=xxx)
-> Seq Scan on t2 bmt2 (cost=xxx..xxx rows=100 width=xxx)
-> Index Only Scan using t3_i1 on t3 bmt3 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = b1t3.c1)
Index Cond: (c1 = bmt1.c1)
-> Index Only Scan using t4_i1 on t4 bmt4 (cost=xxx..xxx rows=1 width=xxx)
Index Cond: (c1 = bmt3.c1)
Index Cond: (c1 = bmt1.c1)

----
---- No. R-2-3 RULE or VIEW
Expand Down
Loading