Skip to content

Commit 9a6edfc

Browse files
authored
disable_merge_join corner case (#2901)
1 parent e787f4e commit 9a6edfc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

enginetest/join_planning_tests.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,20 @@ var JoinPlanningTests = []joinPlanScript{
8787
"CREATE table ab (a int primary key, b int);",
8888
"insert into xy values (1,0), (2,1), (0,2), (3,3);",
8989
"insert into ab values (0,2), (1,2), (2,2), (3,1);",
90-
`analyze table xy update histogram on x using data '{"row_count":1000}'`,
91-
`analyze table ab update histogram on a using data '{"row_count":1000}'`,
90+
`analyze table xy update histogram on x using data '{"row_count":1000000}'`,
91+
`analyze table ab update histogram on a using data '{"row_count":1000000}'`,
9292
},
9393
tests: []JoinPlanTest{
9494
{
9595
q: "select /*+ JOIN_ORDER(ab, xy) MERGE_JOIN(ab, xy)*/ * from ab join xy on y = a order by 1, 3",
9696
types: []plan.JoinType{plan.JoinTypeMerge},
9797
exp: []sql.Row{{0, 2, 1, 0}, {1, 2, 2, 1}, {2, 2, 0, 2}, {3, 1, 3, 3}},
9898
},
99+
{
100+
q: "select * from ab join xy on x = a and y = a order by 1, 3",
101+
types: []plan.JoinType{plan.JoinTypeMerge},
102+
exp: []sql.Row{{3, 1, 3, 3}},
103+
},
99104
{
100105
q: "set @@SESSION.disable_merge_join = 1",
101106
exp: []sql.Row{{}},
@@ -105,6 +110,11 @@ var JoinPlanningTests = []joinPlanScript{
105110
types: []plan.JoinType{plan.JoinTypeLookup},
106111
exp: []sql.Row{{0, 2, 1, 0}, {1, 2, 2, 1}, {2, 2, 0, 2}, {3, 1, 3, 3}},
107112
},
113+
{
114+
q: "select * from ab join xy on x = a and y = a order by 1, 3",
115+
types: []plan.JoinType{plan.JoinTypeLookup},
116+
exp: []sql.Row{{3, 1, 3, 3}},
117+
},
108118
},
109119
},
110120
{

sql/memo/select_hints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ type joinHints struct {
390390
}
391391

392392
func (h joinHints) isEmpty() bool {
393-
return len(h.ops) == 0 && h.order == nil && !h.leftDeep
393+
return len(h.ops) == 0 && h.order == nil && !h.leftDeep && len(h.block) == 0
394394
}
395395

396396
// satisfiedBy returns whether a RelExpr satisfies every join hint. This

0 commit comments

Comments
 (0)