Skip to content

Commit 895e284

Browse files
committed
planner: fix cannot find column bug for natural join
Signed-off-by: guo-shaoge <[email protected]>
1 parent 9bcae5e commit 895e284

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pkg/planner/core/casetest/logicalplan/logical_plan_builder_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ WHERE EXISTS
4545
GROUP BY a1.col_pk_char)) )`).Check(testkit.Rows("TableDual 0.00 root rows:0"))
4646
})
4747
}
48+
49+
func TestNaturalJoinExpressionRewriter(t *testing.T) {
50+
store := testkit.CreateMockStore(t)
51+
tk := testkit.NewTestKit(t, store)
52+
tk.MustExec("use test")
53+
tk.MustExec("create table `mysql_1` (`col_bigint` bigint, col_numeric numeric);")
54+
tk.MustQuery("select 0 from mysql_1 t1 where exists ( select a2.col_bigint from mysql_1 a1 natural left join mysql_1 a2 where t1.col_bigint = (select distinct a2.col_bigint from mysql_1 a2 where ( t1.col_numeric <> '0.0330047607421875' ) ) )").Check(testkit.Rows())
55+
}

pkg/planner/core/logical_plan_builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,12 +877,12 @@ func (b *PlanBuilder) coalesceCommonColumns(p *logicalop.LogicalJoin, leftPlan,
877877
}
878878
}
879879

880-
schemaCols := make([]*expression.Column, len(lColumns)+len(rColumns)-commonLen)
880+
schemaCols := make([]*expression.Column, len(lColumns)+len(rColumns))
881881
copy(schemaCols[:len(lColumns)], lColumns)
882-
copy(schemaCols[len(lColumns):], rColumns[commonLen:])
882+
copy(schemaCols[len(lColumns):], rColumns)
883883
names := make(types.NameSlice, len(schemaCols))
884884
copy(names, lNames)
885-
copy(names[len(lNames):], rNames[commonLen:])
885+
copy(names[len(lNames):], rNames)
886886

887887
conds := make([]expression.Expression, 0, commonLen)
888888
for i := range commonLen {

0 commit comments

Comments
 (0)