Skip to content

Commit b23ad3c

Browse files
authored
ranger: should replace ast.Or with ast.LogicalOr (#55476) (#55484)
close #55475
1 parent 6eba67e commit b23ad3c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

pkg/planner/core/issuetest/planner_issue_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,14 @@ LIMIT 65122436;`).Check(testkit.Rows(
231231
" └─IndexReader_36 32.00 root index:StreamAgg_15",
232232
" └─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",
233233
" └─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"))
234+
tk.MustExec(`CREATE TABLE tl75eff7ba (
235+
col_1 tinyint(1) DEFAULT '0',
236+
KEY idx_1 (col_1),
237+
UNIQUE KEY idx_2 (col_1),
238+
UNIQUE KEY idx_3 (col_1),
239+
KEY idx_4 (col_1) /*!80000 INVISIBLE */,
240+
UNIQUE KEY idx_5 (col_1)
241+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;`)
242+
tk.MustExec(`INSERT INTO tl75eff7ba VALUES(1),(0);`)
243+
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"))
234244
}

pkg/util/ranger/ranger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ func points2EqOrInCond(ctx expression.BuildContext, points []*point, col *expres
764764
if len(orArgs) == 1 {
765765
return orArgs[0]
766766
}
767-
return expression.NewFunctionInternal(ctx, ast.Or, col.GetType(ctx.GetEvalCtx()), orArgs...)
767+
return expression.NewFunctionInternal(ctx, ast.LogicOr, col.GetType(ctx.GetEvalCtx()), orArgs...)
768768
}
769769

770770
// RangesToString print a list of Ranges into a string which can appear in an SQL as a condition.

pkg/util/ranger/ranger_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,18 @@ func TestTableRange(t *testing.T) {
257257
filterConds: "[]",
258258
resultStr: "[]",
259259
},
260+
{
261+
exprStr: "isnull(a) or a in (1, 2, 3)",
262+
accessConds: "[or(isnull(test.t.a), in(test.t.a, 1, 2, 3))]",
263+
filterConds: "[]",
264+
resultStr: "[[1,1] [2,2] [3,3]]",
265+
},
266+
{
267+
exprStr: "isnull(a) and a in (1, 2, 3)",
268+
accessConds: "[isnull(test.t.a) in(test.t.a, 1, 2, 3)]",
269+
filterConds: "[]",
270+
resultStr: "[]",
271+
},
260272
}
261273

262274
ctx := context.Background()
@@ -2232,6 +2244,20 @@ create table t(
22322244
filterConds: "[]",
22332245
resultStr: "[[NULL,NULL]]",
22342246
},
2247+
{
2248+
indexPos: 0,
2249+
exprStr: "isnull(a) or a in (1,2,3,4)",
2250+
accessConds: "[]",
2251+
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))))]",
2252+
resultStr: "[[NULL,+inf]]",
2253+
},
2254+
{
2255+
indexPos: 0,
2256+
exprStr: "isnull(a) and a in (1,2,3,4)",
2257+
accessConds: "[isnull(test.t.a)]",
2258+
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)))]",
2259+
resultStr: "[[NULL,NULL]]",
2260+
},
22352261
{
22362262
indexPos: 0,
22372263
exprStr: "a is not null",

0 commit comments

Comments
 (0)