From 2942608491fc086a43e10e503d9abb0176c1150e Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 29 Jul 2024 11:23:25 +0800 Subject: [PATCH 1/2] fixup --- pkg/planner/core/logical_union_scan.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/planner/core/logical_union_scan.go b/pkg/planner/core/logical_union_scan.go index 26ebe13389bcd..ad72b3c7b6ddd 100644 --- a/pkg/planner/core/logical_union_scan.go +++ b/pkg/planner/core/logical_union_scan.go @@ -62,15 +62,22 @@ func (p *LogicalUnionScan) ExplainInfo() string { // PredicatePushDown implements base.LogicalPlan.<1st> interface. func (p *LogicalUnionScan) PredicatePushDown(predicates []expression.Expression, opt *optimizetrace.LogicalOptimizeOp) ([]expression.Expression, base.LogicalPlan) { - if expression.ContainVirtualColumn(predicates) { - // predicates with virtual columns can't be pushed down to TiKV/TiFlash so they'll be put into a Projection - // below the UnionScan, but the current UnionScan doesn't support placing Projection below it, see #53951. - return predicates, p + var predicatesWithVCol, predicatesWithoutVCol []expression.Expression + // predicates with virtual columns can't be pushed down to TiKV/TiFlash so they'll be put into a Projection + // below the UnionScan, but the current UnionScan doesn't support placing Projection below it, see #53951. + for _, expr := range predicates { + if expression.ContainVirtualColumn([]expression.Expression{expr}) { + predicatesWithVCol = append(predicatesWithVCol, expr) + } else { + predicatesWithoutVCol = append(predicatesWithoutVCol, expr) + } } + predicates = predicatesWithoutVCol retainedPredicates, _ := p.Children()[0].PredicatePushDown(predicates, opt) p.Conditions = make([]expression.Expression, 0, len(predicates)) p.Conditions = append(p.Conditions, predicates...) // The conditions in UnionScan is only used for added rows, so parent Selection should not be removed. + retainedPredicates = append(retainedPredicates, predicatesWithVCol...) return retainedPredicates, p } From 96258b073d01216daf374612183a2ffb11bd413b Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 29 Jul 2024 11:34:14 +0800 Subject: [PATCH 2/2] fixup --- pkg/planner/core/integration_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/planner/core/integration_test.go b/pkg/planner/core/integration_test.go index c613561971c00..aa246de5adf22 100644 --- a/pkg/planner/core/integration_test.go +++ b/pkg/planner/core/integration_test.go @@ -2237,6 +2237,20 @@ func TestIssue54213(t *testing.T) { " └─IndexRangeScan_14 0.10 cop[tikv] table:tb, index:ab(a, b) range:[1 1,1 1], keep order:false, stats:pseudo")) } +func TestIssue54870(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + + tk.MustExec("use test") + tk.MustExec(`create table t (id int, +deleted_at datetime(3) NOT NULL DEFAULT '1970-01-01 01:00:01.000', +is_deleted tinyint(1) GENERATED ALWAYS AS ((deleted_at > _utf8mb4'1970-01-01 01:00:01.000')) VIRTUAL NOT NULL, +key k(id, is_deleted))`) + tk.MustExec(`begin`) + tk.MustExec(`insert into t (id, deleted_at) values (1, now())`) + tk.MustHavePlan(`select 1 from t where id=1 and is_deleted=true`, "IndexRangeScan") +} + func TestIssue52472(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store)