From 26b88e4b798771d62c34ed70baff261881db7db5 Mon Sep 17 00:00:00 2001 From: Max Hoffman Date: Wed, 19 Mar 2025 21:15:22 -0700 Subject: [PATCH] disable_merge_join corner case --- enginetest/join_planning_tests.go | 14 ++++++++++++-- sql/memo/select_hints.go | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/enginetest/join_planning_tests.go b/enginetest/join_planning_tests.go index 21dac2f88a..342d88b3e9 100644 --- a/enginetest/join_planning_tests.go +++ b/enginetest/join_planning_tests.go @@ -87,8 +87,8 @@ var JoinPlanningTests = []joinPlanScript{ "CREATE table ab (a int primary key, b int);", "insert into xy values (1,0), (2,1), (0,2), (3,3);", "insert into ab values (0,2), (1,2), (2,2), (3,1);", - `analyze table xy update histogram on x using data '{"row_count":1000}'`, - `analyze table ab update histogram on a using data '{"row_count":1000}'`, + `analyze table xy update histogram on x using data '{"row_count":1000000}'`, + `analyze table ab update histogram on a using data '{"row_count":1000000}'`, }, tests: []JoinPlanTest{ { @@ -96,6 +96,11 @@ var JoinPlanningTests = []joinPlanScript{ types: []plan.JoinType{plan.JoinTypeMerge}, exp: []sql.Row{{0, 2, 1, 0}, {1, 2, 2, 1}, {2, 2, 0, 2}, {3, 1, 3, 3}}, }, + { + q: "select * from ab join xy on x = a and y = a order by 1, 3", + types: []plan.JoinType{plan.JoinTypeMerge}, + exp: []sql.Row{{3, 1, 3, 3}}, + }, { q: "set @@SESSION.disable_merge_join = 1", exp: []sql.Row{{}}, @@ -105,6 +110,11 @@ var JoinPlanningTests = []joinPlanScript{ types: []plan.JoinType{plan.JoinTypeLookup}, exp: []sql.Row{{0, 2, 1, 0}, {1, 2, 2, 1}, {2, 2, 0, 2}, {3, 1, 3, 3}}, }, + { + q: "select * from ab join xy on x = a and y = a order by 1, 3", + types: []plan.JoinType{plan.JoinTypeLookup}, + exp: []sql.Row{{3, 1, 3, 3}}, + }, }, }, { diff --git a/sql/memo/select_hints.go b/sql/memo/select_hints.go index 6b41d168d6..7c9a515e33 100644 --- a/sql/memo/select_hints.go +++ b/sql/memo/select_hints.go @@ -390,7 +390,7 @@ type joinHints struct { } func (h joinHints) isEmpty() bool { - return len(h.ops) == 0 && h.order == nil && !h.leftDeep + return len(h.ops) == 0 && h.order == nil && !h.leftDeep && len(h.block) == 0 } // satisfiedBy returns whether a RelExpr satisfies every join hint. This