Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

planner: convert cartesian semi join with other nulleq condition to cross semi join with equal condition #58075

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion pkg/planner/core/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_test(
data = glob(["testdata/**"]),
flaky = True,
race = "on",
shard_count = 4,
shard_count = 5,
deps = [
"//pkg/parser",
"//pkg/planner",
Expand Down
25 changes: 25 additions & 0 deletions pkg/planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,28 @@ func TestIssue53175(t *testing.T) {
tk.MustQuery(`select * from t group by null`)
tk.MustQuery(`select * from v`)
}

func TestIssues57583(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("create table t1(id int, v1 int, v2 int, v3 int);")
tk.MustExec(" create table t2(id int, v1 int, v2 int, v3 int);")
tk.MustQuery("explain select t1.id from t1 join t2 on t1.v1 = t2.v2 intersect select t1.id from t1 join t2 on t1.v1 = t2.v2;").Check(testkit.Rows(
"HashJoin_15 6393.60 root semi join, left side:HashAgg_16, equal:[nulleq(test.t1.id, test.t1.id)]",
"├─HashJoin_26(Build) 12487.50 root inner join, equal:[eq(test.t1.v1, test.t2.v2)]",
"│ ├─TableReader_33(Build) 9990.00 root data:Selection_32",
"│ │ └─Selection_32 9990.00 cop[tikv] not(isnull(test.t2.v2))",
"│ │ └─TableFullScan_31 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
"│ └─TableReader_30(Probe) 9990.00 root data:Selection_29",
"│ └─Selection_29 9990.00 cop[tikv] not(isnull(test.t1.v1))",
"│ └─TableFullScan_28 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
"└─HashAgg_16(Probe) 7992.00 root group by:test.t1.id, funcs:firstrow(test.t1.id)->test.t1.id",
" └─HashJoin_17 12487.50 root inner join, equal:[eq(test.t1.v1, test.t2.v2)]",
" ├─TableReader_24(Build) 9990.00 root data:Selection_23",
" │ └─Selection_23 9990.00 cop[tikv] not(isnull(test.t2.v2))",
" │ └─TableFullScan_22 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
" └─TableReader_21(Probe) 9990.00 root data:Selection_20",
" └─Selection_20 9990.00 cop[tikv] not(isnull(test.t1.v1))",
" └─TableFullScan_19 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"))
}
5 changes: 3 additions & 2 deletions pkg/planner/core/operator/logicalop/logical_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -1259,8 +1259,9 @@ func (p *LogicalJoin) ExtractOnCondition(
rightCond = append(rightCond, notNullExpr)
}
}
if binop.FuncName.L == ast.EQ {
cond := expression.NewFunctionInternal(ctx.GetExprCtx(), ast.EQ, types.NewFieldType(mysql.TypeTiny), arg0, arg1)
switch binop.FuncName.L {
case ast.EQ, ast.NullEQ:
cond := expression.NewFunctionInternal(ctx.GetExprCtx(), binop.FuncName.L, types.NewFieldType(mysql.TypeTiny), arg0, arg1)
eqCond = append(eqCond, cond.(*expression.ScalarFunction))
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/testdata/plan_suite_unexported_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,12 @@
"Right": "[]"
},
{
"Plan": "Join{DataScan(t1)->DataScan(t2)}->Projection",
"Plan": "Join{DataScan(t1)->DataScan(t2)}(test.t.e,test.t.e)->Projection",
"Left": "[]",
"Right": "[]"
},
{
"Plan": "Join{DataScan(t1)->DataScan(t2)}->Projection",
"Plan": "Join{DataScan(t1)->DataScan(t2)}(test.t.e,test.t.e)->Projection",
"Left": "[]",
"Right": "[]"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
{
"SQL": "select /*+ hash_join_build(t1) */ * from t1, t2 where t1.k1<=>t2.k1; -- Doesn't support null safe eq predicate",
"Plan": [
"HashJoin_8 1.00 root CARTESIAN inner join, other cond:nulleq(test.t1.k1, test.t2.k1)",
"HashJoin_8 1.00 root inner join, equal:[nulleq(test.t1.k1, test.t2.k1)]",
"├─TableReader_13(Build) 1.00 root MppVersion: 2, data:ExchangeSender_12",
"│ └─ExchangeSender_12 1.00 mpp[tiflash] ExchangeType: PassThrough",
"│ └─TableFullScan_11 1.00 mpp[tiflash] table:t1 keep order:false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ Sort 5333.33 root Column#9, Column#10, Column#11, Column#12
explain FORMAT='brief' select * from t1 where a > 10 intersect select * from t2 where b > 20;
id estRows task access object operator info
Sort 2666.67 root planner__core__casetest__rule__rule_result_reorder.t1.a, planner__core__casetest__rule__rule_result_reorder.t1.b, planner__core__casetest__rule__rule_result_reorder.t1.c, planner__core__casetest__rule__rule_result_reorder.t1.d
└─HashJoin 2666.67 root CARTESIAN semi join, left side:TableReader, other cond:nulleq(planner__core__casetest__rule__rule_result_reorder.t1.a, planner__core__casetest__rule__rule_result_reorder.t2.a), nulleq(planner__core__casetest__rule__rule_result_reorder.t1.b, planner__core__casetest__rule__rule_result_reorder.t2.b), nulleq(planner__core__casetest__rule__rule_result_reorder.t1.c, planner__core__casetest__rule__rule_result_reorder.t2.c), nulleq(planner__core__casetest__rule__rule_result_reorder.t1.d, planner__core__casetest__rule__rule_result_reorder.t2.d)
└─HashJoin 2666.67 root semi join, left side:TableReader, equal:[nulleq(planner__core__casetest__rule__rule_result_reorder.t1.a, planner__core__casetest__rule__rule_result_reorder.t2.a) nulleq(planner__core__casetest__rule__rule_result_reorder.t1.b, planner__core__casetest__rule__rule_result_reorder.t2.b) nulleq(planner__core__casetest__rule__rule_result_reorder.t1.c, planner__core__casetest__rule__rule_result_reorder.t2.c) nulleq(planner__core__casetest__rule__rule_result_reorder.t1.d, planner__core__casetest__rule__rule_result_reorder.t2.d)]
├─TableReader(Build) 3333.33 root data:Selection
│ └─Selection 3333.33 cop[tikv] gt(planner__core__casetest__rule__rule_result_reorder.t2.b, 20)
│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
Expand Down