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: incorrect query result using ISNULL #54819

Merged
merged 3 commits into from
Aug 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@
"Plan": [
" TableReader root ",
" └─ExchangeSender cop[tiflash] ",
" └─Selection cop[tiflash] gt(test.t1.b, ?)",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.a, ?), gt(test.t1.c, ?), keep order:false"
" └─Selection cop[tiflash] gt(test.t1.c, ?)",
" └─TableFullScan cop[tiflash] table:t1, range:[?,?], pushed down filter:gt(test.t1.a, ?), gt(test.t1.b, ?), keep order:false"
]
},
{
Expand Down
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 = 3,
shard_count = 4,
deps = [
"//pkg/parser",
"//pkg/planner",
Expand Down
27 changes: 27 additions & 0 deletions pkg/planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,30 @@ func TestIssue54535(t *testing.T) {
tk.MustQuery("select /*+ inl_join(tmp) */ * from t1 inner join (select col_1, group_concat(col_2) from t2 group by col_1) tmp on t1.col_1 = tmp.col_1;").Check(testkit.Rows())
tk.MustQuery("select /*+ inl_join(tmp) */ * from t1 inner join (select col_1, group_concat(distinct col_2 order by col_2) from t2 group by col_1) tmp on t1.col_1 = tmp.col_1;").Check(testkit.Rows())
}

func TestIssue54803(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`
CREATE TABLE t1db47fc1 (
col_67 time NOT NULL DEFAULT '16:58:45',
col_68 tinyint(3) unsigned DEFAULT NULL,
col_69 bit(6) NOT NULL DEFAULT b'11110',
col_72 double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY HASH (col_68) PARTITIONS 5;
`)
tk.MustQuery(`EXPLAIN SELECT TRIM(t1db47fc1.col_68) AS r0
FROM t1db47fc1
WHERE ISNULL(t1db47fc1.col_68)
GROUP BY t1db47fc1.col_68
HAVING ISNULL(t1db47fc1.col_68) OR t1db47fc1.col_68 IN (62, 200, 196, 99)
LIMIT 106149535;
`).Check(testkit.Rows("Projection_11 8.00 root trim(cast(test.t1db47fc1.col_68, var_string(20)))->Column#7",
"└─Limit_14 8.00 root offset:0, count:106149535",
" └─HashAgg_17 8.00 root group by:test.t1db47fc1.col_68, funcs:firstrow(test.t1db47fc1.col_68)->test.t1db47fc1.col_68",
" └─TableReader_24 10.00 root partition:p0 data:Selection_23",
" └─Selection_23 10.00 cop[tikv] isnull(test.t1db47fc1.col_68), or(isnull(test.t1db47fc1.col_68), in(test.t1db47fc1.col_68, 62, 200, 196, 99))",
" └─TableFullScan_22 10000.00 cop[tikv] table:t1db47fc1 keep order:false, stats:pseudo"))
}
7 changes: 5 additions & 2 deletions pkg/util/ranger/detacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,11 @@ func ExtractEqAndInCondition(sctx *rangerctx.RangerContext, conditions []express
return nil, nil, nil, nil, true
} else {
// All Intervals are single points
accesses[i] = points2EqOrInCond(sctx.ExprCtx, points[i], cols[i])
newConditions = append(newConditions, accesses[i])
if f, ok := accesses[i].(*expression.ScalarFunction); !ok || (ok && f.FuncName.L != ast.IsNull) {
// isnull is not equal to a = NULL
accesses[i] = points2EqOrInCond(sctx.ExprCtx, points[i], cols[i])
newConditions = append(newConditions, accesses[i])
}
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
if f, ok := accesses[i].(*expression.ScalarFunction); ok && f.FuncName.L == ast.EQ {
// Actually the constant column value may not be mutable. Here we assume it is mutable to keep it simple.
// Maybe we can improve it later.
Expand Down