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

ranger: should replace ast.Or with ast.LogicalOr #55476

Merged
merged 4 commits into from
Aug 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
10 changes: 10 additions & 0 deletions pkg/planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,14 @@ LIMIT 65122436;`).Check(testkit.Rows(
" └─IndexReader_36 32.00 root index:StreamAgg_15",
" └─StreamAgg_15 32.00 cop[tikv] group by:test.ta31c32a7.col_63, funcs:bit_xor(cast(test.ta31c32a7.col_63, bigint(22) BINARY))->Column#5",
" └─IndexRangeScan_32 40.00 cop[tikv] table:ta31c32a7, index:idx_24(col_63) range:[NULL,NULL], [1531.4023068774668,1531.4023068774668], [1780.7418079754723,1780.7418079754723], [5904.959667345741,5904.959667345741], keep order:true, stats:pseudo"))
tk.MustExec(`CREATE TABLE tl75eff7ba (
col_1 tinyint(1) DEFAULT '0',
KEY idx_1 (col_1),
UNIQUE KEY idx_2 (col_1),
UNIQUE KEY idx_3 (col_1),
KEY idx_4 (col_1) /*!80000 INVISIBLE */,
UNIQUE KEY idx_5 (col_1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;`)
tk.MustExec(`INSERT INTO tl75eff7ba VALUES(1),(0);`)
tk.MustQuery(`SELECT tl75eff7ba.col_1 AS r0 FROM tl75eff7ba WHERE ISNULL(tl75eff7ba.col_1) OR tl75eff7ba.col_1 IN (0, 0, 1, 1) GROUP BY tl75eff7ba.col_1 HAVING ISNULL(tl75eff7ba.col_1) OR tl75eff7ba.col_1 IN (0, 1, 1, 0) LIMIT 58651509;`).Check(testkit.Rows("0", "1"))
}
2 changes: 1 addition & 1 deletion pkg/util/ranger/ranger.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func points2EqOrInCond(ctx expression.BuildContext, points []*point, col *expres
if len(orArgs) == 1 {
return orArgs[0]
}
return expression.NewFunctionInternal(ctx, ast.Or, col.GetType(ctx.GetEvalCtx()), orArgs...)
return expression.NewFunctionInternal(ctx, ast.LogicOr, col.GetType(ctx.GetEvalCtx()), orArgs...)
}

// RangesToString print a list of Ranges into a string which can appear in an SQL as a condition.
Expand Down
26 changes: 26 additions & 0 deletions pkg/util/ranger/ranger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ func TestTableRange(t *testing.T) {
filterConds: "[]",
resultStr: "[]",
},
{
exprStr: "isnull(a) or a in (1, 2, 3)",
accessConds: "[or(isnull(test.t.a), in(test.t.a, 1, 2, 3))]",
filterConds: "[]",
resultStr: "[[1,1] [2,2] [3,3]]",
},
{
exprStr: "isnull(a) and a in (1, 2, 3)",
accessConds: "[isnull(test.t.a) in(test.t.a, 1, 2, 3)]",
filterConds: "[]",
resultStr: "[]",
},
}

ctx := context.Background()
Expand Down Expand Up @@ -2232,6 +2244,20 @@ create table t(
filterConds: "[]",
resultStr: "[[NULL,NULL]]",
},
{
indexPos: 0,
exprStr: "isnull(a) or a in (1,2,3,4)",
accessConds: "[]",
filterConds: "[or(isnull(test.t.a), or(or(eq(cast(test.t.a, double BINARY), 1), eq(cast(test.t.a, double BINARY), 2)), or(eq(cast(test.t.a, double BINARY), 3), eq(cast(test.t.a, double BINARY), 4))))]",
resultStr: "[[NULL,+inf]]",
},
{
indexPos: 0,
exprStr: "isnull(a) and a in (1,2,3,4)",
accessConds: "[isnull(test.t.a)]",
filterConds: "[or(or(eq(cast(test.t.a, double BINARY), 1), eq(cast(test.t.a, double BINARY), 2)), or(eq(cast(test.t.a, double BINARY), 3), eq(cast(test.t.a, double BINARY), 4)))]",
resultStr: "[[NULL,NULL]]",
},
{
indexPos: 0,
exprStr: "a is not null",
Expand Down