From b8c660e5e98da465561031826f6ca210b55996d2 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 00:20:47 +0800 Subject: [PATCH 01/31] planner: fix wrong schema when to PushDownPush Signed-off-by: Weizhen Wang --- .../core/issuetest/planner_issue_test.go | 26 +++++++++++++++++++ .../operator/logicalop/logical_projection.go | 9 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/planner/core/issuetest/planner_issue_test.go b/pkg/planner/core/issuetest/planner_issue_test.go index e9516ec7ad066..17c8a63ce476a 100644 --- a/pkg/planner/core/issuetest/planner_issue_test.go +++ b/pkg/planner/core/issuetest/planner_issue_test.go @@ -259,3 +259,29 @@ func TestIssue59902(t *testing.T) { " └─Selection 1.00 cop[tikv] not(isnull(test.t2.a))", " └─IndexRangeScan 1.00 cop[tikv] table:t2, index:idx(a) range: decided by [eq(test.t2.a, test.t1.a)], keep order:false, stats:pseudo")) } + +func TestABC(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test;") + tk.MustExec(`CREATE TABLE table_test ( +col16 json DEFAULT NULL, +col17 json DEFAULT NULL +);`) + tk.MustQuery(`SELECT + s.column16 AS column16, + s.column17 AS column17 +FROM + (SELECT + col16 -> '$[].optUid' AS column16, + JSON_UNQUOTE(JSON_EXTRACT(col17, '$[0].value')) AS column17 + FROM + (SELECT + col16, + col17 + FROM table_test) ta24e + ) AS s +ORDER BY CONVERT(column16 USING GBK) ASC,column17 ASC +LIMIT 0, + 20;`) +} diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 69d3d93a58417..5bc19b679df6b 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -224,11 +224,18 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) - return topN.AttachChild(p, opt) + } + } + if !p.Schema().Contains(col) { + // check whether the column is in it. + if p.Children()[0].Schema().Contains(col) { + p.Schema().Append(col) + p.LogicalSchemaProducer.schema.Columns = append(p.LogicalSchemaProducer.schema.Columns.Columns, col.ToInfo()) } } } } + return topN.AttachChild(p, opt) } p.Children()[0] = p.Children()[0].PushDownTopN(topN, opt) return p From 23115324fa76981095540fbf576e77550a24eeb4 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 00:20:55 +0800 Subject: [PATCH 02/31] planner: fix wrong schema when to PushDownPush Signed-off-by: Weizhen Wang --- .../core/operator/logicalop/logical_projection.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 5bc19b679df6b..12b5b185a58d8 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -28,6 +28,7 @@ import ( "github.com/pingcap/tidb/pkg/planner/util/optimizetrace" "github.com/pingcap/tidb/pkg/planner/util/optimizetrace/logicaltrace" "github.com/pingcap/tidb/pkg/planner/util/utilfuncp" + "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/intset" "github.com/pingcap/tidb/pkg/util/plancodec" ) @@ -220,17 +221,17 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * for _, by := range topN.ByItems { cols := expression.ExtractColumns(by.Expr) for _, col := range cols { - if col.ID == 0 && p.Schema().Contains(col) { + isContains := p.Schema().Contains(col) + if col.ID == 0 && isContains { // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) } } - if !p.Schema().Contains(col) { - // check whether the column is in it. + if !isContains { if p.Children()[0].Schema().Contains(col) { p.Schema().Append(col) - p.LogicalSchemaProducer.schema.Columns = append(p.LogicalSchemaProducer.schema.Columns.Columns, col.ToInfo()) + p.SetOutputNames(append(p.OutputNames(), types.EmptyName)) } } } From e71c79a15d57406ab3cadf68b8f8f5eaef8678ea Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 00:33:23 +0800 Subject: [PATCH 03/31] planner: fix wrong schema when to PushDownPush Signed-off-by: Weizhen Wang --- pkg/planner/core/operator/logicalop/logical_projection.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 12b5b185a58d8..b486fc5d7768b 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -229,6 +229,7 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * } } if !isContains { + // The columns are from the children's schema. if p.Children()[0].Schema().Contains(col) { p.Schema().Append(col) p.SetOutputNames(append(p.OutputNames(), types.EmptyName)) From 6b42e53081d4e85cdf40c5a834f4f33ab0a88dff Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 01:00:13 +0800 Subject: [PATCH 04/31] planner: fix wrong schema when to PushDownPush Signed-off-by: Weizhen Wang --- pkg/planner/core/operator/logicalop/logical_projection.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index b486fc5d7768b..18b807b815726 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -218,14 +218,16 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * } // if topN.ByItems contains a column(with ID=0) generated by projection, projection will prevent the optimizer from pushing topN down. + hasPushDownTopN := false for _, by := range topN.ByItems { cols := expression.ExtractColumns(by.Expr) for _, col := range cols { isContains := p.Schema().Contains(col) - if col.ID == 0 && isContains { + if col.ID == 0 && isContains && !hasPushDownTopN { // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) + hasPushDownTopN = true } } if !isContains { @@ -237,7 +239,9 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * } } } - return topN.AttachChild(p, opt) + if hasPushDownTopN { + return topN.AttachChild(p, opt) + } } p.Children()[0] = p.Children()[0].PushDownTopN(topN, opt) return p From b4b06f4d973d8381011c3012a07bbd7086f2af26 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 10:34:24 +0800 Subject: [PATCH 05/31] update Signed-off-by: Weizhen Wang --- pkg/planner/core/issuetest/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/planner/core/issuetest/BUILD.bazel b/pkg/planner/core/issuetest/BUILD.bazel index f6a3a87638ecb..ea7430235e48d 100644 --- a/pkg/planner/core/issuetest/BUILD.bazel +++ b/pkg/planner/core/issuetest/BUILD.bazel @@ -10,7 +10,7 @@ go_test( data = glob(["testdata/**"]), flaky = True, race = "on", - shard_count = 8, + shard_count = 9, deps = [ "//pkg/parser", "//pkg/planner", From e0b4891ec07379eaa0baa4ef2fd6da89c7042654 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 15:51:18 +0800 Subject: [PATCH 06/31] update Signed-off-by: Weizhen Wang --- pkg/planner/core/operator/logicalop/logical_projection.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 18b807b815726..3834891f057ef 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -139,7 +139,6 @@ func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column, op return p, nil } } - // for implicit projected cols, once the ancestor doesn't use it, the implicit expr will be automatically pruned here. for i := len(used) - 1; i >= 0; i-- { if !used[i] && !expression.ExprHasSetVarOrSleep(p.Exprs[i]) { @@ -230,11 +229,13 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * hasPushDownTopN = true } } + if !isContains { // The columns are from the children's schema. if p.Children()[0].Schema().Contains(col) { - p.Schema().Append(col) + p.Exprs = append(p.Exprs, col) p.SetOutputNames(append(p.OutputNames(), types.EmptyName)) + p.Schema().Append(col) } } } From 61837afb94a5edac8406c24d4a13e510eb655afa Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 16:11:18 +0800 Subject: [PATCH 07/31] update Signed-off-by: Weizhen Wang --- pkg/planner/core/issuetest/BUILD.bazel | 2 +- .../core/issuetest/planner_issue_test.go | 26 --------------- .../operator/logicalop/logical_projection.go | 3 +- .../logicalop/logicalop_test/BUILD.bazel | 2 +- .../logicalop_test/logical_operator_test.go | 33 +++++++++++++++++++ 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/pkg/planner/core/issuetest/BUILD.bazel b/pkg/planner/core/issuetest/BUILD.bazel index ea7430235e48d..f6a3a87638ecb 100644 --- a/pkg/planner/core/issuetest/BUILD.bazel +++ b/pkg/planner/core/issuetest/BUILD.bazel @@ -10,7 +10,7 @@ go_test( data = glob(["testdata/**"]), flaky = True, race = "on", - shard_count = 9, + shard_count = 8, deps = [ "//pkg/parser", "//pkg/planner", diff --git a/pkg/planner/core/issuetest/planner_issue_test.go b/pkg/planner/core/issuetest/planner_issue_test.go index 17c8a63ce476a..e9516ec7ad066 100644 --- a/pkg/planner/core/issuetest/planner_issue_test.go +++ b/pkg/planner/core/issuetest/planner_issue_test.go @@ -259,29 +259,3 @@ func TestIssue59902(t *testing.T) { " └─Selection 1.00 cop[tikv] not(isnull(test.t2.a))", " └─IndexRangeScan 1.00 cop[tikv] table:t2, index:idx(a) range: decided by [eq(test.t2.a, test.t1.a)], keep order:false, stats:pseudo")) } - -func TestABC(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec(`CREATE TABLE table_test ( -col16 json DEFAULT NULL, -col17 json DEFAULT NULL -);`) - tk.MustQuery(`SELECT - s.column16 AS column16, - s.column17 AS column17 -FROM - (SELECT - col16 -> '$[].optUid' AS column16, - JSON_UNQUOTE(JSON_EXTRACT(col17, '$[0].value')) AS column17 - FROM - (SELECT - col16, - col17 - FROM table_test) ta24e - ) AS s -ORDER BY CONVERT(column16 USING GBK) ASC,column17 ASC -LIMIT 0, - 20;`) -} diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 3834891f057ef..5de04c3a1ea0b 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -231,7 +231,8 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * } if !isContains { - // The columns are from the children's schema. + // we find this column is not in the schema, so we need to add it from the children. + // because it is projected. so we need to add columns to the projection's Exprs. if p.Children()[0].Schema().Contains(col) { p.Exprs = append(p.Exprs, col) p.SetOutputNames(append(p.OutputNames(), types.EmptyName)) diff --git a/pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel b/pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel index 05f836890faf9..a4e44563b0c01 100644 --- a/pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel +++ b/pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel @@ -10,7 +10,7 @@ go_test( "plan_execute_test.go", ], flaky = True, - shard_count = 36, + shard_count = 37, deps = [ "//pkg/domain", "//pkg/expression", diff --git a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go index 9cc74589e353e..3ed823ed43fe3 100644 --- a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go +++ b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go @@ -20,6 +20,7 @@ import ( "github.com/pingcap/tidb/pkg/expression" "github.com/pingcap/tidb/pkg/parser/ast" "github.com/pingcap/tidb/pkg/planner/core/operator/logicalop" + "github.com/pingcap/tidb/pkg/testkit" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/mock" "github.com/stretchr/testify/require" @@ -103,3 +104,35 @@ func TestLogicalApplyClone(t *testing.T) { require.True(t, clonedApply.EqualConditions[0].FuncName.L == "f2") require.True(t, apply.EqualConditions[0].FuncName.L == "f2") } + +func TestLogicalPushDownTopN(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test;") + tk.MustExec(`CREATE TABLE table_test ( +col16 json DEFAULT NULL, +col17 json DEFAULT NULL +);`) + tk.MustQuery(`explain format='brief' SELECT + s.column16 AS column16, + s.column17 AS column17 +FROM + (SELECT + col16 -> '$[].optUid' AS column16, + JSON_UNQUOTE(JSON_EXTRACT(col17, '$[0].value')) AS column17 + FROM + (SELECT + col16, + col17 + FROM table_test) ta24e + ) AS s +ORDER BY CONVERT(column16 USING GBK) ASC,column17 ASC +LIMIT 0, + 20;`).Check(testkit.Rows( + "Projection 20.00 root Column#4, Column#5, test.table_test.col17", + "└─TopN 20.00 root Column#6, Column#7, offset:0, count:20", + " └─Projection 10000.00 root Column#4, Column#5, test.table_test.col17, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#7", + " └─Projection 10000.00 root json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5, test.table_test.col17", + " └─TableReader 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) +} From 3ff3f8970d1ca23c7b2ca23c8fa201b1d1f2fcaf Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 25 Apr 2025 16:14:33 +0800 Subject: [PATCH 08/31] update Signed-off-by: Weizhen Wang --- .../operator/logicalop/logicalop_test/logical_operator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go index 3ed823ed43fe3..6b981e5bfd3f0 100644 --- a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go +++ b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go @@ -105,7 +105,7 @@ func TestLogicalApplyClone(t *testing.T) { require.True(t, apply.EqualConditions[0].FuncName.L == "f2") } -func TestLogicalPushDownTopN(t *testing.T) { +func TestLogicalProjectionPushDownTopN(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test;") From 2a4fc0260cfa6a81d6d8af648fee6052ead365d3 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 28 Apr 2025 13:51:19 +0800 Subject: [PATCH 09/31] update Signed-off-by: Weizhen Wang --- pkg/planner/core/operator/logicalop/logical_projection.go | 4 ++++ pkg/planner/core/optimizer.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 5de04c3a1ea0b..7f8f3cff858ec 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -15,6 +15,7 @@ package logicalop import ( + "fmt" "slices" "github.com/pingcap/tidb/pkg/expression" @@ -190,6 +191,9 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * if topNLogicalPlan != nil { topN = topNLogicalPlan.(*LogicalTopN) } + if !p.SCtx().GetSessionVars().InRestrictedSQL { + fmt.Println("wwz") + } if slices.ContainsFunc(p.Exprs, expression.HasAssignSetVarFunc) { return p.BaseLogicalPlan.PushDownTopN(topN, opt) } diff --git a/pkg/planner/core/optimizer.go b/pkg/planner/core/optimizer.go index 9b9ffb2fc90f2..12c4547b5b740 100644 --- a/pkg/planner/core/optimizer.go +++ b/pkg/planner/core/optimizer.go @@ -1110,6 +1110,9 @@ func logicalOptimize(ctx context.Context, flag uint64, logic base.LogicalPlan) ( continue } opt.AppendBeforeRuleOptimize(i, rule.Name(), logic.BuildPlanTrace) + if i == 8 && !logic.SCtx().GetSessionVars().InRestrictedSQL { + fmt.Println("wwz") + } var planChanged bool logic, planChanged, err = rule.Optimize(ctx, logic, opt) if err != nil { From ca100129f72ca51fd206cb79fccd319c27ebc625 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 29 Apr 2025 14:02:35 +0800 Subject: [PATCH 10/31] update Signed-off-by: Weizhen Wang --- .../core/operator/logicalop/logical_limit.go | 3 ++ .../operator/logicalop/logical_projection.go | 37 ++++++++++--------- .../core/operator/logicalop/logical_sort.go | 8 +++- .../logicalop_test/logical_operator_test.go | 15 +++++--- pkg/planner/core/optimizer.go | 4 +- pkg/planner/core/rule_topn_push_down.go | 4 ++ .../r/planner/core/plan.result | 18 +++++++++ .../integrationtest/t/planner/core/plan.test | 1 + 8 files changed, 63 insertions(+), 27 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_limit.go b/pkg/planner/core/operator/logicalop/logical_limit.go index cd6cbfd1d5952..ef7005042cd36 100644 --- a/pkg/planner/core/operator/logicalop/logical_limit.go +++ b/pkg/planner/core/operator/logicalop/logical_limit.go @@ -115,6 +115,9 @@ func (p *LogicalLimit) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt *optim if topN != nil { return topN.AttachChild(child, opt) } + if child == p.Children()[0] { + return p + } return child } diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 7f8f3cff858ec..6e82765ec2894 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -29,7 +29,6 @@ import ( "github.com/pingcap/tidb/pkg/planner/util/optimizetrace" "github.com/pingcap/tidb/pkg/planner/util/optimizetrace/logicaltrace" "github.com/pingcap/tidb/pkg/planner/util/utilfuncp" - "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/intset" "github.com/pingcap/tidb/pkg/util/plancodec" ) @@ -140,6 +139,7 @@ func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column, op return p, nil } } + // for implicit projected cols, once the ancestor doesn't use it, the implicit expr will be automatically pruned here. for i := len(used) - 1; i >= 0; i-- { if !used[i] && !expression.ExprHasSetVarOrSleep(p.Exprs[i]) { @@ -221,38 +221,39 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * } // if topN.ByItems contains a column(with ID=0) generated by projection, projection will prevent the optimizer from pushing topN down. - hasPushDownTopN := false for _, by := range topN.ByItems { cols := expression.ExtractColumns(by.Expr) for _, col := range cols { - isContains := p.Schema().Contains(col) - if col.ID == 0 && isContains && !hasPushDownTopN { + if col.ID == 0 && p.Schema().Contains(col) { // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) - hasPushDownTopN = true - } - } - - if !isContains { - // we find this column is not in the schema, so we need to add it from the children. - // because it is projected. so we need to add columns to the projection's Exprs. - if p.Children()[0].Schema().Contains(col) { - p.Exprs = append(p.Exprs, col) - p.SetOutputNames(append(p.OutputNames(), types.EmptyName)) - p.Schema().Append(col) + if p.isSetTopNChild(topN) { + return topN.AttachChild(p, opt) + } else { + return p + } } } } } - if hasPushDownTopN { - return topN.AttachChild(p, opt) - } } p.Children()[0] = p.Children()[0].PushDownTopN(topN, opt) return p } +func (p *LogicalProjection) isSetTopNChild(topN *LogicalTopN) bool { + for _, by := range topN.ByItems { + cols := expression.ExtractColumns(by.Expr) + for _, col := range cols { + if !p.Schema().Contains(col) { + return false + } + } + } + return true +} + // DeriveTopN inherits BaseLogicalPlan.<6th> implementation. // PredicateSimplification inherits BaseLogicalPlan.<7th> implementation. diff --git a/pkg/planner/core/operator/logicalop/logical_sort.go b/pkg/planner/core/operator/logicalop/logical_sort.go index 03f8deb0aa626..9d8a20bc50f7d 100644 --- a/pkg/planner/core/operator/logicalop/logical_sort.go +++ b/pkg/planner/core/operator/logicalop/logical_sort.go @@ -94,9 +94,13 @@ func (ls *LogicalSort) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt *optim if topN == nil { return ls.BaseLogicalPlan.PushDownTopN(nil, opt) } else if topN.IsLimit() { - topN.ByItems = ls.ByItems + copy(ls.ByItems, topN.ByItems) appendSortPassByItemsTraceStep(ls, topN, opt) - return ls.Children()[0].PushDownTopN(topN, opt) + child := ls.Children()[0].PushDownTopN(topN, opt) + if child == ls.Children()[0] { + return ls + } + return child } // If a TopN is pushed down, this sort is useless. return ls.Children()[0].PushDownTopN(topN, opt) diff --git a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go index 6b981e5bfd3f0..86a2233991209 100644 --- a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go +++ b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go @@ -129,10 +129,13 @@ FROM ORDER BY CONVERT(column16 USING GBK) ASC,column17 ASC LIMIT 0, 20;`).Check(testkit.Rows( - "Projection 20.00 root Column#4, Column#5, test.table_test.col17", - "└─TopN 20.00 root Column#6, Column#7, offset:0, count:20", - " └─Projection 10000.00 root Column#4, Column#5, test.table_test.col17, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#7", - " └─Projection 10000.00 root json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5, test.table_test.col17", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) + "Limit 20.00 root offset:0, count:20", + "└─Projection 20.00 root Column#4, Column#5", + " └─Sort 20.00 root Column#6, Column#5", + " └─Projection 20.00 root Column#4, Column#5, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6", + " └─Projection 20.00 root json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", + " └─Limit 20.00 root offset:0, count:20", + " └─TableReader 20.00 root data:Limit", + " └─Limit 20.00 cop[tikv] offset:0, count:20", + " └─TableFullScan 20.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) } diff --git a/pkg/planner/core/optimizer.go b/pkg/planner/core/optimizer.go index 12c4547b5b740..d3c2eec2cf4cd 100644 --- a/pkg/planner/core/optimizer.go +++ b/pkg/planner/core/optimizer.go @@ -1194,7 +1194,9 @@ func physicalOptimize(logic base.LogicalPlan, planCounter *base.PlanCounterTp) ( } return nil, 0, plannererrors.ErrInternal.GenWithStackByArgs(errMsg) } - + if !logic.SCtx().GetSessionVars().InRestrictedSQL { + fmt.Println("wwz") + } if err = t.Plan().ResolveIndices(); err != nil { return nil, 0, err } diff --git a/pkg/planner/core/rule_topn_push_down.go b/pkg/planner/core/rule_topn_push_down.go index dd66407c74c1e..8edd8155360f4 100644 --- a/pkg/planner/core/rule_topn_push_down.go +++ b/pkg/planner/core/rule_topn_push_down.go @@ -16,6 +16,7 @@ package core import ( "context" + "fmt" "github.com/pingcap/tidb/pkg/planner/core/base" "github.com/pingcap/tidb/pkg/planner/util/optimizetrace" @@ -28,6 +29,9 @@ type PushDownTopNOptimizer struct { // Optimize implements the base.LogicalOptRule.<0th> interface. func (*PushDownTopNOptimizer) Optimize(_ context.Context, p base.LogicalPlan, opt *optimizetrace.LogicalOptimizeOp) (base.LogicalPlan, bool, error) { planChanged := false + if !p.SCtx().GetSessionVars().InRestrictedSQL { + fmt.Println("wwz") + } return p.PushDownTopN(nil, opt), planChanged, nil } diff --git a/tests/integrationtest/r/planner/core/plan.result b/tests/integrationtest/r/planner/core/plan.result index 165c09f59d8ad..7f55433a91b4e 100644 --- a/tests/integrationtest/r/planner/core/plan.result +++ b/tests/integrationtest/r/planner/core/plan.result @@ -418,6 +418,24 @@ CREATE TABLE `t2`(`c1` set('kn8pu','7et','vekx6','v3','liwrh','q14','1met','nnd5 r0 r1 affected rows: 0 info: +explain format='brief' (select /*+ agg_to_cop()*/ locate(t1.c3, t1.c3) as r0, t1.c3 as r1 from t1 where not( IsNull(t1.c1)) order by r0,r1) union all (select concat_ws(',', t2.c2, t2.c1) as r0, t2.c1 as r1 from t2 order by r0, r1) order by 1 limit 273; +id estRows task access object operator info +Limit 273.00 root offset:0, count:273 +└─Union 273.00 root + ├─Projection 273.00 root cast(Column#4, longblob BINARY)->Column#9, planner__core__plan.t1.c3->Column#10 + │ └─Sort 273.00 root Column#4, planner__core__plan.t1.c3 + │ └─Projection 273.00 root locate(planner__core__plan.t1.c3, planner__core__plan.t1.c3)->Column#4, planner__core__plan.t1.c3 + │ └─Limit 273.00 root offset:0, count:273 + │ └─TableReader 273.00 root data:Limit + │ └─Limit 273.00 cop[tikv] offset:0, count:273 + │ └─TableFullScan 273.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─Projection 273.00 root cast(to_binary(Column#8), longblob BINARY)->Column#9, cast(planner__core__plan.t2.c1, tinyblob BINARY)->Column#10 + └─Sort 273.00 root Column#8, planner__core__plan.t2.c1 + └─Projection 273.00 root concat_ws(,, cast(planner__core__plan.t2.c2, var_string(5)), planner__core__plan.t2.c1)->Column#8, planner__core__plan.t2.c1 + └─Limit 273.00 root offset:0, count:273 + └─IndexReader 273.00 root index:Limit + └─Limit 273.00 cop[tikv] offset:0, count:273 + └─IndexFullScan 273.00 cop[tikv] table:t2, index:k1(c2, c1) keep order:false, stats:pseudo drop table if exists golang1, golang2; CREATE TABLE golang1 ( `fcbpdt` CHAR (8) COLLATE utf8_general_ci NOT NULL, `fcbpsq` VARCHAR (20) COLLATE utf8_general_ci NOT NULL, `procst` char (4) COLLATE utf8_general_ci DEFAULT NULL,`cipstx` VARCHAR (105) COLLATE utf8_general_ci DEFAULT NULL, `cipsst` CHAR (4) COLLATE utf8_general_ci DEFAULT NULL, `dyngtg` VARCHAR(4) COLLATE utf8_general_ci DEFAULT NULL, `blncdt` VARCHAR (8) COLLATE utf8_general_ci DEFAULT NULL, PRIMARY KEY ( fcbpdt, fcbpsq )); insert into golang1 values('20230925','12023092502158016','abc','','','',''); diff --git a/tests/integrationtest/t/planner/core/plan.test b/tests/integrationtest/t/planner/core/plan.test index 4b18143dcc46b..8f35075a3cb65 100644 --- a/tests/integrationtest/t/planner/core/plan.test +++ b/tests/integrationtest/t/planner/core/plan.test @@ -179,6 +179,7 @@ CREATE TABLE `t2`(`c1` set('kn8pu','7et','vekx6','v3','liwrh','q14','1met','nnd5 --enable_info (select /*+ agg_to_cop()*/ locate(t1.c3, t1.c3) as r0, t1.c3 as r1 from t1 where not( IsNull(t1.c1)) order by r0,r1) union all (select concat_ws(',', t2.c2, t2.c1) as r0, t2.c1 as r1 from t2 order by r0, r1) order by 1 limit 273; --disable_info +explain format='brief' (select /*+ agg_to_cop()*/ locate(t1.c3, t1.c3) as r0, t1.c3 as r1 from t1 where not( IsNull(t1.c1)) order by r0,r1) union all (select concat_ws(',', t2.c2, t2.c1) as r0, t2.c1 as r1 from t2 order by r0, r1) order by 1 limit 273; # TestIssue47445 From 4a5780a9061ba1805ef28bc95a62d773d73729a3 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 29 Apr 2025 18:40:33 +0800 Subject: [PATCH 11/31] update Signed-off-by: Weizhen Wang --- .../core/operator/logicalop/logical_limit.go | 3 --- .../operator/logicalop/logical_projection.go | 26 ++++++------------- .../logicalop_test/logical_operator_test.go | 17 ++++++------ 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_limit.go b/pkg/planner/core/operator/logicalop/logical_limit.go index ef7005042cd36..cd6cbfd1d5952 100644 --- a/pkg/planner/core/operator/logicalop/logical_limit.go +++ b/pkg/planner/core/operator/logicalop/logical_limit.go @@ -115,9 +115,6 @@ func (p *LogicalLimit) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt *optim if topN != nil { return topN.AttachChild(child, opt) } - if child == p.Children()[0] { - return p - } return child } diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 6e82765ec2894..810d62a013f31 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -227,12 +227,14 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * if col.ID == 0 && p.Schema().Contains(col) { // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { - p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) - if p.isSetTopNChild(topN) { - return topN.AttachChild(p, opt) - } else { - return p - } + topn := LogicalTopN{ + Count: topN.Count, + Offset: topN.Offset, + PreferLimitToCop: topN.PreferLimitToCop, + PartitionBy: topN.GetPartitionBy(), + }.Init(topN.SCtx(), topN.QueryBlockOffset()) + p.Children()[0] = p.Children()[0].PushDownTopN(topn, opt) + return p } } } @@ -242,18 +244,6 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * return p } -func (p *LogicalProjection) isSetTopNChild(topN *LogicalTopN) bool { - for _, by := range topN.ByItems { - cols := expression.ExtractColumns(by.Expr) - for _, col := range cols { - if !p.Schema().Contains(col) { - return false - } - } - } - return true -} - // DeriveTopN inherits BaseLogicalPlan.<6th> implementation. // PredicateSimplification inherits BaseLogicalPlan.<7th> implementation. diff --git a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go index 86a2233991209..be05dba860dde 100644 --- a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go +++ b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go @@ -129,13 +129,12 @@ FROM ORDER BY CONVERT(column16 USING GBK) ASC,column17 ASC LIMIT 0, 20;`).Check(testkit.Rows( - "Limit 20.00 root offset:0, count:20", - "└─Projection 20.00 root Column#4, Column#5", - " └─Sort 20.00 root Column#6, Column#5", - " └─Projection 20.00 root Column#4, Column#5, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6", - " └─Projection 20.00 root json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", - " └─Limit 20.00 root offset:0, count:20", - " └─TableReader 20.00 root data:Limit", - " └─Limit 20.00 cop[tikv] offset:0, count:20", - " └─TableFullScan 20.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) + "Projection 20.00 root Column#4, Column#5", + "└─Sort 20.00 root Column#6, Column#5", + " └─Projection 20.00 root Column#4, Column#5, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6", + " └─Projection 20.00 root json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", + " └─Limit 20.00 root offset:0, count:20", + " └─TableReader 20.00 root data:Limit", + " └─Limit 20.00 cop[tikv] offset:0, count:20", + " └─TableFullScan 20.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) } From 98b997974a47be1b4c4fb27b1176ddc20947b8a6 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 29 Apr 2025 18:41:22 +0800 Subject: [PATCH 12/31] remove debug Signed-off-by: Weizhen Wang --- .../operator/logicalop/logical_projection.go | 17 +++++++---- .../core/operator/logicalop/logical_sort.go | 8 ++---- .../logicalop_test/logical_operator_test.go | 28 ++++++++++++------- pkg/planner/core/optimizer.go | 6 ---- pkg/planner/core/rule_topn_push_down.go | 4 --- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 810d62a013f31..285b8f6d76ad2 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -15,7 +15,6 @@ package logicalop import ( - "fmt" "slices" "github.com/pingcap/tidb/pkg/expression" @@ -191,9 +190,6 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * if topNLogicalPlan != nil { topN = topNLogicalPlan.(*LogicalTopN) } - if !p.SCtx().GetSessionVars().InRestrictedSQL { - fmt.Println("wwz") - } if slices.ContainsFunc(p.Exprs, expression.HasAssignSetVarFunc) { return p.BaseLogicalPlan.PushDownTopN(topN, opt) } @@ -227,14 +223,23 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * if col.ID == 0 && p.Schema().Contains(col) { // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { + p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) topn := LogicalTopN{ Count: topN.Count, Offset: topN.Offset, + ByItems: make([]*util.ByItems, 0, len(p.Schema().Columns)), PreferLimitToCop: topN.PreferLimitToCop, PartitionBy: topN.GetPartitionBy(), }.Init(topN.SCtx(), topN.QueryBlockOffset()) - p.Children()[0] = p.Children()[0].PushDownTopN(topn, opt) - return p + for idx, byitem := range p.Schema().Columns { + by := &util.ByItems{ + Expr: byitem, + Desc: topN.ByItems[idx].Desc, + } + topn.ByItems = append(topn.ByItems, by) + } + topn.SetChildren(p) + return topn } } } diff --git a/pkg/planner/core/operator/logicalop/logical_sort.go b/pkg/planner/core/operator/logicalop/logical_sort.go index 9d8a20bc50f7d..03f8deb0aa626 100644 --- a/pkg/planner/core/operator/logicalop/logical_sort.go +++ b/pkg/planner/core/operator/logicalop/logical_sort.go @@ -94,13 +94,9 @@ func (ls *LogicalSort) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt *optim if topN == nil { return ls.BaseLogicalPlan.PushDownTopN(nil, opt) } else if topN.IsLimit() { - copy(ls.ByItems, topN.ByItems) + topN.ByItems = ls.ByItems appendSortPassByItemsTraceStep(ls, topN, opt) - child := ls.Children()[0].PushDownTopN(topN, opt) - if child == ls.Children()[0] { - return ls - } - return child + return ls.Children()[0].PushDownTopN(topN, opt) } // If a TopN is pushed down, this sort is useless. return ls.Children()[0].PushDownTopN(topN, opt) diff --git a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go index be05dba860dde..871c8c332f914 100644 --- a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go +++ b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go @@ -113,7 +113,7 @@ func TestLogicalProjectionPushDownTopN(t *testing.T) { col16 json DEFAULT NULL, col17 json DEFAULT NULL );`) - tk.MustQuery(`explain format='brief' SELECT + sql := `explain format='brief' SELECT s.column16 AS column16, s.column17 AS column17 FROM @@ -128,13 +128,21 @@ FROM ) AS s ORDER BY CONVERT(column16 USING GBK) ASC,column17 ASC LIMIT 0, - 20;`).Check(testkit.Rows( - "Projection 20.00 root Column#4, Column#5", - "└─Sort 20.00 root Column#6, Column#5", - " └─Projection 20.00 root Column#4, Column#5, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6", - " └─Projection 20.00 root json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", - " └─Limit 20.00 root offset:0, count:20", - " └─TableReader 20.00 root data:Limit", - " └─Limit 20.00 cop[tikv] offset:0, count:20", - " └─TableFullScan 20.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) + 20;` + tk.MustQuery(sql).Check(testkit.Rows( + "TopN 20.00 root Column#4, Column#5, offset:0, count:20", + "└─TableReader 20.00 root data:TopN", + " └─TopN 20.00 cop[tikv] Column#4, Column#5, offset:0, count:20", + " └─Projection 10000.00 cop[tikv] json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", + " └─TableFullScan 10000.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) + tk.MustExec(`INSERT INTO mysql.opt_rule_blacklist VALUES("topn_push_down");`) + tk.MustExec(`admin reload opt_rule_blacklist;`) + tk.MustQuery(sql).Check(testkit.Rows( + "Limit 20.00 root offset:0, count:20", + "└─Projection 20.00 root Column#4, Column#5", + " └─Sort 20.00 root Column#6, Column#5", + " └─Projection 10000.00 root Column#4, Column#5, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6", + " └─TableReader 10000.00 root data:Projection", + " └─Projection 10000.00 cop[tikv] json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", + " └─TableFullScan 10000.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) } diff --git a/pkg/planner/core/optimizer.go b/pkg/planner/core/optimizer.go index d3c2eec2cf4cd..058d8f25375bf 100644 --- a/pkg/planner/core/optimizer.go +++ b/pkg/planner/core/optimizer.go @@ -1110,9 +1110,6 @@ func logicalOptimize(ctx context.Context, flag uint64, logic base.LogicalPlan) ( continue } opt.AppendBeforeRuleOptimize(i, rule.Name(), logic.BuildPlanTrace) - if i == 8 && !logic.SCtx().GetSessionVars().InRestrictedSQL { - fmt.Println("wwz") - } var planChanged bool logic, planChanged, err = rule.Optimize(ctx, logic, opt) if err != nil { @@ -1194,9 +1191,6 @@ func physicalOptimize(logic base.LogicalPlan, planCounter *base.PlanCounterTp) ( } return nil, 0, plannererrors.ErrInternal.GenWithStackByArgs(errMsg) } - if !logic.SCtx().GetSessionVars().InRestrictedSQL { - fmt.Println("wwz") - } if err = t.Plan().ResolveIndices(); err != nil { return nil, 0, err } diff --git a/pkg/planner/core/rule_topn_push_down.go b/pkg/planner/core/rule_topn_push_down.go index 8edd8155360f4..dd66407c74c1e 100644 --- a/pkg/planner/core/rule_topn_push_down.go +++ b/pkg/planner/core/rule_topn_push_down.go @@ -16,7 +16,6 @@ package core import ( "context" - "fmt" "github.com/pingcap/tidb/pkg/planner/core/base" "github.com/pingcap/tidb/pkg/planner/util/optimizetrace" @@ -29,9 +28,6 @@ type PushDownTopNOptimizer struct { // Optimize implements the base.LogicalOptRule.<0th> interface. func (*PushDownTopNOptimizer) Optimize(_ context.Context, p base.LogicalPlan, opt *optimizetrace.LogicalOptimizeOp) (base.LogicalPlan, bool, error) { planChanged := false - if !p.SCtx().GetSessionVars().InRestrictedSQL { - fmt.Println("wwz") - } return p.PushDownTopN(nil, opt), planChanged, nil } From 0c01b96c467073c1c78ad079e9b431a1cb03d5da Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 29 Apr 2025 19:21:10 +0800 Subject: [PATCH 13/31] remove debug Signed-off-by: Weizhen Wang --- pkg/planner/core/optimizer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/planner/core/optimizer.go b/pkg/planner/core/optimizer.go index 058d8f25375bf..9b9ffb2fc90f2 100644 --- a/pkg/planner/core/optimizer.go +++ b/pkg/planner/core/optimizer.go @@ -1191,6 +1191,7 @@ func physicalOptimize(logic base.LogicalPlan, planCounter *base.PlanCounterTp) ( } return nil, 0, plannererrors.ErrInternal.GenWithStackByArgs(errMsg) } + if err = t.Plan().ResolveIndices(); err != nil { return nil, 0, err } From fa553fb7d5e51fc111aa999f2231a71730ad31a4 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 29 Apr 2025 19:24:54 +0800 Subject: [PATCH 14/31] remove debug Signed-off-by: Weizhen Wang --- .../r/planner/core/plan.result | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/integrationtest/r/planner/core/plan.result b/tests/integrationtest/r/planner/core/plan.result index 7f55433a91b4e..2f82c6622fcd1 100644 --- a/tests/integrationtest/r/planner/core/plan.result +++ b/tests/integrationtest/r/planner/core/plan.result @@ -420,22 +420,22 @@ affected rows: 0 info: explain format='brief' (select /*+ agg_to_cop()*/ locate(t1.c3, t1.c3) as r0, t1.c3 as r1 from t1 where not( IsNull(t1.c1)) order by r0,r1) union all (select concat_ws(',', t2.c2, t2.c1) as r0, t2.c1 as r1 from t2 order by r0, r1) order by 1 limit 273; id estRows task access object operator info -Limit 273.00 root offset:0, count:273 -└─Union 273.00 root +TopN 273.00 root Column#9, offset:0, count:273 +└─Union 546.00 root ├─Projection 273.00 root cast(Column#4, longblob BINARY)->Column#9, planner__core__plan.t1.c3->Column#10 - │ └─Sort 273.00 root Column#4, planner__core__plan.t1.c3 - │ └─Projection 273.00 root locate(planner__core__plan.t1.c3, planner__core__plan.t1.c3)->Column#4, planner__core__plan.t1.c3 - │ └─Limit 273.00 root offset:0, count:273 - │ └─TableReader 273.00 root data:Limit - │ └─Limit 273.00 cop[tikv] offset:0, count:273 - │ └─TableFullScan 273.00 cop[tikv] table:t1 keep order:false, stats:pseudo + │ └─Projection 273.00 root locate(planner__core__plan.t1.c3, planner__core__plan.t1.c3)->Column#4, planner__core__plan.t1.c3 + │ └─Projection 273.00 root planner__core__plan.t1.c3 + │ └─TopN 273.00 root Column#11, offset:0, count:273 + │ └─Projection 10000.00 root planner__core__plan.t1.c3, cast(locate(planner__core__plan.t1.c3, planner__core__plan.t1.c3), longblob BINARY)->Column#11 + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─Projection 273.00 root cast(to_binary(Column#8), longblob BINARY)->Column#9, cast(planner__core__plan.t2.c1, tinyblob BINARY)->Column#10 - └─Sort 273.00 root Column#8, planner__core__plan.t2.c1 - └─Projection 273.00 root concat_ws(,, cast(planner__core__plan.t2.c2, var_string(5)), planner__core__plan.t2.c1)->Column#8, planner__core__plan.t2.c1 - └─Limit 273.00 root offset:0, count:273 - └─IndexReader 273.00 root index:Limit - └─Limit 273.00 cop[tikv] offset:0, count:273 - └─IndexFullScan 273.00 cop[tikv] table:t2, index:k1(c2, c1) keep order:false, stats:pseudo + └─Projection 273.00 root concat_ws(,, cast(planner__core__plan.t2.c2, var_string(5)), planner__core__plan.t2.c1)->Column#8, planner__core__plan.t2.c1 + └─Projection 273.00 root planner__core__plan.t2.c1, planner__core__plan.t2.c2 + └─TopN 273.00 root Column#12, offset:0, count:273 + └─Projection 10000.00 root planner__core__plan.t2.c1, planner__core__plan.t2.c2, cast(to_binary(concat_ws(,, cast(planner__core__plan.t2.c2, var_string(5)), planner__core__plan.t2.c1)), longblob BINARY)->Column#12 + └─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t2, index:k1(c2, c1) keep order:false, stats:pseudo drop table if exists golang1, golang2; CREATE TABLE golang1 ( `fcbpdt` CHAR (8) COLLATE utf8_general_ci NOT NULL, `fcbpsq` VARCHAR (20) COLLATE utf8_general_ci NOT NULL, `procst` char (4) COLLATE utf8_general_ci DEFAULT NULL,`cipstx` VARCHAR (105) COLLATE utf8_general_ci DEFAULT NULL, `cipsst` CHAR (4) COLLATE utf8_general_ci DEFAULT NULL, `dyngtg` VARCHAR(4) COLLATE utf8_general_ci DEFAULT NULL, `blncdt` VARCHAR (8) COLLATE utf8_general_ci DEFAULT NULL, PRIMARY KEY ( fcbpdt, fcbpsq )); insert into golang1 values('20230925','12023092502158016','abc','','','',''); From fafcaa4fe4ff669cb2431132c7caa9e4e0f35955 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 29 Apr 2025 19:36:36 +0800 Subject: [PATCH 15/31] remove debug Signed-off-by: Weizhen Wang --- pkg/planner/core/operator/logicalop/logical_projection.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 285b8f6d76ad2..11c5a037ffa10 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -224,7 +224,7 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) - topn := LogicalTopN{ + newTopN := LogicalTopN{ Count: topN.Count, Offset: topN.Offset, ByItems: make([]*util.ByItems, 0, len(p.Schema().Columns)), @@ -236,10 +236,9 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * Expr: byitem, Desc: topN.ByItems[idx].Desc, } - topn.ByItems = append(topn.ByItems, by) + newTopN.ByItems = append(newTopN.ByItems, by) } - topn.SetChildren(p) - return topn + return newTopN.AttachChild(p, opt) } } } From 80170b86c7a26e7000f891d12469aade5d5c8f1a Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 29 Apr 2025 20:32:08 +0800 Subject: [PATCH 16/31] update Signed-off-by: Weizhen Wang --- pkg/executor/testdata/prepare_suite_out.json | 32 +- .../testdata/integration_suite_out.json | 16 +- .../testdata/ann_index_suite_in.json | 22 +- .../testdata/ann_index_suite_out.json | 206 ++++----- pkg/planner/core/integration_test.go | 16 +- pkg/planner/core/logical_plan_trace_test.go | 6 +- .../operator/logicalop/logical_projection.go | 46 +- .../logicalop_test/logical_operator_test.go | 11 +- .../integrationtest/r/executor/explain.result | 16 +- .../r/executor/index_merge_reader.result | 24 +- .../integrationtest/r/executor/issues.result | 124 +++--- .../r/globalindex/mem_index_merge.result | 48 +-- tests/integrationtest/r/index_merge.result | 14 +- .../r/infoschema/cluster_tables.result | 36 +- .../r/planner/core/casetest/hint/hint.result | 406 +++++++++--------- .../planner/core/casetest/integration.result | 40 +- .../physicalplantest/physical_plan.result | 30 +- .../core/issuetest/planner_issue.result | 20 + .../r/planner/core/plan_cache.result | 46 +- .../r/planner/core/plan_cost_ver2.result | 32 +- .../r/planner/core/rule_result_reorder.result | 20 +- tests/integrationtest/r/topn_push_down.result | 24 +- 22 files changed, 628 insertions(+), 607 deletions(-) diff --git a/pkg/executor/testdata/prepare_suite_out.json b/pkg/executor/testdata/prepare_suite_out.json index 69271a0bc6195..ade15d5d3e615 100644 --- a/pkg/executor/testdata/prepare_suite_out.json +++ b/pkg/executor/testdata/prepare_suite_out.json @@ -1173,10 +1173,10 @@ "6 6 6" ], "Plan": [ - "Limit_7 10.00 root offset:0, count:10", - "└─TableReader_11 10.00 root data:Limit_10", - " └─Limit_10 10.00 cop[tikv] offset:0, count:10", - " └─TableFullScan_9 10.00 cop[tikv] table:t keep order:false, stats:pseudo" + "Limit_8 10.00 root offset:0, count:10", + "└─TableReader_12 10.00 root data:Limit_11", + " └─Limit_11 10.00 cop[tikv] offset:0, count:10", + " └─TableFullScan_10 10.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, @@ -1190,10 +1190,10 @@ "6 6 6" ], "Plan": [ - "Limit_7 20.00 root offset:0, count:20", - "└─TableReader_11 20.00 root data:Limit_10", - " └─Limit_10 20.00 cop[tikv] offset:0, count:20", - " └─TableFullScan_9 20.00 cop[tikv] table:t keep order:false, stats:pseudo" + "Limit_8 20.00 root offset:0, count:20", + "└─TableReader_12 20.00 root data:Limit_11", + " └─Limit_11 20.00 cop[tikv] offset:0, count:20", + " └─TableFullScan_10 20.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, @@ -1207,10 +1207,10 @@ "1 1 1" ], "Plan": [ - "TopN_7 1.00 root test.t.b, offset:0, count:1", - "└─TableReader_14 1.00 root data:TopN_13", - " └─TopN_13 1.00 cop[tikv] test.t.b, offset:0, count:1", - " └─TableFullScan_12 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TopN_8 1.00 root test.t.b, offset:0, count:1", + "└─TableReader_15 1.00 root data:TopN_14", + " └─TopN_14 1.00 cop[tikv] test.t.b, offset:0, count:1", + " └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, @@ -1223,10 +1223,10 @@ "5 5 5" ], "Plan": [ - "TopN_7 5.00 root test.t.b, offset:0, count:5", - "└─TableReader_14 5.00 root data:TopN_13", - " └─TopN_13 5.00 cop[tikv] test.t.b, offset:0, count:5", - " └─TableFullScan_12 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TopN_8 5.00 root test.t.b, offset:0, count:5", + "└─TableReader_15 5.00 root data:TopN_14", + " └─TopN_14 5.00 cop[tikv] test.t.b, offset:0, count:5", + " └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, diff --git a/pkg/planner/core/casetest/testdata/integration_suite_out.json b/pkg/planner/core/casetest/testdata/integration_suite_out.json index b5a8786148bda..f3428175e89ae 100644 --- a/pkg/planner/core/casetest/testdata/integration_suite_out.json +++ b/pkg/planner/core/casetest/testdata/integration_suite_out.json @@ -66,19 +66,19 @@ { "SQL": "explain format = 'verbose' select * from t3 order by a limit 1", "Plan": [ - "TopN_7 1.00 53.10 root test.t3.a, offset:0, count:1", - "└─TableReader_16 1.00 49.90 root data:TopN_15", - " └─TopN_15 1.00 685.12 cop[tikv] test.t3.a, offset:0, count:1", - " └─TableFullScan_14 3.00 681.92 cop[tikv] table:t3 keep order:false" + "TopN_8 1.00 53.10 root test.t3.a, offset:0, count:1", + "└─TableReader_17 1.00 49.90 root data:TopN_16", + " └─TopN_16 1.00 685.12 cop[tikv] test.t3.a, offset:0, count:1", + " └─TableFullScan_15 3.00 681.92 cop[tikv] table:t3 keep order:false" ] }, { "SQL": "explain format = 'verbose' select * from t3 order by b limit 1", "Plan": [ - "TopN_7 1.00 53.10 root test.t3.b, offset:0, count:1", - "└─TableReader_16 1.00 49.90 root data:TopN_15", - " └─TopN_15 1.00 685.12 cop[tikv] test.t3.b, offset:0, count:1", - " └─TableFullScan_14 3.00 681.92 cop[tikv] table:t3 keep order:false" + "TopN_8 1.00 53.10 root test.t3.b, offset:0, count:1", + "└─TableReader_17 1.00 49.90 root data:TopN_16", + " └─TopN_16 1.00 685.12 cop[tikv] test.t3.b, offset:0, count:1", + " └─TableFullScan_15 3.00 681.92 cop[tikv] table:t3 keep order:false" ] }, { diff --git a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json index b682d966a5d9a..63fc4697bad10 100644 --- a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json +++ b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json @@ -66,19 +66,19 @@ { "name": "TestVectorSearchWithPKForceTiKV", "cases": [ - "explain select id from t1", + "explain format = 'brief' select id from t1", - "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", - "explain select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", + "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", - "explain select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", - "explain select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10" + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", + "explain format = 'brief' select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", + "explain format = 'brief' select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10" ] }, { diff --git a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json index 95023baaff8fe..51b2b788e3025 100644 --- a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json +++ b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json @@ -471,12 +471,12 @@ { "SQL": "explain select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_10 10.00 root Column#9, offset:0, count:10", - "└─TableReader_28 10.00 root MppVersion: 3, data:ExchangeSender_27", - " └─ExchangeSender_27 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_26 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_25 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_24 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "TopN_11 10.00 root Column#9, offset:0, count:10", + "└─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", + " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN_27 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, @@ -506,13 +506,13 @@ { "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_10 10.00 root Column#10, offset:0, count:10", - " └─TableReader_28 10.00 root MppVersion: 3, data:ExchangeSender_27", - " └─ExchangeSender_27 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_26 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_25 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_24 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection_7 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN_11 10.00 root Column#10, offset:0, count:10", + " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", + " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, @@ -530,39 +530,39 @@ { "SQL": "explain select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_10 10.00 root Column#10, offset:0, count:10", - " └─TableReader_28 10.00 root MppVersion: 3, data:ExchangeSender_27", - " └─ExchangeSender_27 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_26 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_25 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_24 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection_7 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN_11 10.00 root Column#10, offset:0, count:10", + " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", + " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7, test.t1.a, test.t1.b", - "└─TopN_10 10.00 root Column#10, offset:0, count:10", - " └─TableReader_28 10.00 root MppVersion: 3, data:ExchangeSender_27", - " └─ExchangeSender_27 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_26 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_25 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_24 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection_7 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7, test.t1.a, test.t1.b", + "└─TopN_11 10.00 root Column#10, offset:0, count:10", + " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", + " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { "SQL": "explain select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_10 10.00 root Column#10, offset:0, count:10", - " └─TableReader_28 10.00 root MppVersion: 3, data:ExchangeSender_27", - " └─ExchangeSender_27 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_26 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_25 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_24 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection_7 10.00 root test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN_11 10.00 root Column#10, offset:0, count:10", + " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", + " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null } @@ -572,125 +572,125 @@ "Name": "TestVectorSearchWithPKForceTiKV", "Cases": [ { - "SQL": "explain select id from t1", + "SQL": "explain format = 'brief' select id from t1", "Plan": [ - "TableReader_5 6000.00 root data:TableFullScan_4", - "└─TableFullScan_4 6000.00 cop[tikv] table:t1 keep order:false" + "TableReader 6000.00 root data:TableFullScan", + "└─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_8 10.00 root Column#8, offset:0, count:10", - "└─TableReader_15 10.00 root data:TopN_14", - " └─TopN_14 10.00 cop[tikv] Column#8, offset:0, count:10", - " └─Projection_13 10.00 cop[tikv] test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_12 6000.00 cop[tikv] table:t1 keep order:false" + "TopN 10.00 root Column#8, offset:0, count:10", + "└─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#8, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", + "SQL": "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", "Plan": [ - "Projection_5 6000.00 root test.t1.id", - "└─Projection_9 6000.00 root test.t1.id, test.t1.vec", - " └─Sort_6 6000.00 root Column#8", - " └─Projection_10 6000.00 root test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableReader_8 6000.00 root data:TableFullScan_7", - " └─TableFullScan_7 6000.00 cop[tikv] table:t1 keep order:false" + "Projection 6000.00 root test.t1.id", + "└─Projection 6000.00 root test.t1.id, test.t1.vec", + " └─Sort 6000.00 root Column#8", + " └─Projection 6000.00 root test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableReader 6000.00 root data:TableFullScan", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_7 10.00 root Column#7, offset:0, count:10", - "└─TableReader_14 10.00 root data:TopN_13", - " └─TopN_13 10.00 cop[tikv] Column#7, offset:0, count:10", - " └─Projection_12 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - " └─TableFullScan_11 6000.00 cop[tikv] table:t1 keep order:false" + "TopN 10.00 root Column#7, offset:0, count:10", + "└─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#7, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_8 10.00 root Column#10, offset:0, count:10", - "└─TableReader_15 10.00 root data:TopN_14", - " └─TopN_14 10.00 cop[tikv] Column#10, offset:0, count:10", - " └─Projection_13 10.00 cop[tikv] test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_12 6000.00 cop[tikv] table:t1 keep order:false" + "TopN 10.00 root Column#10, offset:0, count:10", + "└─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#10, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "Projection_7 10.00 root test.t1.a, test.t1.id, test.t1.b", - "└─TopN_8 10.00 root Column#10, offset:0, count:10", - " └─TableReader_15 10.00 root data:TopN_14", - " └─TopN_14 10.00 cop[tikv] Column#10, offset:0, count:10", - " └─Projection_13 10.00 cop[tikv] test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_12 6000.00 cop[tikv] table:t1 keep order:false" + "Projection 10.00 root test.t1.a, test.t1.id, test.t1.b", + "└─TopN 10.00 root Column#10, offset:0, count:10", + " └─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#10, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_7 10.00 root Column#8, offset:0, count:10", - " └─TableReader_14 10.00 root data:TopN_13", - " └─TopN_13 10.00 cop[tikv] Column#8, offset:0, count:10", - " └─Projection_12 10.00 cop[tikv] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_11 6000.00 cop[tikv] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#8, offset:0, count:10", + " └─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#8, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", + "SQL": "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", "Plan": [ - "Sort_4 6000.00 root Column#7", - "└─Projection_6 6000.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - " └─TableReader_8 6000.00 root data:TableFullScan_7", - " └─TableFullScan_7 6000.00 cop[tikv] table:t1 keep order:false" + "Sort 6000.00 root Column#7", + "└─Projection 6000.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + " └─TableReader 6000.00 root data:TableFullScan", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_7 10.00 root Column#8, offset:0, count:10", - " └─TableReader_14 10.00 root data:TopN_13", - " └─TopN_13 10.00 cop[tikv] Column#8, offset:0, count:10", - " └─Projection_12 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_11 6000.00 cop[tikv] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#8, offset:0, count:10", + " └─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#8, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7, test.t1.a, test.t1.b", - "└─TopN_7 10.00 root Column#8, offset:0, count:10", - " └─TableReader_14 10.00 root data:TopN_13", - " └─TopN_13 10.00 cop[tikv] Column#8, offset:0, count:10", - " └─Projection_12 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_11 6000.00 cop[tikv] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7, test.t1.a, test.t1.b", + "└─TopN 10.00 root Column#8, offset:0, count:10", + " └─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#8, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_7 10.00 root Column#8, offset:0, count:10", - " └─TableReader_14 10.00 root data:TopN_13", - " └─TopN_13 10.00 cop[tikv] Column#8, offset:0, count:10", - " └─Projection_12 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_11 6000.00 cop[tikv] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#8, offset:0, count:10", + " └─TableReader 10.00 root data:TopN", + " └─TopN 10.00 cop[tikv] Column#8, offset:0, count:10", + " └─Projection 10.00 cop[tikv] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 cop[tikv] table:t1 keep order:false" ], "Warn": null } @@ -968,4 +968,4 @@ } ] } -] \ No newline at end of file +] diff --git a/pkg/planner/core/integration_test.go b/pkg/planner/core/integration_test.go index 41a8071868e16..91750c6346ef2 100644 --- a/pkg/planner/core/integration_test.go +++ b/pkg/planner/core/integration_test.go @@ -2181,11 +2181,11 @@ func TestVirtualExprPushDown(t *testing.T) { // TopN to tikv. rows := [][]any{ - {"TopN_7", "root", "test.t.c2, offset:0, count:2"}, - {"└─TableReader_13", "root", "data:TableFullScan_12"}, - {" └─TableFullScan_12", "cop[tikv]", "keep order:false, stats:pseudo"}, + {"TopN", "root", "test.t.c2, offset:0, count:2"}, + {"└─TableReader", "root", "data:TableFullScan"}, + {" └─TableFullScan", "cop[tikv]", "keep order:false, stats:pseudo"}, } - tk.MustQuery("explain select * from t order by c2 limit 2;").CheckAt([]int{0, 2, 4}, rows) + tk.MustQuery("explain format='brief' select * from t order by c2 limit 2;").CheckAt([]int{0, 2, 4}, rows) // Projection to tikv. rows = [][]any{ @@ -2217,11 +2217,11 @@ func TestVirtualExprPushDown(t *testing.T) { // TopN to tiflash. rows = [][]any{ - {"TopN_7", "root", "test.t.c2, offset:0, count:2"}, - {"└─TableReader_15", "root", "data:TableFullScan_14"}, - {" └─TableFullScan_14", "cop[tiflash]", "keep order:false, stats:pseudo"}, + {"TopN", "root", "test.t.c2, offset:0, count:2"}, + {"└─TableReader", "root", "data:TableFullScan"}, + {" └─TableFullScan", "cop[tiflash]", "keep order:false, stats:pseudo"}, } - tk.MustQuery("explain select * from t order by c2 limit 2;").CheckAt([]int{0, 2, 4}, rows) + tk.MustQuery("explain format='brief' select * from t order by c2 limit 2;").CheckAt([]int{0, 2, 4}, rows) // Projection to tiflash. rows = [][]any{ diff --git a/pkg/planner/core/logical_plan_trace_test.go b/pkg/planner/core/logical_plan_trace_test.go index a904223bc1e65..0af775488de60 100644 --- a/pkg/planner/core/logical_plan_trace_test.go +++ b/pkg/planner/core/logical_plan_trace_test.go @@ -156,11 +156,11 @@ func TestSingleRuleTraceStep(t *testing.T) { assertReason: "TopN_7 is Limit originally", }, { - assertAction: "TopN_8 is added and pushed into Join_3's left table", + assertAction: "TopN_9 is added and pushed into Join_3's left table", assertReason: "Join_3's joinType is left outer join, and all ByItems[test.t.a] contained in left table", }, { - assertAction: "TopN_8 is added as DataSource_1's parent", + assertAction: "TopN_9 is added as DataSource_1's parent", assertReason: "TopN is pushed down", }, { @@ -183,7 +183,7 @@ func TestSingleRuleTraceStep(t *testing.T) { assertReason: "TopN_5 is Limit originally", }, { - assertAction: "TopN_5 is added as DataSource_1's parent", + assertAction: "TopN_6 is added as DataSource_1's parent", assertReason: "TopN is pushed down", }, }, diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index 11c5a037ffa10..a2eca26555983 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -193,6 +193,7 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * if slices.ContainsFunc(p.Exprs, expression.HasAssignSetVarFunc) { return p.BaseLogicalPlan.PushDownTopN(topN, opt) } + if topN != nil { exprCtx := p.SCtx().GetExprCtx() substitutedExprs := make([]expression.Expression, 0, len(topN.ByItems)) @@ -204,47 +205,46 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * } substitutedExprs = append(substitutedExprs, substituted) } + pushDownTopNByItems := make([]*util.ByItems, 0, len(topN.ByItems)) for i, by := range topN.ByItems { - by.Expr = substitutedExprs[i] + expr := substitutedExprs[i] + pushDownTopNByItems = append(pushDownTopNByItems, &util.ByItems{ + Expr: expr, + Desc: by.Desc, + }) } - // remove meaningless constant sort items. - for i := len(topN.ByItems) - 1; i >= 0; i-- { - switch topN.ByItems[i].Expr.(type) { + for i := len(pushDownTopNByItems) - 1; i >= 0; i-- { + switch pushDownTopNByItems[i].Expr.(type) { case *expression.Constant, *expression.CorrelatedColumn: - topN.ByItems = slices.Delete(topN.ByItems, i, i+1) + pushDownTopNByItems = slices.Delete(pushDownTopNByItems, i, i+1) } } - + pushDownTopN := LogicalTopN{ + Count: topN.Count, + Offset: topN.Offset, + ByItems: pushDownTopNByItems, + PreferLimitToCop: topN.PreferLimitToCop, + PartitionBy: topN.GetPartitionBy(), + }.Init(topN.SCtx(), topN.QueryBlockOffset()) // if topN.ByItems contains a column(with ID=0) generated by projection, projection will prevent the optimizer from pushing topN down. - for _, by := range topN.ByItems { + for _, by := range pushDownTopN.ByItems { cols := expression.ExtractColumns(by.Expr) for _, col := range cols { if col.ID == 0 && p.Schema().Contains(col) { // check whether the column is generated by projection if !p.Children()[0].Schema().Contains(col) { p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) - newTopN := LogicalTopN{ - Count: topN.Count, - Offset: topN.Offset, - ByItems: make([]*util.ByItems, 0, len(p.Schema().Columns)), - PreferLimitToCop: topN.PreferLimitToCop, - PartitionBy: topN.GetPartitionBy(), - }.Init(topN.SCtx(), topN.QueryBlockOffset()) - for idx, byitem := range p.Schema().Columns { - by := &util.ByItems{ - Expr: byitem, - Desc: topN.ByItems[idx].Desc, - } - newTopN.ByItems = append(newTopN.ByItems, by) - } - return newTopN.AttachChild(p, opt) + return topN.AttachChild(p, opt) } } } } + p.Children()[0] = p.Children()[0].PushDownTopN(pushDownTopN, opt) + return p } - p.Children()[0] = p.Children()[0].PushDownTopN(topN, opt) + + p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) return p } diff --git a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go index 871c8c332f914..6e40cdeaa30ff 100644 --- a/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go +++ b/pkg/planner/core/operator/logicalop/logicalop_test/logical_operator_test.go @@ -130,11 +130,12 @@ ORDER BY CONVERT(column16 USING GBK) ASC,column17 ASC LIMIT 0, 20;` tk.MustQuery(sql).Check(testkit.Rows( - "TopN 20.00 root Column#4, Column#5, offset:0, count:20", - "└─TableReader 20.00 root data:TopN", - " └─TopN 20.00 cop[tikv] Column#4, Column#5, offset:0, count:20", - " └─Projection 10000.00 cop[tikv] json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", - " └─TableFullScan 10000.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) + "Projection 20.00 root Column#4, Column#5", + "└─TopN 20.00 root Column#6, Column#5, offset:0, count:20", + " └─Projection 10000.00 root Column#4, Column#5, convert(cast(Column#4, var_string(16777216)), gbk)->Column#6", + " └─TableReader 10000.00 root data:Projection", + " └─Projection 10000.00 cop[tikv] json_extract(test.table_test.col16, $[].optUid)->Column#4, json_unquote(cast(json_extract(test.table_test.col17, $[0].value), var_string(16777216)))->Column#5", + " └─TableFullScan 10000.00 cop[tikv] table:table_test keep order:false, stats:pseudo")) tk.MustExec(`INSERT INTO mysql.opt_rule_blacklist VALUES("topn_push_down");`) tk.MustExec(`admin reload opt_rule_blacklist;`) tk.MustQuery(sql).Check(testkit.Rows( diff --git a/tests/integrationtest/r/executor/explain.result b/tests/integrationtest/r/executor/explain.result index 567fd7822e93a..b5f58eb573795 100644 --- a/tests/integrationtest/r/executor/explain.result +++ b/tests/integrationtest/r/executor/explain.result @@ -110,19 +110,19 @@ select * from t limit 1; a explain format = 'plan_cache' select * from (select * from t) t1 limit 1; id estRows task access object operator info -Limit_8 1.00 root offset:0, count:1 -└─TableReader_12 1.00 root data:Limit_11 - └─Limit_11 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan_10 1.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_9 1.00 root offset:0, count:1 +└─TableReader_13 1.00 root data:Limit_12 + └─Limit_12 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan_11 1.00 cop[tikv] table:t keep order:false, stats:pseudo show warnings; Level Code Message Warning 1105 skip non-prepared plan-cache: queries that have sub-queries are not supported explain format = 'plan_cache' select * from (select * from t) t1 limit 1; id estRows task access object operator info -Limit_8 1.00 root offset:0, count:1 -└─TableReader_12 1.00 root data:Limit_11 - └─Limit_11 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan_10 1.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_9 1.00 root offset:0, count:1 +└─TableReader_13 1.00 root data:Limit_12 + └─Limit_12 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan_11 1.00 cop[tikv] table:t keep order:false, stats:pseudo select @@last_plan_from_cache; @@last_plan_from_cache 0 diff --git a/tests/integrationtest/r/executor/index_merge_reader.result b/tests/integrationtest/r/executor/index_merge_reader.result index 5fdb7f1203bcd..d2202fe566763 100644 --- a/tests/integrationtest/r/executor/index_merge_reader.result +++ b/tests/integrationtest/r/executor/index_merge_reader.result @@ -486,12 +486,12 @@ begin; insert into t values(1, 1, -3); explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; id estRows task access object operator info -Limit_15 2.00 root offset:0, count:2 -└─UnionScan_21 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) - └─IndexMerge_25 2.00 root type: union - ├─IndexRangeScan_22(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, stats:pseudo - ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo - └─TableRowIDScan_24(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_16 2.00 root offset:0, count:2 +└─UnionScan_22 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + └─IndexMerge_26 2.00 root type: union + ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, stats:pseudo + ├─IndexRangeScan_24(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan_25(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; a b c 1 1 -3 @@ -501,12 +501,12 @@ begin; insert into t values(1, 2, 4); explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; id estRows task access object operator info -Limit_15 2.00 root offset:0, count:2 -└─UnionScan_21 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) - └─IndexMerge_25 2.00 root type: union - ├─IndexRangeScan_22(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, desc, stats:pseudo - ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, desc, stats:pseudo - └─TableRowIDScan_24(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_16 2.00 root offset:0, count:2 +└─UnionScan_22 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + └─IndexMerge_26 2.00 root type: union + ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, desc, stats:pseudo + ├─IndexRangeScan_24(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, desc, stats:pseudo + └─TableRowIDScan_25(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; a b c 1 2 4 diff --git a/tests/integrationtest/r/executor/issues.result b/tests/integrationtest/r/executor/issues.result index 679f1e3f42fe8..e25983afcfebf 100644 --- a/tests/integrationtest/r/executor/issues.result +++ b/tests/integrationtest/r/executor/issues.result @@ -905,49 +905,49 @@ TableReader_11 256.00 root NULL max_distsql_concurrency: 2 NULL cop[tikv] table:t NULL keep order:true explain analyze select * from t limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_7 100.00 root NULL NULL offset:0, count:100 -└─TableReader_11 100.00 root NULL max_distsql_concurrency: 1 NULL - └─Limit_10 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_9 100.00 cop[tikv] table:t NULL keep order:false +Limit_8 100.00 root NULL NULL offset:0, count:100 +└─TableReader_12 100.00 root NULL max_distsql_concurrency: 1 NULL + └─Limit_11 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_10 100.00 cop[tikv] table:t NULL keep order:false explain analyze select * from t limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_7 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_11 256.00 root NULL max_distsql_concurrency: 15 NULL - └─Limit_10 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_9 256.00 cop[tikv] table:t NULL keep order:false +Limit_8 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_12 256.00 root NULL max_distsql_concurrency: 15 NULL + └─Limit_11 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_10 256.00 cop[tikv] table:t NULL keep order:false explain analyze select * from t where c = 'abc' limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_8 0.26 root NULL NULL offset:0, count:100 -└─TableReader_13 0.26 root NULL max_distsql_concurrency: 15 NULL - └─Limit_12 0.26 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_11 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") - └─TableFullScan_10 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] +Limit_9 0.26 root NULL NULL offset:0, count:100 +└─TableReader_14 0.26 root NULL max_distsql_concurrency: 15 NULL + └─Limit_13 0.26 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_12 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") + └─TableFullScan_11 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] explain analyze select * from t where c = 'abc' limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_8 0.26 root NULL NULL offset:0, count:100000 -└─TableReader_13 0.26 root NULL max_distsql_concurrency: 15 NULL - └─Limit_12 0.26 cop[tikv] NULL NULL offset:0, count:100000 - └─Selection_11 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") - └─TableFullScan_10 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] +Limit_9 0.26 root NULL NULL offset:0, count:100000 +└─TableReader_14 0.26 root NULL max_distsql_concurrency: 15 NULL + └─Limit_13 0.26 cop[tikv] NULL NULL offset:0, count:100000 + └─Selection_12 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") + └─TableFullScan_11 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] explain analyze select * from t order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_10 100.00 root NULL NULL offset:0, count:100 -└─TableReader_17 100.00 root NULL max_distsql_concurrency: 1 NULL - └─Limit_16 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_15 100.00 cop[tikv] table:t NULL keep order:true +Limit_11 100.00 root NULL NULL offset:0, count:100 +└─TableReader_18 100.00 root NULL max_distsql_concurrency: 1 NULL + └─Limit_17 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_16 100.00 cop[tikv] table:t NULL keep order:true explain analyze select * from t order by id limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_11 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_21 256.00 root NULL max_distsql_concurrency: 15 NULL - └─Limit_20 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_19 256.00 cop[tikv] table:t NULL keep order:true +Limit_12 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_22 256.00 root NULL max_distsql_concurrency: 15 NULL + └─Limit_21 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_20 256.00 cop[tikv] table:t NULL keep order:true explain analyze select * from t where c = 'abd' order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_11 0.26 root NULL NULL offset:0, count:100 -└─TableReader_20 0.26 root NULL max_distsql_concurrency: 15 NULL - └─Limit_19 0.26 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_18 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abd") - └─TableFullScan_17 256.00 cop[tikv] table:t NULL keep order:true, stats:partial[c:unInitialized] +Limit_12 0.26 root NULL NULL offset:0, count:100 +└─TableReader_21 0.26 root NULL max_distsql_concurrency: 15 NULL + └─Limit_20 0.26 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_19 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abd") + └─TableFullScan_18 256.00 cop[tikv] table:t NULL keep order:true, stats:partial[c:unInitialized] select @@tidb_partition_prune_mode; @@tidb_partition_prune_mode dynamic @@ -957,49 +957,49 @@ TableReader_11 256.00 root partition:all max_distsql_concurrency: 2 NU └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:true explain analyze select * from pt limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_7 100.00 root NULL NULL offset:0, count:100 -└─TableReader_11 100.00 root partition:all max_distsql_concurrency: 7 NULL - └─Limit_10 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_9 100.00 cop[tikv] table:pt NULL keep order:false +Limit_8 100.00 root NULL NULL offset:0, count:100 +└─TableReader_12 100.00 root partition:all max_distsql_concurrency: 7 NULL + └─Limit_11 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_10 100.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_7 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_11 256.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_10 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_9 256.00 cop[tikv] table:pt NULL keep order:false +Limit_8 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_12 256.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_11 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt where val = 125 limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_8 1.00 root NULL NULL offset:0, count:100 -└─TableReader_13 1.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_12 1.00 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_11 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) - └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:false +Limit_9 1.00 root NULL NULL offset:0, count:100 +└─TableReader_14 1.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_13 1.00 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_12 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) + └─TableFullScan_11 256.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt where val = 125 limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_8 1.00 root NULL NULL offset:0, count:100000 -└─TableReader_13 1.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_12 1.00 cop[tikv] NULL NULL offset:0, count:100000 - └─Selection_11 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) - └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:false +Limit_9 1.00 root NULL NULL offset:0, count:100000 +└─TableReader_14 1.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_13 1.00 cop[tikv] NULL NULL offset:0, count:100000 + └─Selection_12 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) + └─TableFullScan_11 256.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_10 100.00 root NULL NULL offset:0, count:100 -└─TableReader_17 100.00 root partition:all max_distsql_concurrency: 1 NULL - └─Limit_16 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_15 100.00 cop[tikv] table:pt NULL keep order:true +Limit_11 100.00 root NULL NULL offset:0, count:100 +└─TableReader_18 100.00 root partition:all max_distsql_concurrency: 1 NULL + └─Limit_17 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_16 100.00 cop[tikv] table:pt NULL keep order:true explain analyze select * from pt order by id limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_11 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_21 256.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_20 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_19 256.00 cop[tikv] table:pt NULL keep order:true +Limit_12 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_22 256.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_21 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_20 256.00 cop[tikv] table:pt NULL keep order:true explain analyze select * from pt where val = 126 order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_11 1.00 root NULL NULL offset:0, count:100 -└─TableReader_20 1.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_19 1.00 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_18 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 126) - └─TableFullScan_17 256.00 cop[tikv] table:pt NULL keep order:true +Limit_12 1.00 root NULL NULL offset:0, count:100 +└─TableReader_21 1.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_20 1.00 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_19 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 126) + └─TableFullScan_18 256.00 cop[tikv] table:pt NULL keep order:true CREATE TABLE test_55837 (col1 int(4) NOT NULL, col2 bigint(4) NOT NULL, KEY col2_index (col2)); insert into test_55837 values(0,1725292800),(0,1725292800); select from_unixtime( if(col2 >9999999999, col2/1000, col2), '%Y-%m-%d %H:%i:%s') as result from test_55837; diff --git a/tests/integrationtest/r/globalindex/mem_index_merge.result b/tests/integrationtest/r/globalindex/mem_index_merge.result index f61d589ada36a..2e77fb7348562 100644 --- a/tests/integrationtest/r/globalindex/mem_index_merge.result +++ b/tests/integrationtest/r/globalindex/mem_index_merge.result @@ -157,23 +157,23 @@ a b c d ## for indexMerge union in txn with order by limit explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; id estRows task access object operator info -Limit_15 1.00 root offset:0, count:1 -└─UnionScan_22 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) - └─IndexMerge_27 1.00 root partition:all type: union - ├─IndexRangeScan_23(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo - ├─IndexRangeScan_25(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo - └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo +Limit_16 1.00 root offset:0, count:1 +└─UnionScan_23 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) + └─IndexMerge_28 1.00 root partition:all type: union + ├─IndexRangeScan_24(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + ├─IndexRangeScan_26(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo + └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; a b c d 1 2 1 1 explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; id estRows task access object operator info -Limit_15 1.00 root offset:0, count:1 -└─UnionScan_22 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) - └─IndexMerge_27 1.00 root partition:all type: union - ├─IndexRangeScan_23(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo - ├─IndexRangeScan_25(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo - └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo +Limit_16 1.00 root offset:0, count:1 +└─UnionScan_23 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) + └─IndexMerge_28 1.00 root partition:all type: union + ├─IndexRangeScan_24(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo + ├─IndexRangeScan_26(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo + └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; a b c d 2 4 2 2 @@ -181,25 +181,25 @@ commit; ## for indexMerge union with order by limit explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; id estRows task access object operator info -Projection_26 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d -└─IndexMerge_25 1.00 root partition:all type: union, limit embedded(offset:0, count:1) - ├─Limit_23(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_19 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo +Projection_27 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d +└─IndexMerge_26 1.00 root partition:all type: union, limit embedded(offset:0, count:1) ├─Limit_24(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_21 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo - └─TableRowIDScan_22(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo + │ └─IndexRangeScan_20 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + ├─Limit_25(Build) 0.91 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_22 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo + └─TableRowIDScan_23(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; a b c d 1 2 1 1 explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; id estRows task access object operator info -Projection_26 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d -└─IndexMerge_25 1.00 root partition:all type: union, limit embedded(offset:0, count:1) - ├─Limit_23(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_19 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo +Projection_27 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d +└─IndexMerge_26 1.00 root partition:all type: union, limit embedded(offset:0, count:1) ├─Limit_24(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_21 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo - └─TableRowIDScan_22(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo + │ └─IndexRangeScan_20 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo + ├─Limit_25(Build) 0.91 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_22 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo + └─TableRowIDScan_23(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; a b c d 2 4 2 2 diff --git a/tests/integrationtest/r/index_merge.result b/tests/integrationtest/r/index_merge.result index 85d66873a4953..855be678add2f 100644 --- a/tests/integrationtest/r/index_merge.result +++ b/tests/integrationtest/r/index_merge.result @@ -468,13 +468,13 @@ create table t1(c1 int, c2 int, c3 int, key(c1), key(c2)); insert into t1 values(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5); explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 order by 1 limit 1 offset 2; id estRows task access object operator info -TopN_9 1.00 root index_merge.t1.c1, offset:2, count:1 -└─IndexMerge_18 3.00 root type: union - ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo - ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo - └─TopN_17(Probe) 3.00 cop[tikv] index_merge.t1.c1, offset:0, count:3 - └─Selection_16 1841.86 cop[tikv] lt(index_merge.t1.c3, 10) - └─TableRowIDScan_15 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_10 1.00 root index_merge.t1.c1, offset:2, count:1 +└─IndexMerge_19 3.00 root type: union + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo + └─TopN_18(Probe) 3.00 cop[tikv] index_merge.t1.c1, offset:0, count:3 + └─Selection_17 1841.86 cop[tikv] lt(index_merge.t1.c3, 10) + └─TableRowIDScan_16 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 order by 1 limit 1 offset 2; c1 c2 c3 3 3 3 diff --git a/tests/integrationtest/r/infoschema/cluster_tables.result b/tests/integrationtest/r/infoschema/cluster_tables.result index 043cc263b3500..096300dec7d19 100644 --- a/tests/integrationtest/r/infoschema/cluster_tables.result +++ b/tests/integrationtest/r/infoschema/cluster_tables.result @@ -12,10 +12,10 @@ create session binding from history using plan digest '20cf414ff6bd6fff3de17a266 drop binding for sql digest '83de0854921816c038565229b8008f5d679d373d16bf6b2a5cacd5937e11ea21'; explain select * from information_schema.cluster_slow_query order by time limit 1; id estRows task access object operator info -TopN_7 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 -└─TableReader_16 1.00 root data:Limit_15 - └─Limit_15 1.00 cop[tidb] offset:0, count:1 - └─MemTableScan_14 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_8 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 +└─TableReader_17 1.00 root data:Limit_16 + └─Limit_16 1.00 cop[tidb] offset:0, count:1 + └─MemTableScan_15 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query order by time; id estRows task access object operator info Sort_4 10000.00 root information_schema.cluster_slow_query.time @@ -23,10 +23,10 @@ Sort_4 10000.00 root information_schema.cluster_slow_query.time └─MemTableScan_7 10000.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query order by time desc limit 1; id estRows task access object operator info -TopN_7 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 -└─TableReader_16 1.00 root data:Limit_15 - └─Limit_15 1.00 cop[tidb] offset:0, count:1 - └─MemTableScan_14 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_8 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 +└─TableReader_17 1.00 root data:Limit_16 + └─Limit_16 1.00 cop[tidb] offset:0, count:1 + └─MemTableScan_15 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query order by time desc; id estRows task access object operator info Sort_4 10000.00 root information_schema.cluster_slow_query.time:desc @@ -34,11 +34,11 @@ Sort_4 10000.00 root information_schema.cluster_slow_query.time:desc └─MemTableScan_7 10000.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time limit 1; id estRows task access object operator info -TopN_8 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 -└─TableReader_18 1.00 root data:Limit_17 - └─Limit_17 1.00 cop[tidb] offset:0, count:1 - └─Selection_16 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") - └─MemTableScan_15 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_9 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 +└─TableReader_19 1.00 root data:Limit_18 + └─Limit_18 1.00 cop[tidb] offset:0, count:1 + └─Selection_17 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") + └─MemTableScan_16 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time; id estRows task access object operator info Sort_5 166.42 root information_schema.cluster_slow_query.time @@ -47,11 +47,11 @@ Sort_5 166.42 root information_schema.cluster_slow_query.time └─MemTableScan_8 250.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time desc limit 1; id estRows task access object operator info -TopN_8 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 -└─TableReader_18 1.00 root data:Limit_17 - └─Limit_17 1.00 cop[tidb] offset:0, count:1 - └─Selection_16 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") - └─MemTableScan_15 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_9 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 +└─TableReader_19 1.00 root data:Limit_18 + └─Limit_18 1.00 cop[tidb] offset:0, count:1 + └─Selection_17 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") + └─MemTableScan_16 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time desc; id estRows task access object operator info Sort_5 166.42 root information_schema.cluster_slow_query.time:desc diff --git a/tests/integrationtest/r/planner/core/casetest/hint/hint.result b/tests/integrationtest/r/planner/core/casetest/hint/hint.result index 9af080d6b214a..ae53ad85735b2 100644 --- a/tests/integrationtest/r/planner/core/casetest/hint/hint.result +++ b/tests/integrationtest/r/planner/core/casetest/hint/hint.result @@ -37,208 +37,208 @@ select /*+ order_index(thh, a) */ * from thh where a<1 order by a limit 1; a b explain select /*+ order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -Projection_17 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_16 1.00 root limit embedded(offset:0, count:1) - ├─Limit_15(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_18 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_17 1.00 root limit embedded(offset:0, count:1) + ├─Limit_16(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─TableReader_15 1.00 root data:Limit_14 - └─Limit_14 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_16 1.00 root data:Limit_15 + └─Limit_15 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_16 1.00 root - ├─TopN_15(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_17 1.00 root + ├─TopN_16(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_15 1.00 root data:TopN_14 - └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 where a<10 limit 1; id estRows task access object operator info -IndexLookUp_13 1.00 root limit embedded(offset:0, count:1) -├─Limit_12(Build) 1.00 cop[tikv] offset:0, count:1 -│ └─IndexRangeScan_10 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo -└─TableRowIDScan_11(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexLookUp_14 1.00 root limit embedded(offset:0, count:1) +├─Limit_13(Build) 1.00 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_11 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo +└─TableRowIDScan_12(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t where a<10 limit 1; id estRows task access object operator info -Limit_8 1.00 root offset:0, count:1 -└─TableReader_12 1.00 root data:Limit_11 - └─Limit_11 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_10 333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +Limit_9 1.00 root offset:0, count:1 +└─TableReader_13 1.00 root data:Limit_12 + └─Limit_12 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_11 333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_b) */ * from t1 where b<10 order by b limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 - └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) - └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 + └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) + └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't1' explain select /*+ order_index(t, idx_b) */ * from t where b<10 order by b limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 - └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) - └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 + └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) + └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't' explain select /*+ no_order_index(t1, idx_b) */ * from t1 where b<10 order by b limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 - └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) - └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 + └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) + └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't1' explain select /*+ no_order_index(t, idx_b) */ * from t where b<10 order by b limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 - └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) - └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 + └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) + └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't' explain select /*+ order_index(t1, idx_a) use_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) - ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) + ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) */ * from t1 use index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) - ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) + ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) force_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) - ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) + ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) */ * from t1 force index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) - ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) + ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) ignore_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) - └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) + └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t, primary) use_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─TableReader_16 1.00 root data:Limit_15 - └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_17 1.00 root data:Limit_16 + └─Limit_16 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ order_index(t, primary) */ * from t use index(primary) where a<10 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─TableReader_16 1.00 root data:Limit_15 - └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_17 1.00 root data:Limit_16 + └─Limit_16 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ order_index(t, primary) force_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─TableReader_16 1.00 root data:Limit_15 - └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_17 1.00 root data:Limit_16 + └─Limit_16 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ order_index(t, primary) */ * from t force index(primary) where a<10 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─TableReader_16 1.00 root data:Limit_15 - └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_17 1.00 root data:Limit_16 + └─Limit_16 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ order_index(t, primary) ignore_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─TableReader_15 1.00 root data:Limit_14 - └─Limit_14 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_16 1.00 root data:Limit_15 + └─Limit_15 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ no_order_index(t, primary) use_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t use index(primary) where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) force_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t force index(primary) where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) ignore_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_15 1.00 root data:TopN_14 - └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) use_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_18 1.00 root - ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_19 1.00 root + ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 use index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_18 1.00 root - ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_19 1.00 root + ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) force_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_18 1.00 root - ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_19 1.00 root + ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 force index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_18 1.00 root - ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_19 1.00 root + ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) ignore_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) - └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─TableReader_17 1.00 root data:TopN_16 + └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) + └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ qb_name(qb, v) order_index(t1@qb, idx_a) */ * from v; id estRows task access object operator info Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b @@ -267,93 +267,93 @@ TopN_10 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 └─TableRangeScan_15 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain WITH CTE AS (select /*+ order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; id estRows task access object operator info -HashAgg_31 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 -└─Union_32 1.28 root - ├─Selection_34 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) - │ └─CTEFullScan_35 0.80 root CTE:cte data:CTE_0 - └─Selection_37 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) - └─CTEFullScan_38 0.80 root CTE:cte data:CTE_0 +HashAgg_32 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 +└─Union_33 1.28 root + ├─Selection_35 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) + │ └─CTEFullScan_36 0.80 root CTE:cte data:CTE_0 + └─Selection_38 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) + └─CTEFullScan_39 0.80 root CTE:cte data:CTE_0 CTE_0 0.80 root Non-Recursive CTE -└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) - └─Projection_29 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b - └─IndexLookUp_28 1.00 root limit embedded(offset:0, count:1) - ├─Limit_27(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_25 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) + └─Projection_30 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b + └─IndexLookUp_29 1.00 root limit embedded(offset:0, count:1) + ├─Limit_28(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_26 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain WITH CTE AS (select /*+ order_index(t, primary) */ * from t where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; id estRows task access object operator info -HashAgg_28 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 -└─Union_29 1.28 root - ├─Selection_31 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) - │ └─CTEFullScan_32 0.80 root CTE:cte data:CTE_0 - └─Selection_34 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) - └─CTEFullScan_35 0.80 root CTE:cte data:CTE_0 -CTE_0 0.80 root Non-Recursive CTE -└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) - └─Limit_23 1.00 root offset:0, count:1 - └─TableReader_27 1.00 root data:Limit_26 - └─Limit_26 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_25 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo -explain WITH CTE AS (select /*+ no_order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; -id estRows task access object operator info -HashAgg_29 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 +HashAgg_29 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 └─Union_30 1.28 root - ├─Selection_32 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) + ├─Selection_32 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) │ └─CTEFullScan_33 0.80 root CTE:cte data:CTE_0 - └─Selection_35 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) + └─Selection_35 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) └─CTEFullScan_36 0.80 root CTE:cte data:CTE_0 CTE_0 0.80 root Non-Recursive CTE -└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) - └─TopN_21 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - └─IndexLookUp_28 1.00 root - ├─TopN_27(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_25 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) + └─Limit_24 1.00 root offset:0, count:1 + └─TableReader_28 1.00 root data:Limit_27 + └─Limit_27 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_26 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +explain WITH CTE AS (select /*+ no_order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; +id estRows task access object operator info +HashAgg_30 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 +└─Union_31 1.28 root + ├─Selection_33 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) + │ └─CTEFullScan_34 0.80 root CTE:cte data:CTE_0 + └─Selection_36 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) + └─CTEFullScan_37 0.80 root CTE:cte data:CTE_0 +CTE_0 0.80 root Non-Recursive CTE +└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) + └─TopN_22 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + └─IndexLookUp_29 1.00 root + ├─TopN_28(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_26 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain WITH CTE AS (select /*+ no_order_index(t, primary) */ * from t where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; id estRows task access object operator info -HashAgg_28 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 -└─Union_29 1.28 root - ├─Selection_31 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) - │ └─CTEFullScan_32 0.80 root CTE:cte data:CTE_0 - └─Selection_34 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) - └─CTEFullScan_35 0.80 root CTE:cte data:CTE_0 +HashAgg_29 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 +└─Union_30 1.28 root + ├─Selection_32 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) + │ └─CTEFullScan_33 0.80 root CTE:cte data:CTE_0 + └─Selection_35 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) + └─CTEFullScan_36 0.80 root CTE:cte data:CTE_0 CTE_0 0.80 root Non-Recursive CTE -└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) - └─TopN_20 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableReader_27 1.00 root data:TopN_26 - └─TopN_26 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_25 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) + └─TopN_21 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableReader_28 1.00 root data:TopN_27 + └─TopN_27 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_26 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ order_index(th, a) */ a from th where a<1 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─IndexReader_15 1.00 root partition:all index:Limit_14 - └─Limit_14 1.00 cop[tikv] offset:0, count:1 - └─IndexRangeScan_13 1.00 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─IndexReader_16 1.00 root partition:all index:Limit_15 + └─Limit_15 1.00 cop[tikv] offset:0, count:1 + └─IndexRangeScan_14 1.00 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:true, stats:pseudo explain select /*+ no_order_index(th, a) */ a from th where a<1 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.th.a, offset:0, count:1 -└─IndexReader_15 1.00 root partition:all index:TopN_14 - └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.th.a, offset:0, count:1 - └─IndexRangeScan_13 3323.33 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.th.a, offset:0, count:1 +└─IndexReader_16 1.00 root partition:all index:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.th.a, offset:0, count:1 + └─IndexRangeScan_14 3323.33 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:false, stats:pseudo explain select /*+ order_index(thp, primary) */ a from thp where a<1 order by a limit 1; id estRows task access object operator info -Limit_11 1.00 root offset:0, count:1 -└─TableReader_15 1.00 root partition:all data:Limit_14 - └─Limit_14 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_16 1.00 root partition:all data:Limit_15 + └─Limit_15 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:true, stats:pseudo explain select /*+ no_order_index(thp, primary) */ a from thp where a<1 order by a limit 1; id estRows task access object operator info -TopN_8 1.00 root planner__core__casetest__hint__hint.thp.a, offset:0, count:1 -└─TableReader_15 1.00 root partition:all data:TopN_14 - └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.thp.a, offset:0, count:1 - └─TableRangeScan_13 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.thp.a, offset:0, count:1 +└─TableReader_16 1.00 root partition:all data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.thp.a, offset:0, count:1 + └─TableRangeScan_14 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:false, stats:pseudo explain select /*+ order_index(thh, a) */ * from thh where a<1 order by a limit 1; id estRows task access object operator info -Projection_17 1.00 root planner__core__casetest__hint__hint.thh.a, planner__core__casetest__hint__hint.thh.b -└─IndexLookUp_16 1.00 root partition:all limit embedded(offset:0, count:1) - ├─Limit_15(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_13 1.00 cop[tikv] table:thh, index:a(a) range:[-inf,1), keep order:true, stats:pseudo - └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:thh keep order:false, stats:pseudo +Projection_18 1.00 root planner__core__casetest__hint__hint.thh.a, planner__core__casetest__hint__hint.thh.b +└─IndexLookUp_17 1.00 root partition:all limit embedded(offset:0, count:1) + ├─Limit_16(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_14 1.00 cop[tikv] table:thh, index:a(a) range:[-inf,1), keep order:true, stats:pseudo + └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:thh keep order:false, stats:pseudo set tidb_cost_model_version=2; drop view if exists v, v1, v2; drop table if exists t, t1, t2; diff --git a/tests/integrationtest/r/planner/core/casetest/integration.result b/tests/integrationtest/r/planner/core/casetest/integration.result index 284022e10388d..97e30d0604dec 100644 --- a/tests/integrationtest/r/planner/core/casetest/integration.result +++ b/tests/integrationtest/r/planner/core/casetest/integration.result @@ -1151,18 +1151,18 @@ TableReader_7 3.00 130.42 root data:Selection_6 └─TableFullScan_5 5.00 1136.54 cop[tikv] table:t keep order:false explain format = 'verbose' select * from t where b = 6 order by a limit 1; id estRows estCost task access object operator info -Limit_11 1.00 98.74 root offset:0, count:1 -└─TableReader_24 1.00 98.74 root data:Limit_23 - └─Limit_23 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_22 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_21 5.00 1136.54 cop[tikv] table:t keep order:true +Limit_12 1.00 98.74 root offset:0, count:1 +└─TableReader_25 1.00 98.74 root data:Limit_24 + └─Limit_24 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_23 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_22 5.00 1136.54 cop[tikv] table:t keep order:true explain format = 'verbose' select * from t where b = 6 limit 1; id estRows estCost task access object operator info -Limit_8 1.00 98.74 root offset:0, count:1 -└─TableReader_13 1.00 98.74 root data:Limit_12 - └─Limit_12 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_11 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_10 5.00 1136.54 cop[tikv] table:t keep order:false +Limit_9 1.00 98.74 root offset:0, count:1 +└─TableReader_14 1.00 98.74 root data:Limit_13 + └─Limit_13 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_12 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_11 5.00 1136.54 cop[tikv] table:t keep order:false set tidb_opt_prefer_range_scan = 1; explain format = 'verbose' select * from t where b > 5; id estRows estCost task access object operator info @@ -1171,18 +1171,18 @@ TableReader_7 3.00 130.42 root data:Selection_6 └─TableFullScan_5 5.00 1136.54 cop[tikv] table:t keep order:false explain format = 'verbose' select * from t where b = 6 order by a limit 1; id estRows estCost task access object operator info -Limit_11 1.00 98.74 root offset:0, count:1 -└─TableReader_24 1.00 98.74 root data:Limit_23 - └─Limit_23 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_22 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_21 5.00 1136.54 cop[tikv] table:t keep order:true +Limit_12 1.00 98.74 root offset:0, count:1 +└─TableReader_25 1.00 98.74 root data:Limit_24 + └─Limit_24 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_23 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_22 5.00 1136.54 cop[tikv] table:t keep order:true explain format = 'verbose' select * from t where b = 6 limit 1; id estRows estCost task access object operator info -Limit_8 1.00 98.74 root offset:0, count:1 -└─TableReader_13 1.00 98.74 root data:Limit_12 - └─Limit_12 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_11 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_10 5.00 1136.54 cop[tikv] table:t keep order:false +Limit_9 1.00 98.74 root offset:0, count:1 +└─TableReader_14 1.00 98.74 root data:Limit_13 + └─Limit_13 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_12 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_11 5.00 1136.54 cop[tikv] table:t keep order:false set @@tidb_enable_chunk_rpc = default; set tidb_opt_prefer_range_scan = default; drop table if exists t; diff --git a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result index 0228e7e0d5a4e..7f16599228e35 100644 --- a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result +++ b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result @@ -823,20 +823,20 @@ HashAgg_16 8000.00 root group by:planner__core__casetest__physicalplantest__phy └─TableFullScan_15 10000.00 cop[tikv] table:test keep order:false, stats:pseudo explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test limit 1) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain limit and ref by CET1 recursive part cannot be inlined; id estRows task access object operator info -CTEFullScan_42 16400.00 root CTE:cte1 data:CTE_1 +CTEFullScan_43 16400.00 root CTE:cte1 data:CTE_1 CTE_1 16400.00 root Recursive CTE ├─TableReader_22(Seed Part) 10000.00 root data:TableFullScan_21 │ └─TableFullScan_21 10000.00 cop[tikv] table:test keep order:false, stats:pseudo -└─HashJoin_36(Recursive Part) 6400.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.test.a, planner__core__casetest__physicalplantest__physical_plan.test.a)] - ├─Selection_37(Build) 0.80 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) - │ └─CTEFullScan_38 1.00 root CTE:cte data:CTE_0 - └─Selection_39(Probe) 8000.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) - └─CTETable_40 10000.00 root Scan on CTE_1 +└─HashJoin_37(Recursive Part) 6400.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.test.a, planner__core__casetest__physicalplantest__physical_plan.test.a)] + ├─Selection_38(Build) 0.80 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + │ └─CTEFullScan_39 1.00 root CTE:cte data:CTE_0 + └─Selection_40(Probe) 8000.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + └─CTETable_41 10000.00 root Scan on CTE_1 CTE_0 1.00 root Non-Recursive CTE -└─Limit_28(Seed Part) 1.00 root offset:0, count:1 - └─TableReader_32 1.00 root data:Limit_31 - └─Limit_31 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan_30 1.00 cop[tikv] table:test keep order:false, stats:pseudo +└─Limit_29(Seed Part) 1.00 root offset:0, count:1 + └─TableReader_33 1.00 root data:Limit_32 + └─Limit_32 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan_31 1.00 cop[tikv] table:test keep order:false, stats:pseudo explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test order by a) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain order by and ref by CET1 recursive part cannot be inlined; id estRows task access object operator info CTEFullScan_35 20000.00 root CTE:cte1 data:CTE_1 @@ -3997,12 +3997,12 @@ Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type set tidb_cost_model_version=DEFAULT; explain select /*+ USE_INDEX_MERGE(t3, aid_c1, aid_c2) */ * from t3 where (aid = 1 and c1='aaa') or (aid = 1 and c2='bbb') limit 1; id estRows task access object operator info -IndexMerge_20 1.00 root type: union, limit embedded(offset:0, count:1) -├─Limit_18(Build) 0.01 cop[tikv] offset:0, count:1 -│ └─IndexRangeScan_11 0.01 cop[tikv] table:t3, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo +IndexMerge_21 1.00 root type: union, limit embedded(offset:0, count:1) ├─Limit_19(Build) 0.01 cop[tikv] offset:0, count:1 -│ └─IndexRangeScan_12 0.01 cop[tikv] table:t3, index:aid_c2(aid, c2) range:[1 "bbb",1 "bbb"], keep order:false, stats:pseudo -└─TableRowIDScan_13(Probe) 1.00 cop[tikv] table:t3 keep order:false, stats:pseudo +│ └─IndexRangeScan_12 0.01 cop[tikv] table:t3, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo +├─Limit_20(Build) 0.01 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_13 0.01 cop[tikv] table:t3, index:aid_c2(aid, c2) range:[1 "bbb",1 "bbb"], keep order:false, stats:pseudo +└─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t3 keep order:false, stats:pseudo show warnings; Level Code Message CREATE TABLE `tbl_43` ( diff --git a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result index 65010f3b2819a..a20b30adf9b2a 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -12,12 +12,21 @@ KEY 19dc3c2d (57fd8d09) ) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin COMMENT='320f8401'; explain format='brief' select /*+ use_index_merge( `aa311c3c` ) */ `aa311c3c`.`43b06e99` as r0 , `aa311c3c`.`6302d8ac` as r1 from `aa311c3c` where `aa311c3c`.`b80b3746` = 3 or not( `aa311c3c`.`57fd8d09` >= '2008' ) order by r0,r1 limit 95; id estRows task access object operator info +<<<<<<< HEAD TopN 95.00 root planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 └─IndexMerge 95.00 root type: union ├─IndexRangeScan(Build) 10.00 cop[tikv] table:aa311c3c, index:464b386e(b80b3746) range:[3,3], keep order:false, stats:pseudo ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:aa311c3c, index:3080c821(57fd8d09, 43b06e99, b80b3746) range:[-inf,2008), keep order:false, stats:pseudo └─TopN(Probe) 95.00 cop[tikv] planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 └─TableRowIDScan 3330.01 cop[tikv] table:aa311c3c keep order:false, stats:pseudo +======= +TopN_10 95.00 root planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 +└─IndexMerge_18 95.00 root type: union + ├─IndexRangeScan_14(Build) 10.00 cop[tikv] table:aa311c3c, index:464b386e(b80b3746) range:[3,3], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:aa311c3c, index:3080c821(57fd8d09, 43b06e99, b80b3746) range:[-inf,2008), keep order:false, stats:pseudo + └─TopN_17(Probe) 95.00 cop[tikv] planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 + └─TableRowIDScan_16 3330.01 cop[tikv] table:aa311c3c keep order:false, stats:pseudo +>>>>>>> 776d9f4117 (update) CREATE TABLE t1(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10)); CREATE TABLE t2(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10)); INSERT INTO t1 values(1,NULL,NULL,null),(2,NULL,NULL,null),(3,NULL,NULL,null); @@ -110,6 +119,7 @@ create table tbl_39(col_239 year(4) not null default '2009', primary key(col_239 insert into tbl_39 values (1994),(1995),(1996),(1997); explain format='brief' select /*+ use_index_merge( tbl_39) */ col_239 from tbl_39 where not( tbl_39.col_239 not in ( '1994' ) ) and tbl_39.col_239 not in ( '2004' , '2010' , '2010' ) or not( tbl_39.col_239 <= '1996' ) and not( tbl_39.col_239 between '2026' and '2011' ) order by tbl_39.col_239 limit 382; id estRows task access object operator info +<<<<<<< HEAD Limit 382.00 root offset:0, count:382 └─UnionScan 382.00 root or(and(not(not(eq(planner__core__issuetest__planner_issue.tbl_39.col_239, 1994))), not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010))), and(not(le(planner__core__issuetest__planner_issue.tbl_39.col_239, 1996)), not(and(ge(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), le(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011))))) └─IndexMerge 382.00 root type: union @@ -118,6 +128,16 @@ Limit 382.00 root offset:0, count:382 ├─Selection(Build) 458.26 cop[tikv] or(lt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), gt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011)) │ └─IndexRangeScan 477.36 cop[tikv] table:tbl_39, index:idx_223(col_239) range:(1996,+inf], keep order:true, stats:pseudo └─TableRowIDScan(Probe) 382.00 cop[tikv] table:tbl_39 keep order:false, stats:pseudo +======= +Limit_16 382.00 root offset:0, count:382 +└─UnionScan_24 382.00 root or(and(not(not(eq(planner__core__issuetest__planner_issue.tbl_39.col_239, 1994))), not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010))), and(not(le(planner__core__issuetest__planner_issue.tbl_39.col_239, 1996)), not(and(ge(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), le(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011))))) + └─IndexMerge_30 382.00 root type: union + ├─Selection_26(Build) 0.05 cop[tikv] not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010)) + │ └─IndexRangeScan_25 0.14 cop[tikv] table:tbl_39, index:PRIMARY(col_239) range:[1994,1994], keep order:true, stats:pseudo + ├─Selection_28(Build) 458.26 cop[tikv] or(lt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), gt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011)) + │ └─IndexRangeScan_27 477.36 cop[tikv] table:tbl_39, index:idx_223(col_239) range:(1996,+inf], keep order:true, stats:pseudo + └─TableRowIDScan_29(Probe) 382.00 cop[tikv] table:tbl_39 keep order:false, stats:pseudo +>>>>>>> 776d9f4117 (update) select /*+ use_index_merge( tbl_39) */ col_239 from tbl_39 where not( tbl_39.col_239 not in ( '1994' ) ) and tbl_39.col_239 not in ( '2004' , '2010' , '2010' ) or not( tbl_39.col_239 <= '1996' ) and not( tbl_39.col_239 between '2026' and '2011' ) order by tbl_39.col_239 limit 382; col_239 1994 diff --git a/tests/integrationtest/r/planner/core/plan_cache.result b/tests/integrationtest/r/planner/core/plan_cache.result index 38a7be8f16f4c..70effae8c302c 100644 --- a/tests/integrationtest/r/planner/core/plan_cache.result +++ b/tests/integrationtest/r/planner/core/plan_cache.result @@ -1637,10 +1637,10 @@ select @@last_plan_from_cache; 0 explain format = 'row' select * from t limit 1; id estRows task access object operator info -Limit_7 1.00 root offset:0, count:1 -└─IndexReader_12 1.00 root index:Limit_11 - └─Limit_11 1.00 cop[tikv] offset:0, count:1 - └─IndexFullScan_10 1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +Limit_8 1.00 root offset:0, count:1 +└─IndexReader_13 1.00 root index:Limit_12 + └─Limit_12 1.00 cop[tikv] offset:0, count:1 + └─IndexFullScan_11 1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo explain format = 'brief' select * from t limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 @@ -1650,45 +1650,45 @@ Limit 1.00 root offset:0, count:1 explain format = 'dot' select * from t limit 1; dot contents -digraph Limit_7 { -subgraph cluster7{ +digraph Limit_8 { +subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "root" -"Limit_7" -> "IndexReader_12" +"Limit_8" -> "IndexReader_13" } -subgraph cluster11{ +subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "cop" -"Limit_11" -> "IndexFullScan_10" +"Limit_12" -> "IndexFullScan_11" } -"IndexReader_12" -> "Limit_11" +"IndexReader_13" -> "Limit_12" } explain format = 'tidb_json' select * from t limit 1; TiDB_JSON [ { - "id": "Limit_7", + "id": "Limit_8", "estRows": "1.00", "taskType": "root", "operatorInfo": "offset:0, count:1", "subOperators": [ { - "id": "IndexReader_12", + "id": "IndexReader_13", "estRows": "1.00", "taskType": "root", - "operatorInfo": "index:Limit_11", + "operatorInfo": "index:Limit_12", "subOperators": [ { - "id": "Limit_11", + "id": "Limit_12", "estRows": "1.00", "taskType": "cop[tikv]", "operatorInfo": "offset:0, count:1", "subOperators": [ { - "id": "IndexFullScan_10", + "id": "IndexFullScan_11", "estRows": "1.00", "taskType": "cop[tikv]", "accessObject": "table:t, index:a(a)", @@ -1704,16 +1704,16 @@ TiDB_JSON explain format = 'verbose' select * from t limit 1; id estRows estCost task access object operator info -Limit_7 1.00 12.97 root offset:0, count:1 -└─IndexReader_12 1.00 12.97 root index:Limit_11 - └─Limit_11 1.00 162.80 cop[tikv] offset:0, count:1 - └─IndexFullScan_10 1.00 162.80 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +Limit_8 1.00 12.97 root offset:0, count:1 +└─IndexReader_13 1.00 12.97 root index:Limit_12 + └─Limit_12 1.00 162.80 cop[tikv] offset:0, count:1 + └─IndexFullScan_11 1.00 162.80 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo explain format = 'cost_trace' select * from t limit 1; id estRows estCost costFormula task access object operator info -Limit_7 1.00 12.97 ((((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00) root offset:0, count:1 -└─IndexReader_12 1.00 12.97 (((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:Limit_11 - └─Limit_11 1.00 162.80 ((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00) cop[tikv] offset:0, count:1 - └─IndexFullScan_10 1.00 162.80 (scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +Limit_8 1.00 12.97 ((((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00) root offset:0, count:1 +└─IndexReader_13 1.00 12.97 (((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:Limit_12 + └─Limit_12 1.00 162.80 ((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00) cop[tikv] offset:0, count:1 + └─IndexFullScan_11 1.00 162.80 (scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo set tidb_enable_non_prepared_plan_cache=DEFAULT; drop table if exists t, t1, t2; CREATE TABLE `t1` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/tests/integrationtest/r/planner/core/plan_cost_ver2.result b/tests/integrationtest/r/planner/core/plan_cost_ver2.result index 5ddbf4080fede..ad80f4a28be76 100644 --- a/tests/integrationtest/r/planner/core/plan_cost_ver2.result +++ b/tests/integrationtest/r/planner/core/plan_cost_ver2.result @@ -4,18 +4,18 @@ insert into t values (1); analyze table t all columns; explain format='verbose' select /*+ limit_to_cop() */ * from t where a=1 order by a limit 1; id estRows estCost task access object operator info -TopN_8 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1 -└─TableReader_16 1.00 19.11 root data:TopN_15 - └─TopN_15 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1 - └─Selection_14 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) - └─TableFullScan_13 1.00 203.50 cop[tikv] table:t keep order:false +TopN_9 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1 +└─TableReader_17 1.00 19.11 root data:TopN_16 + └─TopN_16 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1 + └─Selection_15 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) + └─TableFullScan_14 1.00 203.50 cop[tikv] table:t keep order:false explain format='verbose' select /*+ limit_to_cop() */ * from t where a=1 order by a limit 1000000000; id estRows estCost task access object operator info -TopN_8 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 -└─TableReader_16 1.00 19.11 root data:TopN_15 - └─TopN_15 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 - └─Selection_14 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) - └─TableFullScan_13 1.00 203.50 cop[tikv] table:t keep order:false +TopN_9 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 +└─TableReader_17 1.00 19.11 root data:TopN_16 + └─TopN_16 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 + └─Selection_15 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) + └─TableFullScan_14 1.00 203.50 cop[tikv] table:t keep order:false drop table if exists t; create table t (a int primary key, b int, c int, key(b)); insert into t values (0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5), (6, 6, 6), (7, 7, 7), (8, 8, 8), (9, 9, 9), (10, 10, 10), (11, 11, 11), (12, 12, 12), (13, 13, 13), (14, 14, 14), (15, 15, 15), (16, 16, 16), (17, 17, 17), (18, 18, 18), (19, 19, 19), (20, 20, 20), (21, 21, 21), (22, 22, 22), (23, 23, 23), (24, 24, 24), (25, 25, 25), (26, 26, 26), (27, 27, 27), (28, 28, 28), (29, 29, 29), (30, 30, 30), (31, 31, 31), (32, 32, 32), (33, 33, 33), (34, 34, 34), (35, 35, 35), (36, 36, 36), (37, 37, 37), (38, 38, 38), (39, 39, 39), (40, 40, 40), (41, 41, 41), (42, 42, 42), (43, 43, 43), (44, 44, 44), (45, 45, 45), (46, 46, 46), (47, 47, 47), (48, 48, 48), (49, 49, 49), (50, 50, 50), (51, 51, 51), (52, 52, 52), (53, 53, 53), (54, 54, 54), (55, 55, 55), (56, 56, 56), (57, 57, 57), (58, 58, 58), (59, 59, 59), (60, 60, 60), (61, 61, 61), (62, 62, 62), (63, 63, 63), (64, 64, 64), (65, 65, 65), (66, 66, 66), (67, 67, 67), (68, 68, 68), (69, 69, 69), (70, 70, 70), (71, 71, 71), (72, 72, 72), (73, 73, 73), (74, 74, 74), (75, 75, 75), (76, 76, 76), (77, 77, 77), (78, 78, 78), (79, 79, 79), (80, 80, 80), (81, 81, 81), (82, 82, 82), (83, 83, 83), (84, 84, 84), (85, 85, 85), (86, 86, 86), (87, 87, 87), (88, 88, 88), (89, 89, 89), (90, 90, 90), (91, 91, 91), (92, 92, 92), (93, 93, 93), (94, 94, 94), (95, 95, 95), (96, 96, 96), (97, 97, 97), (98, 98, 98), (99, 99, 99); @@ -241,12 +241,12 @@ create table t(a int, b int, c int, d int, index ia(a), index ibc(b,c)); set @@tidb_cost_model_version=1; explain select * from t where a between 1 and 5 and b != 200 and c = 20 limit 100000; id estRows task access object operator info -Limit_9 0.17 root offset:0, count:100000 -└─IndexLookUp_22 0.17 root - ├─IndexRangeScan_14(Build) 250.00 cop[tikv] table:t, index:ia(a) range:[1,5], keep order:false, stats:pseudo - └─Limit_21(Probe) 0.17 cop[tikv] offset:0, count:100000 - └─Selection_16 0.17 cop[tikv] eq(planner__core__plan_cost_ver2.t.c, 20), ne(planner__core__plan_cost_ver2.t.b, 200) - └─TableRowIDScan_15 250.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_10 0.17 root offset:0, count:100000 +└─IndexLookUp_23 0.17 root + ├─IndexRangeScan_15(Build) 250.00 cop[tikv] table:t, index:ia(a) range:[1,5], keep order:false, stats:pseudo + └─Limit_22(Probe) 0.17 cop[tikv] offset:0, count:100000 + └─Selection_17 0.17 cop[tikv] eq(planner__core__plan_cost_ver2.t.c, 20), ne(planner__core__plan_cost_ver2.t.b, 200) + └─TableRowIDScan_16 250.00 cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t; create table t (a int); set @@tidb_cost_model_version=2; diff --git a/tests/integrationtest/r/planner/core/rule_result_reorder.result b/tests/integrationtest/r/planner/core/rule_result_reorder.result index 24cefea1ff4c7..7abfbf0d2ea18 100644 --- a/tests/integrationtest/r/planner/core/rule_result_reorder.result +++ b/tests/integrationtest/r/planner/core/rule_result_reorder.result @@ -22,19 +22,19 @@ drop table if exists t; create table t (a int primary key, b int, c int, d int, key(b)); explain select * from t where a > 0 limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─TableReader_22 1.00 root data:Limit_21 - └─Limit_21 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_20 1.00 cop[tikv] table:t range:(0,+inf], keep order:true, stats:pseudo +Limit_13 1.00 root offset:0, count:1 +└─TableReader_23 1.00 root data:Limit_22 + └─Limit_22 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_21 1.00 cop[tikv] table:t range:(0,+inf], keep order:true, stats:pseudo create session binding for select * from t where a>0 limit 1 using select * from t use index(b) where a>0 limit 1; explain select * from t where a > 0 limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__rule_result_reorder.t.a, offset:0, count:1 -└─IndexLookUp_19 1.00 root - ├─TopN_18(Build) 1.00 cop[tikv] planner__core__rule_result_reorder.t.a, offset:0, count:1 - │ └─Selection_17 3333.33 cop[tikv] gt(planner__core__rule_result_reorder.t.a, 0) - │ └─IndexFullScan_15 10000.00 cop[tikv] table:t, index:b(b) keep order:false, stats:pseudo - └─TableRowIDScan_16(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo +TopN_10 1.00 root planner__core__rule_result_reorder.t.a, offset:0, count:1 +└─IndexLookUp_20 1.00 root + ├─TopN_19(Build) 1.00 cop[tikv] planner__core__rule_result_reorder.t.a, offset:0, count:1 + │ └─Selection_18 3333.33 cop[tikv] gt(planner__core__rule_result_reorder.t.a, 0) + │ └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:b(b) keep order:false, stats:pseudo + └─TableRowIDScan_17(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo set tidb_enable_ordered_result_mode=DEFAULT; set tidb_opt_limit_push_down_threshold=DEFAULT; set tidb_enable_ordered_result_mode=1; diff --git a/tests/integrationtest/r/topn_push_down.result b/tests/integrationtest/r/topn_push_down.result index 5c8f9e2dae86b..671492cb0023a 100644 --- a/tests/integrationtest/r/topn_push_down.result +++ b/tests/integrationtest/r/topn_push_down.result @@ -186,8 +186,8 @@ Limit 0.00 root offset:0, count:5 └─IndexRangeScan 0.00 cop[tikv] table:p, index:payment_relate_id(relate_id) range: decided by [eq(topn_push_down.p.relate_id, topn_push_down.tr.id)], keep order:false, stats:pseudo desc select 1 as a from dual order by a limit 1; id estRows task access object operator info -Projection_6 1.00 root 1->Column#1 -└─TableDual_7 1.00 root rows:1 +Projection_7 1.00 root 1->Column#1 +└─TableDual_8 1.00 root rows:1 drop table if exists t1; drop table if exists t2; create table t1(a bigint, b bigint); @@ -206,16 +206,16 @@ Apply_15 9990.00 root semi join, left side:TableReader_18, equal:[eq(topn_push_ └─TableFullScan_22 12487.50 cop[tikv] table:t2 keep order:false, stats:pseudo desc select * from t1 where t1.a in (select a from (select t2.a as a, t1.b as b from t2 where t2.b > t1.b) x order by b limit 1); id estRows task access object operator info -Apply_17 9990.00 root semi join, left side:TableReader_20, equal:[eq(topn_push_down.t1.a, topn_push_down.t2.a)] -├─TableReader_20(Build) 9990.00 root data:Selection_19 -│ └─Selection_19 9990.00 cop[tikv] not(isnull(topn_push_down.t1.a)) -│ └─TableFullScan_18 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -└─Selection_21(Probe) 7992.00 root not(isnull(topn_push_down.t2.a)) - └─Limit_23 9990.00 root offset:0, count:1 - └─TableReader_28 9990.00 root data:Limit_27 - └─Limit_27 9990.00 cop[tikv] offset:0, count:1 - └─Selection_26 9990.00 cop[tikv] gt(topn_push_down.t2.b, topn_push_down.t1.b) - └─TableFullScan_25 12487.50 cop[tikv] table:t2 keep order:false, stats:pseudo +Apply_18 9990.00 root semi join, left side:TableReader_21, equal:[eq(topn_push_down.t1.a, topn_push_down.t2.a)] +├─TableReader_21(Build) 9990.00 root data:Selection_20 +│ └─Selection_20 9990.00 cop[tikv] not(isnull(topn_push_down.t1.a)) +│ └─TableFullScan_19 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─Selection_22(Probe) 7992.00 root not(isnull(topn_push_down.t2.a)) + └─Limit_24 9990.00 root offset:0, count:1 + └─TableReader_29 9990.00 root data:Limit_28 + └─Limit_28 9990.00 cop[tikv] offset:0, count:1 + └─Selection_27 9990.00 cop[tikv] gt(topn_push_down.t2.b, topn_push_down.t1.b) + └─TableFullScan_26 12487.50 cop[tikv] table:t2 keep order:false, stats:pseudo drop table if exists t; create table t(a int not null, index idx(a)); explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5; From 7437c9692ff7ddba5cb151f08b4a06d84db5cabf Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 6 May 2025 19:49:09 +0800 Subject: [PATCH 17/31] update Signed-off-by: Weizhen Wang --- .../testdata/ann_index_suite_in.json | 42 +-- .../testdata/ann_index_suite_out.json | 324 +++++++++--------- 2 files changed, 183 insertions(+), 183 deletions(-) diff --git a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json index 63fc4697bad10..ff47cd7e28673 100644 --- a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json +++ b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json @@ -84,29 +84,29 @@ { "name": "TestVectorSearchHeavyFunction", "cases": [ - "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select id from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", - "explain select id from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", - "explain select id from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", - "explain select id from t1 order by vec_dims(vec) limit 10", - "explain select id from t1 order by vec_l2_norm(vec) limit 10", - "explain select id from t1 order by MOD(a, 3) limit 10", + "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_dims(vec) limit 10", + "explain format = 'brief' select id from t1 order by vec_l2_norm(vec) limit 10", + "explain format = 'brief' select id from t1 order by MOD(a, 3) limit 10", - "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_l1_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_l2_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_negative_inner_product(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_dims(vec) as d from t1 order by d limit 10", - "explain select id, vec_l2_norm(vec) as d from t1 order by d limit 10", - "explain select id, MOD(a, 3) as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_l1_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_l2_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_negative_inner_product(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_dims(vec) as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_l2_norm(vec) as d from t1 order by d limit 10", + "explain format = 'brief' select id, MOD(a, 3) as d from t1 order by d limit 10", - "explain select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select * from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", - "explain select * from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", - "explain select * from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", - "explain select * from t1 order by vec_dims(vec) limit 10", - "explain select * from t1 order by vec_l2_norm(vec) limit 10", - "explain select * from t1 order by MOD(a, 3) limit 10" + "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select * from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select * from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select * from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select * from t1 order by vec_dims(vec) limit 10", + "explain format = 'brief' select * from t1 order by vec_l2_norm(vec) limit 10", + "explain format = 'brief' select * from t1 order by MOD(a, 3) limit 10" ] } ] diff --git a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json index 51b2b788e3025..6e0233e74e708 100644 --- a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json +++ b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json @@ -700,269 +700,269 @@ "Name": "TestVectorSearchHeavyFunction", "Cases": [ { - "SQL": "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_11 10.00 root Column#11, offset:0, count:10", - "└─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#11, offset:0, count:10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#11" + "TopN 10.00 root Column#11, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#11, offset:0, count:10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#11" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_10 10.00 root Column#9, offset:0, count:10", - "└─TableReader_23 10.00 root MppVersion: 3, data:ExchangeSender_22", - " └─ExchangeSender_22 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_21 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_20 10.00 mpp[tiflash] test.t1.id, vec_l1_distance(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_18 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#9, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, vec_l1_distance(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_10 10.00 root Column#9, offset:0, count:10", - "└─TableReader_23 10.00 root MppVersion: 3, data:ExchangeSender_22", - " └─ExchangeSender_22 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_21 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_20 10.00 mpp[tiflash] test.t1.id, vec_l2_distance(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_18 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#9, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, vec_l2_distance(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_10 10.00 root Column#9, offset:0, count:10", - "└─TableReader_23 10.00 root MppVersion: 3, data:ExchangeSender_22", - " └─ExchangeSender_22 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_21 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_20 10.00 mpp[tiflash] test.t1.id, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_18 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#9, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_dims(vec) limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_dims(vec) limit 10", "Plan": [ - "TopN_10 10.00 root Column#9, offset:0, count:10", - "└─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, vec_dims(test.t1.vec)->Column#9", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#9, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, vec_dims(test.t1.vec)->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_l2_norm(vec) limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_l2_norm(vec) limit 10", "Plan": [ - "TopN_10 10.00 root Column#9, offset:0, count:10", - "└─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, vec_l2_norm(test.t1.vec)->Column#9", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#9, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, vec_l2_norm(test.t1.vec)->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by MOD(a, 3) limit 10", + "SQL": "explain format = 'brief' select id from t1 order by MOD(a, 3) limit 10", "Plan": [ - "Projection_23 10.00 root test.t1.id", - "└─TopN_10 10.00 root Column#9, offset:0, count:10", - " └─Projection_24 10.00 root test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#9", - " └─TableReader_20 10.00 root MppVersion: 3, data:ExchangeSender_19", - " └─ExchangeSender_19 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection_21 10.00 mpp[tiflash] test.t1.id, test.t1.a", - " └─TopN_18 10.00 mpp[tiflash] Column#8, offset:0, count:10", - " └─Projection_22 6000.00 mpp[tiflash] test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#8", - " └─TableFullScan_16 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id", + "└─TopN 10.00 root Column#9, offset:0, count:10", + " └─Projection 10.00 root test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#9", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.a", + " └─TopN 10.00 mpp[tiflash] Column#8, offset:0, count:10", + " └─Projection 6000.00 mpp[tiflash] test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#8", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_10 10.00 root Column#10, offset:0, count:10", - " └─TableReader_28 10.00 root MppVersion: 3, data:ExchangeSender_27", - " └─ExchangeSender_27 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_26 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_25 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_24 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#10, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { - "SQL": "explain select id, vec_l1_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_l1_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_l1_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_9 10.00 root Column#9, offset:0, count:10", - " └─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_l1_distance(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, vec_l1_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#9, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_l1_distance(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_l2_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_l2_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_l2_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_9 10.00 root Column#9, offset:0, count:10", - " └─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_l2_distance(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, vec_l2_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#9, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_l2_distance(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_negative_inner_product(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_negative_inner_product(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_9 10.00 root Column#9, offset:0, count:10", - " └─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#9, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_dims(vec) as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_dims(vec) as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_dims(test.t1.vec)->Column#7", - "└─TopN_9 10.00 root Column#9, offset:0, count:10", - " └─TableReader_21 10.00 root MppVersion: 3, data:ExchangeSender_20", - " └─ExchangeSender_20 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_19 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_18 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_dims(test.t1.vec)->Column#9", - " └─TableFullScan_16 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, vec_dims(test.t1.vec)->Column#7", + "└─TopN 10.00 root Column#9, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_dims(test.t1.vec)->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, vec_l2_norm(vec) as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_l2_norm(vec) as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, vec_l2_norm(test.t1.vec)->Column#7", - "└─TopN_9 10.00 root Column#9, offset:0, count:10", - " └─TableReader_21 10.00 root MppVersion: 3, data:ExchangeSender_20", - " └─ExchangeSender_20 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_19 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_18 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_l2_norm(test.t1.vec)->Column#9", - " └─TableFullScan_16 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, vec_l2_norm(test.t1.vec)->Column#7", + "└─TopN 10.00 root Column#9, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_l2_norm(test.t1.vec)->Column#9", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id, MOD(a, 3) as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, MOD(a, 3) as d from t1 order by d limit 10", "Plan": [ - "Projection_6 10.00 root test.t1.id, mod(test.t1.a, 3)->Column#7", - "└─Projection_22 10.00 root test.t1.id, test.t1.a", - " └─TopN_9 10.00 root Column#9, offset:0, count:10", - " └─Projection_23 10.00 root test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#9", - " └─TableReader_19 10.00 root MppVersion: 3, data:ExchangeSender_18", - " └─ExchangeSender_18 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection_20 10.00 mpp[tiflash] test.t1.id, test.t1.a", - " └─TopN_17 10.00 mpp[tiflash] Column#8, offset:0, count:10", - " └─Projection_21 6000.00 mpp[tiflash] test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#8", - " └─TableFullScan_15 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, mod(test.t1.a, 3)->Column#7", + "└─Projection 10.00 root test.t1.id, test.t1.a", + " └─TopN 10.00 root Column#9, offset:0, count:10", + " └─Projection 10.00 root test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#9", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.a", + " └─TopN 10.00 mpp[tiflash] Column#8, offset:0, count:10", + " └─Projection 6000.00 mpp[tiflash] test.t1.id, test.t1.a, mod(test.t1.a, 3)->Column#8", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_10 10.00 root Column#9, offset:0, count:10", - "└─TableReader_28 10.00 root MppVersion: 3, data:ExchangeSender_27", - " └─ExchangeSender_27 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_26 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_25 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_24 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "TopN 10.00 root Column#9, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_9 10.00 root Column#8, offset:0, count:10", - "└─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#8, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_l1_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#8, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#8, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_l1_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_9 10.00 root Column#8, offset:0, count:10", - "└─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#8, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_l2_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#8, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#8, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_l2_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_negative_inner_product(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_9 10.00 root Column#8, offset:0, count:10", - "└─TableReader_22 10.00 root MppVersion: 3, data:ExchangeSender_21", - " └─ExchangeSender_21 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_20 10.00 mpp[tiflash] Column#8, offset:0, count:10", - " └─Projection_19 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#8", - " └─TableFullScan_17 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#8, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#8, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_negative_inner_product(test.t1.vec, [1,1,1])->Column#8", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_dims(vec) limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_dims(vec) limit 10", "Plan": [ - "TopN_9 10.00 root Column#8, offset:0, count:10", - "└─TableReader_21 10.00 root MppVersion: 3, data:ExchangeSender_20", - " └─ExchangeSender_20 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_19 10.00 mpp[tiflash] Column#8, offset:0, count:10", - " └─Projection_18 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_dims(test.t1.vec)->Column#8", - " └─TableFullScan_16 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#8, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#8, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_dims(test.t1.vec)->Column#8", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_l2_norm(vec) limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_l2_norm(vec) limit 10", "Plan": [ - "TopN_9 10.00 root Column#8, offset:0, count:10", - "└─TableReader_21 10.00 root MppVersion: 3, data:ExchangeSender_20", - " └─ExchangeSender_20 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_19 10.00 mpp[tiflash] Column#8, offset:0, count:10", - " └─Projection_18 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_l2_norm(test.t1.vec)->Column#8", - " └─TableFullScan_16 6000.00 mpp[tiflash] table:t1 keep order:false" + "TopN 10.00 root Column#8, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#8, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_l2_norm(test.t1.vec)->Column#8", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by MOD(a, 3) limit 10", + "SQL": "explain format = 'brief' select * from t1 order by MOD(a, 3) limit 10", "Plan": [ - "Projection_22 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d", - "└─TopN_9 10.00 root Column#8, offset:0, count:10", - " └─Projection_23 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, mod(test.t1.a, 3)->Column#8", - " └─TableReader_19 10.00 root MppVersion: 3, data:ExchangeSender_18", - " └─ExchangeSender_18 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection_20 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d", - " └─TopN_17 10.00 mpp[tiflash] Column#7, offset:0, count:10", - " └─Projection_21 6000.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, mod(test.t1.a, 3)->Column#7", - " └─TableFullScan_15 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d", + "└─TopN 10.00 root Column#8, offset:0, count:10", + " └─Projection 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, mod(test.t1.a, 3)->Column#8", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d", + " └─TopN 10.00 mpp[tiflash] Column#7, offset:0, count:10", + " └─Projection 6000.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, mod(test.t1.a, 3)->Column#7", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null } From bfd1c341c4da141655c9f56695b016e17d009f59 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 6 May 2025 19:56:47 +0800 Subject: [PATCH 18/31] update Signed-off-by: Weizhen Wang --- pkg/executor/infoschema_reader_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/executor/infoschema_reader_test.go b/pkg/executor/infoschema_reader_test.go index c499939133af0..97b2be0bafbaf 100644 --- a/pkg/executor/infoschema_reader_test.go +++ b/pkg/executor/infoschema_reader_test.go @@ -982,10 +982,10 @@ func TestInfoSchemaDDLJobs(t *testing.T) { )) // Test explain output, since the output may change in future. - tk.MustQuery(`EXPLAIN SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( - `Limit_10 10.00 root offset:0, count:10`, - `└─Selection_11 10.00 root eq(Column#2, "test2")`, - ` └─MemTableScan_12 10000.00 root table:DDL_JOBS db_name:["test2"]`, + tk.MustQuery(`EXPLAIN FORMAT='breif 'SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( + `Limit 10.00 root offset:0, count:10`, + `└─Selection 10.00 root eq(Column#2, "test2")`, + ` └─MemTableScan 10000.00 root table:DDL_JOBS db_name:["test2"]`, )) } From b2cb8b7b6a4eb8ee13aac0a9afde2ff642a8582b Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 6 May 2025 20:03:24 +0800 Subject: [PATCH 19/31] update Signed-off-by: Weizhen Wang --- pkg/executor/infoschema_reader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/executor/infoschema_reader_test.go b/pkg/executor/infoschema_reader_test.go index 97b2be0bafbaf..7ee4f31d9a0ac 100644 --- a/pkg/executor/infoschema_reader_test.go +++ b/pkg/executor/infoschema_reader_test.go @@ -982,7 +982,7 @@ func TestInfoSchemaDDLJobs(t *testing.T) { )) // Test explain output, since the output may change in future. - tk.MustQuery(`EXPLAIN FORMAT='breif 'SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( + tk.MustQuery(`EXPLAIN FORMAT='brief 'SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( `Limit 10.00 root offset:0, count:10`, `└─Selection 10.00 root eq(Column#2, "test2")`, ` └─MemTableScan 10000.00 root table:DDL_JOBS db_name:["test2"]`, From f702752a233653b0be6c7a2638d04d97f5f8483b Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 6 May 2025 20:12:11 +0800 Subject: [PATCH 20/31] update Signed-off-by: Weizhen Wang --- pkg/executor/infoschema_reader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/executor/infoschema_reader_test.go b/pkg/executor/infoschema_reader_test.go index 7ee4f31d9a0ac..6667a95215d84 100644 --- a/pkg/executor/infoschema_reader_test.go +++ b/pkg/executor/infoschema_reader_test.go @@ -982,7 +982,7 @@ func TestInfoSchemaDDLJobs(t *testing.T) { )) // Test explain output, since the output may change in future. - tk.MustQuery(`EXPLAIN FORMAT='brief 'SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( + tk.MustQuery(`EXPLAIN FORMAT='brieffail' SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( `Limit 10.00 root offset:0, count:10`, `└─Selection 10.00 root eq(Column#2, "test2")`, ` └─MemTableScan 10000.00 root table:DDL_JOBS db_name:["test2"]`, From 940c95026f3c181dff3ecf405008728dafe19f07 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 09:11:05 +0800 Subject: [PATCH 21/31] update Signed-off-by: Weizhen Wang --- pkg/executor/infoschema_reader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/executor/infoschema_reader_test.go b/pkg/executor/infoschema_reader_test.go index 6667a95215d84..2af48afda10b0 100644 --- a/pkg/executor/infoschema_reader_test.go +++ b/pkg/executor/infoschema_reader_test.go @@ -982,7 +982,7 @@ func TestInfoSchemaDDLJobs(t *testing.T) { )) // Test explain output, since the output may change in future. - tk.MustQuery(`EXPLAIN FORMAT='brieffail' SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( + tk.MustQuery(`EXPLAIN FORMAT='brief' SELECT * FROM information_schema.ddl_jobs where db_name = "test2" limit 10;`).Check(testkit.Rows( `Limit 10.00 root offset:0, count:10`, `└─Selection 10.00 root eq(Column#2, "test2")`, ` └─MemTableScan 10000.00 root table:DDL_JOBS db_name:["test2"]`, From 4b87bbf29c87fb52691b6e15e3bf4d1a8f59e310 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 10:03:05 +0800 Subject: [PATCH 22/31] update Signed-off-by: Weizhen Wang --- .../core/issuetest/planner_issue.result | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result index a20b30adf9b2a..65010f3b2819a 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -12,21 +12,12 @@ KEY 19dc3c2d (57fd8d09) ) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin COMMENT='320f8401'; explain format='brief' select /*+ use_index_merge( `aa311c3c` ) */ `aa311c3c`.`43b06e99` as r0 , `aa311c3c`.`6302d8ac` as r1 from `aa311c3c` where `aa311c3c`.`b80b3746` = 3 or not( `aa311c3c`.`57fd8d09` >= '2008' ) order by r0,r1 limit 95; id estRows task access object operator info -<<<<<<< HEAD TopN 95.00 root planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 └─IndexMerge 95.00 root type: union ├─IndexRangeScan(Build) 10.00 cop[tikv] table:aa311c3c, index:464b386e(b80b3746) range:[3,3], keep order:false, stats:pseudo ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:aa311c3c, index:3080c821(57fd8d09, 43b06e99, b80b3746) range:[-inf,2008), keep order:false, stats:pseudo └─TopN(Probe) 95.00 cop[tikv] planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 └─TableRowIDScan 3330.01 cop[tikv] table:aa311c3c keep order:false, stats:pseudo -======= -TopN_10 95.00 root planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 -└─IndexMerge_18 95.00 root type: union - ├─IndexRangeScan_14(Build) 10.00 cop[tikv] table:aa311c3c, index:464b386e(b80b3746) range:[3,3], keep order:false, stats:pseudo - ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:aa311c3c, index:3080c821(57fd8d09, 43b06e99, b80b3746) range:[-inf,2008), keep order:false, stats:pseudo - └─TopN_17(Probe) 95.00 cop[tikv] planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95 - └─TableRowIDScan_16 3330.01 cop[tikv] table:aa311c3c keep order:false, stats:pseudo ->>>>>>> 776d9f4117 (update) CREATE TABLE t1(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10)); CREATE TABLE t2(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10)); INSERT INTO t1 values(1,NULL,NULL,null),(2,NULL,NULL,null),(3,NULL,NULL,null); @@ -119,7 +110,6 @@ create table tbl_39(col_239 year(4) not null default '2009', primary key(col_239 insert into tbl_39 values (1994),(1995),(1996),(1997); explain format='brief' select /*+ use_index_merge( tbl_39) */ col_239 from tbl_39 where not( tbl_39.col_239 not in ( '1994' ) ) and tbl_39.col_239 not in ( '2004' , '2010' , '2010' ) or not( tbl_39.col_239 <= '1996' ) and not( tbl_39.col_239 between '2026' and '2011' ) order by tbl_39.col_239 limit 382; id estRows task access object operator info -<<<<<<< HEAD Limit 382.00 root offset:0, count:382 └─UnionScan 382.00 root or(and(not(not(eq(planner__core__issuetest__planner_issue.tbl_39.col_239, 1994))), not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010))), and(not(le(planner__core__issuetest__planner_issue.tbl_39.col_239, 1996)), not(and(ge(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), le(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011))))) └─IndexMerge 382.00 root type: union @@ -128,16 +118,6 @@ Limit 382.00 root offset:0, count:382 ├─Selection(Build) 458.26 cop[tikv] or(lt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), gt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011)) │ └─IndexRangeScan 477.36 cop[tikv] table:tbl_39, index:idx_223(col_239) range:(1996,+inf], keep order:true, stats:pseudo └─TableRowIDScan(Probe) 382.00 cop[tikv] table:tbl_39 keep order:false, stats:pseudo -======= -Limit_16 382.00 root offset:0, count:382 -└─UnionScan_24 382.00 root or(and(not(not(eq(planner__core__issuetest__planner_issue.tbl_39.col_239, 1994))), not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010))), and(not(le(planner__core__issuetest__planner_issue.tbl_39.col_239, 1996)), not(and(ge(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), le(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011))))) - └─IndexMerge_30 382.00 root type: union - ├─Selection_26(Build) 0.05 cop[tikv] not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010)) - │ └─IndexRangeScan_25 0.14 cop[tikv] table:tbl_39, index:PRIMARY(col_239) range:[1994,1994], keep order:true, stats:pseudo - ├─Selection_28(Build) 458.26 cop[tikv] or(lt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), gt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011)) - │ └─IndexRangeScan_27 477.36 cop[tikv] table:tbl_39, index:idx_223(col_239) range:(1996,+inf], keep order:true, stats:pseudo - └─TableRowIDScan_29(Probe) 382.00 cop[tikv] table:tbl_39 keep order:false, stats:pseudo ->>>>>>> 776d9f4117 (update) select /*+ use_index_merge( tbl_39) */ col_239 from tbl_39 where not( tbl_39.col_239 not in ( '1994' ) ) and tbl_39.col_239 not in ( '2004' , '2010' , '2010' ) or not( tbl_39.col_239 <= '1996' ) and not( tbl_39.col_239 between '2026' and '2011' ) order by tbl_39.col_239 limit 382; col_239 1994 From 935295e1febfee4910c0b9dba812a859bbc03ed3 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 14:54:15 +0800 Subject: [PATCH 23/31] update Signed-off-by: Weizhen Wang --- .../operator/logicalop/logical_projection.go | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index a2eca26555983..a51af3b555758 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -203,6 +203,18 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * // after substituting, if the order-by expression is un-deterministic like 'order by rand()', stop pushing down. return p.BaseLogicalPlan.PushDownTopN(topN, opt) } + // if topN.ByItems contains a column(with ID=0) generated by projection, + // projection will prevent the optimizer from pushing topN down. + cols := expression.ExtractColumns(substituted) + for _, col := range cols { + if col.ID == 0 && p.Schema().Contains(col) { + // check whether the column is generated by projection + if !p.Children()[0].Schema().Contains(col) { + p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) + return topN.AttachChild(p, opt) + } + } + } substitutedExprs = append(substitutedExprs, substituted) } pushDownTopNByItems := make([]*util.ByItems, 0, len(topN.ByItems)) @@ -227,19 +239,6 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * PreferLimitToCop: topN.PreferLimitToCop, PartitionBy: topN.GetPartitionBy(), }.Init(topN.SCtx(), topN.QueryBlockOffset()) - // if topN.ByItems contains a column(with ID=0) generated by projection, projection will prevent the optimizer from pushing topN down. - for _, by := range pushDownTopN.ByItems { - cols := expression.ExtractColumns(by.Expr) - for _, col := range cols { - if col.ID == 0 && p.Schema().Contains(col) { - // check whether the column is generated by projection - if !p.Children()[0].Schema().Contains(col) { - p.Children()[0] = p.Children()[0].PushDownTopN(nil, opt) - return topN.AttachChild(p, opt) - } - } - } - } p.Children()[0] = p.Children()[0].PushDownTopN(pushDownTopN, opt) return p } From 253ff134f28d2850d1164d9292c8a9a7fb7319b9 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 14:55:45 +0800 Subject: [PATCH 24/31] update Signed-off-by: Weizhen Wang --- .../core/operator/logicalop/logical_projection.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index a51af3b555758..d7d2550d87ea3 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -232,14 +232,8 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * pushDownTopNByItems = slices.Delete(pushDownTopNByItems, i, i+1) } } - pushDownTopN := LogicalTopN{ - Count: topN.Count, - Offset: topN.Offset, - ByItems: pushDownTopNByItems, - PreferLimitToCop: topN.PreferLimitToCop, - PartitionBy: topN.GetPartitionBy(), - }.Init(topN.SCtx(), topN.QueryBlockOffset()) - p.Children()[0] = p.Children()[0].PushDownTopN(pushDownTopN, opt) + topN.ByItems = pushDownTopNByItems + p.Children()[0] = p.Children()[0].PushDownTopN(topN, opt) return p } From bca1d7af853f3afd250c3cdec4e81c7c2d1f7420 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 14:59:15 +0800 Subject: [PATCH 25/31] update Signed-off-by: Weizhen Wang --- .../core/operator/logicalop/logical_projection.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_projection.go b/pkg/planner/core/operator/logicalop/logical_projection.go index d7d2550d87ea3..8e6acd75e42b8 100644 --- a/pkg/planner/core/operator/logicalop/logical_projection.go +++ b/pkg/planner/core/operator/logicalop/logical_projection.go @@ -217,22 +217,16 @@ func (p *LogicalProjection) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt * } substitutedExprs = append(substitutedExprs, substituted) } - pushDownTopNByItems := make([]*util.ByItems, 0, len(topN.ByItems)) for i, by := range topN.ByItems { - expr := substitutedExprs[i] - pushDownTopNByItems = append(pushDownTopNByItems, &util.ByItems{ - Expr: expr, - Desc: by.Desc, - }) + by.Expr = substitutedExprs[i] } // remove meaningless constant sort items. - for i := len(pushDownTopNByItems) - 1; i >= 0; i-- { - switch pushDownTopNByItems[i].Expr.(type) { + for i := len(topN.ByItems) - 1; i >= 0; i-- { + switch topN.ByItems[i].Expr.(type) { case *expression.Constant, *expression.CorrelatedColumn: - pushDownTopNByItems = slices.Delete(pushDownTopNByItems, i, i+1) + topN.ByItems = slices.Delete(topN.ByItems, i, i+1) } } - topN.ByItems = pushDownTopNByItems p.Children()[0] = p.Children()[0].PushDownTopN(topN, opt) return p } From 4cbfbb9aebcffe23bf06a165399ff08a38708264 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 15:20:45 +0800 Subject: [PATCH 26/31] update Signed-off-by: Weizhen Wang --- pkg/planner/core/logical_plan_trace_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/planner/core/logical_plan_trace_test.go b/pkg/planner/core/logical_plan_trace_test.go index 0af775488de60..a904223bc1e65 100644 --- a/pkg/planner/core/logical_plan_trace_test.go +++ b/pkg/planner/core/logical_plan_trace_test.go @@ -156,11 +156,11 @@ func TestSingleRuleTraceStep(t *testing.T) { assertReason: "TopN_7 is Limit originally", }, { - assertAction: "TopN_9 is added and pushed into Join_3's left table", + assertAction: "TopN_8 is added and pushed into Join_3's left table", assertReason: "Join_3's joinType is left outer join, and all ByItems[test.t.a] contained in left table", }, { - assertAction: "TopN_9 is added as DataSource_1's parent", + assertAction: "TopN_8 is added as DataSource_1's parent", assertReason: "TopN is pushed down", }, { @@ -183,7 +183,7 @@ func TestSingleRuleTraceStep(t *testing.T) { assertReason: "TopN_5 is Limit originally", }, { - assertAction: "TopN_6 is added as DataSource_1's parent", + assertAction: "TopN_5 is added as DataSource_1's parent", assertReason: "TopN is pushed down", }, }, From 0c2ca4ffe8ed344d110b527f01737e25b8a0a0c7 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 15:26:40 +0800 Subject: [PATCH 27/31] update Signed-off-by: Weizhen Wang --- .../integrationtest/r/executor/explain.result | 16 +- .../r/executor/index_merge_reader.result | 24 +- .../integrationtest/r/executor/issues.result | 124 +++--- .../r/globalindex/mem_index_merge.result | 48 +-- tests/integrationtest/r/index_merge.result | 14 +- .../r/infoschema/cluster_tables.result | 36 +- .../r/planner/core/casetest/hint/hint.result | 406 +++++++++--------- .../planner/core/casetest/integration.result | 40 +- .../physicalplantest/physical_plan.result | 30 +- .../r/planner/core/plan_cache.result | 46 +- .../r/planner/core/plan_cost_ver2.result | 32 +- .../r/planner/core/rule_result_reorder.result | 20 +- tests/integrationtest/r/topn_push_down.result | 24 +- 13 files changed, 430 insertions(+), 430 deletions(-) diff --git a/tests/integrationtest/r/executor/explain.result b/tests/integrationtest/r/executor/explain.result index b5f58eb573795..567fd7822e93a 100644 --- a/tests/integrationtest/r/executor/explain.result +++ b/tests/integrationtest/r/executor/explain.result @@ -110,19 +110,19 @@ select * from t limit 1; a explain format = 'plan_cache' select * from (select * from t) t1 limit 1; id estRows task access object operator info -Limit_9 1.00 root offset:0, count:1 -└─TableReader_13 1.00 root data:Limit_12 - └─Limit_12 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan_11 1.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_8 1.00 root offset:0, count:1 +└─TableReader_12 1.00 root data:Limit_11 + └─Limit_11 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan_10 1.00 cop[tikv] table:t keep order:false, stats:pseudo show warnings; Level Code Message Warning 1105 skip non-prepared plan-cache: queries that have sub-queries are not supported explain format = 'plan_cache' select * from (select * from t) t1 limit 1; id estRows task access object operator info -Limit_9 1.00 root offset:0, count:1 -└─TableReader_13 1.00 root data:Limit_12 - └─Limit_12 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan_11 1.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_8 1.00 root offset:0, count:1 +└─TableReader_12 1.00 root data:Limit_11 + └─Limit_11 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan_10 1.00 cop[tikv] table:t keep order:false, stats:pseudo select @@last_plan_from_cache; @@last_plan_from_cache 0 diff --git a/tests/integrationtest/r/executor/index_merge_reader.result b/tests/integrationtest/r/executor/index_merge_reader.result index d2202fe566763..5fdb7f1203bcd 100644 --- a/tests/integrationtest/r/executor/index_merge_reader.result +++ b/tests/integrationtest/r/executor/index_merge_reader.result @@ -486,12 +486,12 @@ begin; insert into t values(1, 1, -3); explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; id estRows task access object operator info -Limit_16 2.00 root offset:0, count:2 -└─UnionScan_22 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) - └─IndexMerge_26 2.00 root type: union - ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, stats:pseudo - ├─IndexRangeScan_24(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo - └─TableRowIDScan_25(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_15 2.00 root offset:0, count:2 +└─UnionScan_21 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + └─IndexMerge_25 2.00 root type: union + ├─IndexRangeScan_22(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, stats:pseudo + ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan_24(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; a b c 1 1 -3 @@ -501,12 +501,12 @@ begin; insert into t values(1, 2, 4); explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; id estRows task access object operator info -Limit_16 2.00 root offset:0, count:2 -└─UnionScan_22 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) - └─IndexMerge_26 2.00 root type: union - ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, desc, stats:pseudo - ├─IndexRangeScan_24(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, desc, stats:pseudo - └─TableRowIDScan_25(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_15 2.00 root offset:0, count:2 +└─UnionScan_21 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + └─IndexMerge_25 2.00 root type: union + ├─IndexRangeScan_22(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, desc, stats:pseudo + ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, desc, stats:pseudo + └─TableRowIDScan_24(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; a b c 1 2 4 diff --git a/tests/integrationtest/r/executor/issues.result b/tests/integrationtest/r/executor/issues.result index e25983afcfebf..679f1e3f42fe8 100644 --- a/tests/integrationtest/r/executor/issues.result +++ b/tests/integrationtest/r/executor/issues.result @@ -905,49 +905,49 @@ TableReader_11 256.00 root NULL max_distsql_concurrency: 2 NULL cop[tikv] table:t NULL keep order:true explain analyze select * from t limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_8 100.00 root NULL NULL offset:0, count:100 -└─TableReader_12 100.00 root NULL max_distsql_concurrency: 1 NULL - └─Limit_11 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_10 100.00 cop[tikv] table:t NULL keep order:false +Limit_7 100.00 root NULL NULL offset:0, count:100 +└─TableReader_11 100.00 root NULL max_distsql_concurrency: 1 NULL + └─Limit_10 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_9 100.00 cop[tikv] table:t NULL keep order:false explain analyze select * from t limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_8 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_12 256.00 root NULL max_distsql_concurrency: 15 NULL - └─Limit_11 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_10 256.00 cop[tikv] table:t NULL keep order:false +Limit_7 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_11 256.00 root NULL max_distsql_concurrency: 15 NULL + └─Limit_10 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_9 256.00 cop[tikv] table:t NULL keep order:false explain analyze select * from t where c = 'abc' limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_9 0.26 root NULL NULL offset:0, count:100 -└─TableReader_14 0.26 root NULL max_distsql_concurrency: 15 NULL - └─Limit_13 0.26 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_12 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") - └─TableFullScan_11 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] +Limit_8 0.26 root NULL NULL offset:0, count:100 +└─TableReader_13 0.26 root NULL max_distsql_concurrency: 15 NULL + └─Limit_12 0.26 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_11 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") + └─TableFullScan_10 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] explain analyze select * from t where c = 'abc' limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_9 0.26 root NULL NULL offset:0, count:100000 -└─TableReader_14 0.26 root NULL max_distsql_concurrency: 15 NULL - └─Limit_13 0.26 cop[tikv] NULL NULL offset:0, count:100000 - └─Selection_12 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") - └─TableFullScan_11 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] +Limit_8 0.26 root NULL NULL offset:0, count:100000 +└─TableReader_13 0.26 root NULL max_distsql_concurrency: 15 NULL + └─Limit_12 0.26 cop[tikv] NULL NULL offset:0, count:100000 + └─Selection_11 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abc") + └─TableFullScan_10 256.00 cop[tikv] table:t NULL keep order:false, stats:partial[c:unInitialized] explain analyze select * from t order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_11 100.00 root NULL NULL offset:0, count:100 -└─TableReader_18 100.00 root NULL max_distsql_concurrency: 1 NULL - └─Limit_17 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_16 100.00 cop[tikv] table:t NULL keep order:true +Limit_10 100.00 root NULL NULL offset:0, count:100 +└─TableReader_17 100.00 root NULL max_distsql_concurrency: 1 NULL + └─Limit_16 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_15 100.00 cop[tikv] table:t NULL keep order:true explain analyze select * from t order by id limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_12 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_22 256.00 root NULL max_distsql_concurrency: 15 NULL - └─Limit_21 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_20 256.00 cop[tikv] table:t NULL keep order:true +Limit_11 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_21 256.00 root NULL max_distsql_concurrency: 15 NULL + └─Limit_20 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_19 256.00 cop[tikv] table:t NULL keep order:true explain analyze select * from t where c = 'abd' order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_12 0.26 root NULL NULL offset:0, count:100 -└─TableReader_21 0.26 root NULL max_distsql_concurrency: 15 NULL - └─Limit_20 0.26 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_19 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abd") - └─TableFullScan_18 256.00 cop[tikv] table:t NULL keep order:true, stats:partial[c:unInitialized] +Limit_11 0.26 root NULL NULL offset:0, count:100 +└─TableReader_20 0.26 root NULL max_distsql_concurrency: 15 NULL + └─Limit_19 0.26 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_18 0.26 cop[tikv] NULL NULL eq(executor__issues.t.c, "abd") + └─TableFullScan_17 256.00 cop[tikv] table:t NULL keep order:true, stats:partial[c:unInitialized] select @@tidb_partition_prune_mode; @@tidb_partition_prune_mode dynamic @@ -957,49 +957,49 @@ TableReader_11 256.00 root partition:all max_distsql_concurrency: 2 NU └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:true explain analyze select * from pt limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_8 100.00 root NULL NULL offset:0, count:100 -└─TableReader_12 100.00 root partition:all max_distsql_concurrency: 7 NULL - └─Limit_11 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_10 100.00 cop[tikv] table:pt NULL keep order:false +Limit_7 100.00 root NULL NULL offset:0, count:100 +└─TableReader_11 100.00 root partition:all max_distsql_concurrency: 7 NULL + └─Limit_10 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_9 100.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_8 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_12 256.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_11 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:false +Limit_7 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_11 256.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_10 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_9 256.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt where val = 125 limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_9 1.00 root NULL NULL offset:0, count:100 -└─TableReader_14 1.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_13 1.00 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_12 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) - └─TableFullScan_11 256.00 cop[tikv] table:pt NULL keep order:false +Limit_8 1.00 root NULL NULL offset:0, count:100 +└─TableReader_13 1.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_12 1.00 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_11 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) + └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt where val = 125 limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_9 1.00 root NULL NULL offset:0, count:100000 -└─TableReader_14 1.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_13 1.00 cop[tikv] NULL NULL offset:0, count:100000 - └─Selection_12 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) - └─TableFullScan_11 256.00 cop[tikv] table:pt NULL keep order:false +Limit_8 1.00 root NULL NULL offset:0, count:100000 +└─TableReader_13 1.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_12 1.00 cop[tikv] NULL NULL offset:0, count:100000 + └─Selection_11 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 125) + └─TableFullScan_10 256.00 cop[tikv] table:pt NULL keep order:false explain analyze select * from pt order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_11 100.00 root NULL NULL offset:0, count:100 -└─TableReader_18 100.00 root partition:all max_distsql_concurrency: 1 NULL - └─Limit_17 100.00 cop[tikv] NULL NULL offset:0, count:100 - └─TableFullScan_16 100.00 cop[tikv] table:pt NULL keep order:true +Limit_10 100.00 root NULL NULL offset:0, count:100 +└─TableReader_17 100.00 root partition:all max_distsql_concurrency: 1 NULL + └─Limit_16 100.00 cop[tikv] NULL NULL offset:0, count:100 + └─TableFullScan_15 100.00 cop[tikv] table:pt NULL keep order:true explain analyze select * from pt order by id limit 100000; id estRows actRows task access object execution info operator info memory disk -Limit_12 256.00 root NULL NULL offset:0, count:100000 -└─TableReader_22 256.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_21 256.00 cop[tikv] NULL NULL offset:0, count:100000 - └─TableFullScan_20 256.00 cop[tikv] table:pt NULL keep order:true +Limit_11 256.00 root NULL NULL offset:0, count:100000 +└─TableReader_21 256.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_20 256.00 cop[tikv] NULL NULL offset:0, count:100000 + └─TableFullScan_19 256.00 cop[tikv] table:pt NULL keep order:true explain analyze select * from pt where val = 126 order by id limit 100; id estRows actRows task access object execution info operator info memory disk -Limit_12 1.00 root NULL NULL offset:0, count:100 -└─TableReader_21 1.00 root partition:all max_distsql_concurrency: 15 NULL - └─Limit_20 1.00 cop[tikv] NULL NULL offset:0, count:100 - └─Selection_19 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 126) - └─TableFullScan_18 256.00 cop[tikv] table:pt NULL keep order:true +Limit_11 1.00 root NULL NULL offset:0, count:100 +└─TableReader_20 1.00 root partition:all max_distsql_concurrency: 15 NULL + └─Limit_19 1.00 cop[tikv] NULL NULL offset:0, count:100 + └─Selection_18 1.00 cop[tikv] NULL NULL eq(executor__issues.pt.val, 126) + └─TableFullScan_17 256.00 cop[tikv] table:pt NULL keep order:true CREATE TABLE test_55837 (col1 int(4) NOT NULL, col2 bigint(4) NOT NULL, KEY col2_index (col2)); insert into test_55837 values(0,1725292800),(0,1725292800); select from_unixtime( if(col2 >9999999999, col2/1000, col2), '%Y-%m-%d %H:%i:%s') as result from test_55837; diff --git a/tests/integrationtest/r/globalindex/mem_index_merge.result b/tests/integrationtest/r/globalindex/mem_index_merge.result index 2e77fb7348562..f61d589ada36a 100644 --- a/tests/integrationtest/r/globalindex/mem_index_merge.result +++ b/tests/integrationtest/r/globalindex/mem_index_merge.result @@ -157,23 +157,23 @@ a b c d ## for indexMerge union in txn with order by limit explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; id estRows task access object operator info -Limit_16 1.00 root offset:0, count:1 -└─UnionScan_23 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) - └─IndexMerge_28 1.00 root partition:all type: union - ├─IndexRangeScan_24(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo - ├─IndexRangeScan_26(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo - └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo +Limit_15 1.00 root offset:0, count:1 +└─UnionScan_22 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) + └─IndexMerge_27 1.00 root partition:all type: union + ├─IndexRangeScan_23(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + ├─IndexRangeScan_25(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo + └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; a b c d 1 2 1 1 explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; id estRows task access object operator info -Limit_16 1.00 root offset:0, count:1 -└─UnionScan_23 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) - └─IndexMerge_28 1.00 root partition:all type: union - ├─IndexRangeScan_24(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo - ├─IndexRangeScan_26(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo - └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo +Limit_15 1.00 root offset:0, count:1 +└─UnionScan_22 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4)) + └─IndexMerge_27 1.00 root partition:all type: union + ├─IndexRangeScan_23(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo + ├─IndexRangeScan_25(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo + └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; a b c d 2 4 2 2 @@ -181,25 +181,25 @@ commit; ## for indexMerge union with order by limit explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; id estRows task access object operator info -Projection_27 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d -└─IndexMerge_26 1.00 root partition:all type: union, limit embedded(offset:0, count:1) +Projection_26 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d +└─IndexMerge_25 1.00 root partition:all type: union, limit embedded(offset:0, count:1) + ├─Limit_23(Build) 0.91 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_19 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo ├─Limit_24(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_20 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo - ├─Limit_25(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_22 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo - └─TableRowIDScan_23(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo + │ └─IndexRangeScan_21 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo + └─TableRowIDScan_22(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1; a b c d 1 2 1 1 explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; id estRows task access object operator info -Projection_27 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d -└─IndexMerge_26 1.00 root partition:all type: union, limit embedded(offset:0, count:1) +Projection_26 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d +└─IndexMerge_25 1.00 root partition:all type: union, limit embedded(offset:0, count:1) + ├─Limit_23(Build) 0.91 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_19 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo ├─Limit_24(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_20 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo - ├─Limit_25(Build) 0.91 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_22 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo - └─TableRowIDScan_23(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo + │ └─IndexRangeScan_21 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo + └─TableRowIDScan_22(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1; a b c d 2 4 2 2 diff --git a/tests/integrationtest/r/index_merge.result b/tests/integrationtest/r/index_merge.result index 855be678add2f..85d66873a4953 100644 --- a/tests/integrationtest/r/index_merge.result +++ b/tests/integrationtest/r/index_merge.result @@ -468,13 +468,13 @@ create table t1(c1 int, c2 int, c3 int, key(c1), key(c2)); insert into t1 values(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5); explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 order by 1 limit 1 offset 2; id estRows task access object operator info -TopN_10 1.00 root index_merge.t1.c1, offset:2, count:1 -└─IndexMerge_19 3.00 root type: union - ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo - ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo - └─TopN_18(Probe) 3.00 cop[tikv] index_merge.t1.c1, offset:0, count:3 - └─Selection_17 1841.86 cop[tikv] lt(index_merge.t1.c3, 10) - └─TableRowIDScan_16 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root index_merge.t1.c1, offset:2, count:1 +└─IndexMerge_18 3.00 root type: union + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo + └─TopN_17(Probe) 3.00 cop[tikv] index_merge.t1.c1, offset:0, count:3 + └─Selection_16 1841.86 cop[tikv] lt(index_merge.t1.c3, 10) + └─TableRowIDScan_15 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 order by 1 limit 1 offset 2; c1 c2 c3 3 3 3 diff --git a/tests/integrationtest/r/infoschema/cluster_tables.result b/tests/integrationtest/r/infoschema/cluster_tables.result index 096300dec7d19..043cc263b3500 100644 --- a/tests/integrationtest/r/infoschema/cluster_tables.result +++ b/tests/integrationtest/r/infoschema/cluster_tables.result @@ -12,10 +12,10 @@ create session binding from history using plan digest '20cf414ff6bd6fff3de17a266 drop binding for sql digest '83de0854921816c038565229b8008f5d679d373d16bf6b2a5cacd5937e11ea21'; explain select * from information_schema.cluster_slow_query order by time limit 1; id estRows task access object operator info -TopN_8 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 -└─TableReader_17 1.00 root data:Limit_16 - └─Limit_16 1.00 cop[tidb] offset:0, count:1 - └─MemTableScan_15 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_7 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 +└─TableReader_16 1.00 root data:Limit_15 + └─Limit_15 1.00 cop[tidb] offset:0, count:1 + └─MemTableScan_14 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query order by time; id estRows task access object operator info Sort_4 10000.00 root information_schema.cluster_slow_query.time @@ -23,10 +23,10 @@ Sort_4 10000.00 root information_schema.cluster_slow_query.time └─MemTableScan_7 10000.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query order by time desc limit 1; id estRows task access object operator info -TopN_8 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 -└─TableReader_17 1.00 root data:Limit_16 - └─Limit_16 1.00 cop[tidb] offset:0, count:1 - └─MemTableScan_15 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_7 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 +└─TableReader_16 1.00 root data:Limit_15 + └─Limit_15 1.00 cop[tidb] offset:0, count:1 + └─MemTableScan_14 1.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query order by time desc; id estRows task access object operator info Sort_4 10000.00 root information_schema.cluster_slow_query.time:desc @@ -34,11 +34,11 @@ Sort_4 10000.00 root information_schema.cluster_slow_query.time:desc └─MemTableScan_7 10000.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time limit 1; id estRows task access object operator info -TopN_9 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 -└─TableReader_19 1.00 root data:Limit_18 - └─Limit_18 1.00 cop[tidb] offset:0, count:1 - └─Selection_17 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") - └─MemTableScan_16 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_8 1.00 root information_schema.cluster_slow_query.time, offset:0, count:1 +└─TableReader_18 1.00 root data:Limit_17 + └─Limit_17 1.00 cop[tidb] offset:0, count:1 + └─Selection_16 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") + └─MemTableScan_15 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time; id estRows task access object operator info Sort_5 166.42 root information_schema.cluster_slow_query.time @@ -47,11 +47,11 @@ Sort_5 166.42 root information_schema.cluster_slow_query.time └─MemTableScan_8 250.00 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time desc limit 1; id estRows task access object operator info -TopN_9 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 -└─TableReader_19 1.00 root data:Limit_18 - └─Limit_18 1.00 cop[tidb] offset:0, count:1 - └─Selection_17 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") - └─MemTableScan_16 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY +TopN_8 1.00 root information_schema.cluster_slow_query.time:desc, offset:0, count:1 +└─TableReader_18 1.00 root data:Limit_17 + └─Limit_17 1.00 cop[tidb] offset:0, count:1 + └─Selection_16 1.00 cop[tidb] ne(information_schema.cluster_slow_query.query, "x") + └─MemTableScan_15 1.50 cop[tidb] table:CLUSTER_SLOW_QUERY explain select * from information_schema.cluster_slow_query WHERE (time between '2020-09-24 15:23:41.421396' and '2020-09-25 17:57:35.047111') and query != 'x' order by time desc; id estRows task access object operator info Sort_5 166.42 root information_schema.cluster_slow_query.time:desc diff --git a/tests/integrationtest/r/planner/core/casetest/hint/hint.result b/tests/integrationtest/r/planner/core/casetest/hint/hint.result index ae53ad85735b2..9af080d6b214a 100644 --- a/tests/integrationtest/r/planner/core/casetest/hint/hint.result +++ b/tests/integrationtest/r/planner/core/casetest/hint/hint.result @@ -37,208 +37,208 @@ select /*+ order_index(thh, a) */ * from thh where a<1 order by a limit 1; a b explain select /*+ order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -Projection_18 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_17 1.00 root limit embedded(offset:0, count:1) - ├─Limit_16(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_17 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_16 1.00 root limit embedded(offset:0, count:1) + ├─Limit_15(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─TableReader_16 1.00 root data:Limit_15 - └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_11 1.00 root offset:0, count:1 +└─TableReader_15 1.00 root data:Limit_14 + └─Limit_14 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_17 1.00 root - ├─TopN_16(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_16 1.00 root + ├─TopN_15(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_16 1.00 root data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_15 1.00 root data:TopN_14 + └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 where a<10 limit 1; id estRows task access object operator info -IndexLookUp_14 1.00 root limit embedded(offset:0, count:1) -├─Limit_13(Build) 1.00 cop[tikv] offset:0, count:1 -│ └─IndexRangeScan_11 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo -└─TableRowIDScan_12(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexLookUp_13 1.00 root limit embedded(offset:0, count:1) +├─Limit_12(Build) 1.00 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_10 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo +└─TableRowIDScan_11(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t where a<10 limit 1; id estRows task access object operator info -Limit_9 1.00 root offset:0, count:1 -└─TableReader_13 1.00 root data:Limit_12 - └─Limit_12 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_11 333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +Limit_8 1.00 root offset:0, count:1 +└─TableReader_12 1.00 root data:Limit_11 + └─Limit_11 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_10 333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_b) */ * from t1 where b<10 order by b limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 - └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) - └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 + └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) + └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't1' explain select /*+ order_index(t, idx_b) */ * from t where b<10 order by b limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 - └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) - └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 + └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) + └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't' explain select /*+ no_order_index(t1, idx_b) */ * from t1 where b<10 order by b limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 - └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) - └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t1.b, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.b, offset:0, count:1 + └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.b, 10) + └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't1' explain select /*+ no_order_index(t, idx_b) */ * from t where b<10 order by b limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 - └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) - └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t.b, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.b, offset:0, count:1 + └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t.b, 10) + └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo Level Code Message Warning 1176 Key 'idx_b' doesn't exist in table 't' explain select /*+ order_index(t1, idx_a) use_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) - ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) + ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) */ * from t1 use index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) - ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) + ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) force_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) - ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) + ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) */ * from t1 force index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -Projection_20 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b -└─IndexLookUp_19 1.00 root limit embedded(offset:0, count:1) - ├─Limit_18(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_14 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b +└─IndexLookUp_18 1.00 root limit embedded(offset:0, count:1) + ├─Limit_17(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_13 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t1, idx_a) ignore_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) - └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) + └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ order_index(t, primary) use_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─TableReader_17 1.00 root data:Limit_16 - └─Limit_16 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_11 1.00 root offset:0, count:1 +└─TableReader_16 1.00 root data:Limit_15 + └─Limit_15 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ order_index(t, primary) */ * from t use index(primary) where a<10 order by a limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─TableReader_17 1.00 root data:Limit_16 - └─Limit_16 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_11 1.00 root offset:0, count:1 +└─TableReader_16 1.00 root data:Limit_15 + └─Limit_15 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ order_index(t, primary) force_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─TableReader_17 1.00 root data:Limit_16 - └─Limit_16 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +Limit_11 1.00 root offset:0, count:1 +└─TableReader_16 1.00 root data:Limit_15 + └─Limit_15 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ order_index(t, primary) */ * from t force index(primary) where a<10 order by a limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─TableReader_17 1.00 root data:Limit_16 - └─Limit_16 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo -explain select /*+ order_index(t, primary) ignore_index(t, primary) */ * from t where a<10 order by a limit 1; -id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 +Limit_11 1.00 root offset:0, count:1 └─TableReader_16 1.00 root data:Limit_15 └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_14 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo + └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +explain select /*+ order_index(t, primary) ignore_index(t, primary) */ * from t where a<10 order by a limit 1; +id estRows task access object operator info +Limit_11 1.00 root offset:0, count:1 +└─TableReader_15 1.00 root data:Limit_14 + └─Limit_14 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_13 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain select /*+ no_order_index(t, primary) use_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t use index(primary) where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) force_index(t, primary) */ * from t where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t, primary) */ * from t force index(primary) where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo -explain select /*+ no_order_index(t, primary) ignore_index(t, primary) */ * from t where a<10 order by a limit 1; -id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 └─TableReader_16 1.00 root data:TopN_15 └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +explain select /*+ no_order_index(t, primary) ignore_index(t, primary) */ * from t where a<10 order by a limit 1; +id estRows task access object operator info +TopN_8 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 +└─TableReader_15 1.00 root data:TopN_14 + └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_13 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) use_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_19 1.00 root - ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_18 1.00 root + ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 use index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_19 1.00 root - ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_18 1.00 root + ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) force_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_19 1.00 root - ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_18 1.00 root + ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) */ * from t1 force index(idx_a) where a<10 order by a limit 1; id estRows task access object operator info -TopN_10 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─IndexLookUp_19 1.00 root - ├─TopN_18(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_14 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─IndexLookUp_18 1.00 root + ├─TopN_17(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_13 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ no_order_index(t1, idx_a) ignore_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 -└─TableReader_17 1.00 root data:TopN_16 - └─TopN_16 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - └─Selection_15 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) - └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 +└─TableReader_16 1.00 root data:TopN_15 + └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + └─Selection_14 3323.33 cop[tikv] lt(planner__core__casetest__hint__hint.t1.a, 10) + └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select /*+ qb_name(qb, v) order_index(t1@qb, idx_a) */ * from v; id estRows task access object operator info Projection_19 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b @@ -267,93 +267,93 @@ TopN_10 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 └─TableRangeScan_15 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain WITH CTE AS (select /*+ order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; id estRows task access object operator info -HashAgg_32 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 -└─Union_33 1.28 root - ├─Selection_35 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) - │ └─CTEFullScan_36 0.80 root CTE:cte data:CTE_0 - └─Selection_38 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) - └─CTEFullScan_39 0.80 root CTE:cte data:CTE_0 +HashAgg_31 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 +└─Union_32 1.28 root + ├─Selection_34 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) + │ └─CTEFullScan_35 0.80 root CTE:cte data:CTE_0 + └─Selection_37 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) + └─CTEFullScan_38 0.80 root CTE:cte data:CTE_0 CTE_0 0.80 root Non-Recursive CTE -└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) - └─Projection_30 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b - └─IndexLookUp_29 1.00 root limit embedded(offset:0, count:1) - ├─Limit_28(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_26 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo - └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) + └─Projection_29 1.00 root planner__core__casetest__hint__hint.t1.a, planner__core__casetest__hint__hint.t1.b + └─IndexLookUp_28 1.00 root limit embedded(offset:0, count:1) + ├─Limit_27(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_25 1.00 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:true, stats:pseudo + └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain WITH CTE AS (select /*+ order_index(t, primary) */ * from t where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; id estRows task access object operator info -HashAgg_29 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 -└─Union_30 1.28 root - ├─Selection_32 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) - │ └─CTEFullScan_33 0.80 root CTE:cte data:CTE_0 - └─Selection_35 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) - └─CTEFullScan_36 0.80 root CTE:cte data:CTE_0 +HashAgg_28 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 +└─Union_29 1.28 root + ├─Selection_31 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) + │ └─CTEFullScan_32 0.80 root CTE:cte data:CTE_0 + └─Selection_34 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) + └─CTEFullScan_35 0.80 root CTE:cte data:CTE_0 CTE_0 0.80 root Non-Recursive CTE -└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) - └─Limit_24 1.00 root offset:0, count:1 - └─TableReader_28 1.00 root data:Limit_27 - └─Limit_27 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_26 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo +└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) + └─Limit_23 1.00 root offset:0, count:1 + └─TableReader_27 1.00 root data:Limit_26 + └─Limit_26 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_25 333.33 cop[tikv] table:t range:[-inf,10), keep order:true, stats:pseudo explain WITH CTE AS (select /*+ no_order_index(t1, idx_a) */ * from t1 where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; id estRows task access object operator info -HashAgg_30 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 -└─Union_31 1.28 root - ├─Selection_33 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) - │ └─CTEFullScan_34 0.80 root CTE:cte data:CTE_0 - └─Selection_36 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) - └─CTEFullScan_37 0.80 root CTE:cte data:CTE_0 -CTE_0 0.80 root Non-Recursive CTE -└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) - └─TopN_22 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - └─IndexLookUp_29 1.00 root - ├─TopN_28(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 - │ └─IndexRangeScan_26 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo - └─TableRowIDScan_27(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo -explain WITH CTE AS (select /*+ no_order_index(t, primary) */ * from t where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; -id estRows task access object operator info -HashAgg_29 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 +HashAgg_29 2.00 root group by:Column#8, Column#9, funcs:firstrow(Column#8)->Column#8, funcs:firstrow(Column#9)->Column#9 └─Union_30 1.28 root - ├─Selection_32 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) + ├─Selection_32 0.64 root lt(planner__core__casetest__hint__hint.t1.a, 18) │ └─CTEFullScan_33 0.80 root CTE:cte data:CTE_0 - └─Selection_35 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) + └─Selection_35 0.64 root gt(planner__core__casetest__hint__hint.t1.b, 1) └─CTEFullScan_36 0.80 root CTE:cte data:CTE_0 CTE_0 0.80 root Non-Recursive CTE -└─Selection_19(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) - └─TopN_21 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableReader_28 1.00 root data:TopN_27 - └─TopN_27 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 - └─TableRangeScan_26 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo +└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t1.a, 18), gt(planner__core__casetest__hint__hint.t1.b, 1)) + └─TopN_21 1.00 root planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + └─IndexLookUp_28 1.00 root + ├─TopN_27(Build) 1.00 cop[tikv] planner__core__casetest__hint__hint.t1.a, offset:0, count:1 + │ └─IndexRangeScan_25 3323.33 cop[tikv] table:t1, index:idx_a(a) range:[-inf,10), keep order:false, stats:pseudo + └─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +explain WITH CTE AS (select /*+ no_order_index(t, primary) */ * from t where a<10 order by a limit 1) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1; +id estRows task access object operator info +HashAgg_28 2.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 +└─Union_29 1.28 root + ├─Selection_31 0.64 root lt(planner__core__casetest__hint__hint.t.a, 18) + │ └─CTEFullScan_32 0.80 root CTE:cte data:CTE_0 + └─Selection_34 0.64 root gt(planner__core__casetest__hint__hint.t.b, 1) + └─CTEFullScan_35 0.80 root CTE:cte data:CTE_0 +CTE_0 0.80 root Non-Recursive CTE +└─Selection_18(Seed Part) 0.80 root or(lt(planner__core__casetest__hint__hint.t.a, 18), gt(planner__core__casetest__hint__hint.t.b, 1)) + └─TopN_20 1.00 root planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableReader_27 1.00 root data:TopN_26 + └─TopN_26 1.00 cop[tikv] planner__core__casetest__hint__hint.t.a, offset:0, count:1 + └─TableRangeScan_25 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo explain select /*+ order_index(th, a) */ a from th where a<1 order by a limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─IndexReader_16 1.00 root partition:all index:Limit_15 - └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─IndexRangeScan_14 1.00 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:true, stats:pseudo +Limit_11 1.00 root offset:0, count:1 +└─IndexReader_15 1.00 root partition:all index:Limit_14 + └─Limit_14 1.00 cop[tikv] offset:0, count:1 + └─IndexRangeScan_13 1.00 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:true, stats:pseudo explain select /*+ no_order_index(th, a) */ a from th where a<1 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.th.a, offset:0, count:1 -└─IndexReader_16 1.00 root partition:all index:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.th.a, offset:0, count:1 - └─IndexRangeScan_14 3323.33 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.th.a, offset:0, count:1 +└─IndexReader_15 1.00 root partition:all index:TopN_14 + └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.th.a, offset:0, count:1 + └─IndexRangeScan_13 3323.33 cop[tikv] table:th, index:a(a) range:[-inf,1), keep order:false, stats:pseudo explain select /*+ order_index(thp, primary) */ a from thp where a<1 order by a limit 1; id estRows task access object operator info -Limit_12 1.00 root offset:0, count:1 -└─TableReader_16 1.00 root partition:all data:Limit_15 - └─Limit_15 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:true, stats:pseudo +Limit_11 1.00 root offset:0, count:1 +└─TableReader_15 1.00 root partition:all data:Limit_14 + └─Limit_14 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_13 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:true, stats:pseudo explain select /*+ no_order_index(thp, primary) */ a from thp where a<1 order by a limit 1; id estRows task access object operator info -TopN_9 1.00 root planner__core__casetest__hint__hint.thp.a, offset:0, count:1 -└─TableReader_16 1.00 root partition:all data:TopN_15 - └─TopN_15 1.00 cop[tikv] planner__core__casetest__hint__hint.thp.a, offset:0, count:1 - └─TableRangeScan_14 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:false, stats:pseudo +TopN_8 1.00 root planner__core__casetest__hint__hint.thp.a, offset:0, count:1 +└─TableReader_15 1.00 root partition:all data:TopN_14 + └─TopN_14 1.00 cop[tikv] planner__core__casetest__hint__hint.thp.a, offset:0, count:1 + └─TableRangeScan_13 3333.33 cop[tikv] table:thp range:[-inf,1), keep order:false, stats:pseudo explain select /*+ order_index(thh, a) */ * from thh where a<1 order by a limit 1; id estRows task access object operator info -Projection_18 1.00 root planner__core__casetest__hint__hint.thh.a, planner__core__casetest__hint__hint.thh.b -└─IndexLookUp_17 1.00 root partition:all limit embedded(offset:0, count:1) - ├─Limit_16(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_14 1.00 cop[tikv] table:thh, index:a(a) range:[-inf,1), keep order:true, stats:pseudo - └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:thh keep order:false, stats:pseudo +Projection_17 1.00 root planner__core__casetest__hint__hint.thh.a, planner__core__casetest__hint__hint.thh.b +└─IndexLookUp_16 1.00 root partition:all limit embedded(offset:0, count:1) + ├─Limit_15(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_13 1.00 cop[tikv] table:thh, index:a(a) range:[-inf,1), keep order:true, stats:pseudo + └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:thh keep order:false, stats:pseudo set tidb_cost_model_version=2; drop view if exists v, v1, v2; drop table if exists t, t1, t2; diff --git a/tests/integrationtest/r/planner/core/casetest/integration.result b/tests/integrationtest/r/planner/core/casetest/integration.result index 97e30d0604dec..284022e10388d 100644 --- a/tests/integrationtest/r/planner/core/casetest/integration.result +++ b/tests/integrationtest/r/planner/core/casetest/integration.result @@ -1151,18 +1151,18 @@ TableReader_7 3.00 130.42 root data:Selection_6 └─TableFullScan_5 5.00 1136.54 cop[tikv] table:t keep order:false explain format = 'verbose' select * from t where b = 6 order by a limit 1; id estRows estCost task access object operator info -Limit_12 1.00 98.74 root offset:0, count:1 -└─TableReader_25 1.00 98.74 root data:Limit_24 - └─Limit_24 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_23 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_22 5.00 1136.54 cop[tikv] table:t keep order:true +Limit_11 1.00 98.74 root offset:0, count:1 +└─TableReader_24 1.00 98.74 root data:Limit_23 + └─Limit_23 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_22 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_21 5.00 1136.54 cop[tikv] table:t keep order:true explain format = 'verbose' select * from t where b = 6 limit 1; id estRows estCost task access object operator info -Limit_9 1.00 98.74 root offset:0, count:1 -└─TableReader_14 1.00 98.74 root data:Limit_13 - └─Limit_13 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_12 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_11 5.00 1136.54 cop[tikv] table:t keep order:false +Limit_8 1.00 98.74 root offset:0, count:1 +└─TableReader_13 1.00 98.74 root data:Limit_12 + └─Limit_12 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_11 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_10 5.00 1136.54 cop[tikv] table:t keep order:false set tidb_opt_prefer_range_scan = 1; explain format = 'verbose' select * from t where b > 5; id estRows estCost task access object operator info @@ -1171,18 +1171,18 @@ TableReader_7 3.00 130.42 root data:Selection_6 └─TableFullScan_5 5.00 1136.54 cop[tikv] table:t keep order:false explain format = 'verbose' select * from t where b = 6 order by a limit 1; id estRows estCost task access object operator info -Limit_12 1.00 98.74 root offset:0, count:1 -└─TableReader_25 1.00 98.74 root data:Limit_24 - └─Limit_24 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_23 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_22 5.00 1136.54 cop[tikv] table:t keep order:true +Limit_11 1.00 98.74 root offset:0, count:1 +└─TableReader_24 1.00 98.74 root data:Limit_23 + └─Limit_23 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_22 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_21 5.00 1136.54 cop[tikv] table:t keep order:true explain format = 'verbose' select * from t where b = 6 limit 1; id estRows estCost task access object operator info -Limit_9 1.00 98.74 root offset:0, count:1 -└─TableReader_14 1.00 98.74 root data:Limit_13 - └─Limit_13 1.00 1386.04 cop[tikv] offset:0, count:1 - └─Selection_12 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) - └─TableFullScan_11 5.00 1136.54 cop[tikv] table:t keep order:false +Limit_8 1.00 98.74 root offset:0, count:1 +└─TableReader_13 1.00 98.74 root data:Limit_12 + └─Limit_12 1.00 1386.04 cop[tikv] offset:0, count:1 + └─Selection_11 1.00 1386.04 cop[tikv] eq(planner__core__casetest__integration.t.b, 6) + └─TableFullScan_10 5.00 1136.54 cop[tikv] table:t keep order:false set @@tidb_enable_chunk_rpc = default; set tidb_opt_prefer_range_scan = default; drop table if exists t; diff --git a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result index 7f16599228e35..0228e7e0d5a4e 100644 --- a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result +++ b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result @@ -823,20 +823,20 @@ HashAgg_16 8000.00 root group by:planner__core__casetest__physicalplantest__phy └─TableFullScan_15 10000.00 cop[tikv] table:test keep order:false, stats:pseudo explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test limit 1) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain limit and ref by CET1 recursive part cannot be inlined; id estRows task access object operator info -CTEFullScan_43 16400.00 root CTE:cte1 data:CTE_1 +CTEFullScan_42 16400.00 root CTE:cte1 data:CTE_1 CTE_1 16400.00 root Recursive CTE ├─TableReader_22(Seed Part) 10000.00 root data:TableFullScan_21 │ └─TableFullScan_21 10000.00 cop[tikv] table:test keep order:false, stats:pseudo -└─HashJoin_37(Recursive Part) 6400.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.test.a, planner__core__casetest__physicalplantest__physical_plan.test.a)] - ├─Selection_38(Build) 0.80 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) - │ └─CTEFullScan_39 1.00 root CTE:cte data:CTE_0 - └─Selection_40(Probe) 8000.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) - └─CTETable_41 10000.00 root Scan on CTE_1 +└─HashJoin_36(Recursive Part) 6400.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.test.a, planner__core__casetest__physicalplantest__physical_plan.test.a)] + ├─Selection_37(Build) 0.80 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + │ └─CTEFullScan_38 1.00 root CTE:cte data:CTE_0 + └─Selection_39(Probe) 8000.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + └─CTETable_40 10000.00 root Scan on CTE_1 CTE_0 1.00 root Non-Recursive CTE -└─Limit_29(Seed Part) 1.00 root offset:0, count:1 - └─TableReader_33 1.00 root data:Limit_32 - └─Limit_32 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan_31 1.00 cop[tikv] table:test keep order:false, stats:pseudo +└─Limit_28(Seed Part) 1.00 root offset:0, count:1 + └─TableReader_32 1.00 root data:Limit_31 + └─Limit_31 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan_30 1.00 cop[tikv] table:test keep order:false, stats:pseudo explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test order by a) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain order by and ref by CET1 recursive part cannot be inlined; id estRows task access object operator info CTEFullScan_35 20000.00 root CTE:cte1 data:CTE_1 @@ -3997,12 +3997,12 @@ Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type set tidb_cost_model_version=DEFAULT; explain select /*+ USE_INDEX_MERGE(t3, aid_c1, aid_c2) */ * from t3 where (aid = 1 and c1='aaa') or (aid = 1 and c2='bbb') limit 1; id estRows task access object operator info -IndexMerge_21 1.00 root type: union, limit embedded(offset:0, count:1) +IndexMerge_20 1.00 root type: union, limit embedded(offset:0, count:1) +├─Limit_18(Build) 0.01 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_11 0.01 cop[tikv] table:t3, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo ├─Limit_19(Build) 0.01 cop[tikv] offset:0, count:1 -│ └─IndexRangeScan_12 0.01 cop[tikv] table:t3, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo -├─Limit_20(Build) 0.01 cop[tikv] offset:0, count:1 -│ └─IndexRangeScan_13 0.01 cop[tikv] table:t3, index:aid_c2(aid, c2) range:[1 "bbb",1 "bbb"], keep order:false, stats:pseudo -└─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t3 keep order:false, stats:pseudo +│ └─IndexRangeScan_12 0.01 cop[tikv] table:t3, index:aid_c2(aid, c2) range:[1 "bbb",1 "bbb"], keep order:false, stats:pseudo +└─TableRowIDScan_13(Probe) 1.00 cop[tikv] table:t3 keep order:false, stats:pseudo show warnings; Level Code Message CREATE TABLE `tbl_43` ( diff --git a/tests/integrationtest/r/planner/core/plan_cache.result b/tests/integrationtest/r/planner/core/plan_cache.result index 70effae8c302c..38a7be8f16f4c 100644 --- a/tests/integrationtest/r/planner/core/plan_cache.result +++ b/tests/integrationtest/r/planner/core/plan_cache.result @@ -1637,10 +1637,10 @@ select @@last_plan_from_cache; 0 explain format = 'row' select * from t limit 1; id estRows task access object operator info -Limit_8 1.00 root offset:0, count:1 -└─IndexReader_13 1.00 root index:Limit_12 - └─Limit_12 1.00 cop[tikv] offset:0, count:1 - └─IndexFullScan_11 1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +Limit_7 1.00 root offset:0, count:1 +└─IndexReader_12 1.00 root index:Limit_11 + └─Limit_11 1.00 cop[tikv] offset:0, count:1 + └─IndexFullScan_10 1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo explain format = 'brief' select * from t limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 @@ -1650,45 +1650,45 @@ Limit 1.00 root offset:0, count:1 explain format = 'dot' select * from t limit 1; dot contents -digraph Limit_8 { -subgraph cluster8{ +digraph Limit_7 { +subgraph cluster7{ node [style=filled, color=lightgrey] color=black label = "root" -"Limit_8" -> "IndexReader_13" +"Limit_7" -> "IndexReader_12" } -subgraph cluster12{ +subgraph cluster11{ node [style=filled, color=lightgrey] color=black label = "cop" -"Limit_12" -> "IndexFullScan_11" +"Limit_11" -> "IndexFullScan_10" } -"IndexReader_13" -> "Limit_12" +"IndexReader_12" -> "Limit_11" } explain format = 'tidb_json' select * from t limit 1; TiDB_JSON [ { - "id": "Limit_8", + "id": "Limit_7", "estRows": "1.00", "taskType": "root", "operatorInfo": "offset:0, count:1", "subOperators": [ { - "id": "IndexReader_13", + "id": "IndexReader_12", "estRows": "1.00", "taskType": "root", - "operatorInfo": "index:Limit_12", + "operatorInfo": "index:Limit_11", "subOperators": [ { - "id": "Limit_12", + "id": "Limit_11", "estRows": "1.00", "taskType": "cop[tikv]", "operatorInfo": "offset:0, count:1", "subOperators": [ { - "id": "IndexFullScan_11", + "id": "IndexFullScan_10", "estRows": "1.00", "taskType": "cop[tikv]", "accessObject": "table:t, index:a(a)", @@ -1704,16 +1704,16 @@ TiDB_JSON explain format = 'verbose' select * from t limit 1; id estRows estCost task access object operator info -Limit_8 1.00 12.97 root offset:0, count:1 -└─IndexReader_13 1.00 12.97 root index:Limit_12 - └─Limit_12 1.00 162.80 cop[tikv] offset:0, count:1 - └─IndexFullScan_11 1.00 162.80 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +Limit_7 1.00 12.97 root offset:0, count:1 +└─IndexReader_12 1.00 12.97 root index:Limit_11 + └─Limit_11 1.00 162.80 cop[tikv] offset:0, count:1 + └─IndexFullScan_10 1.00 162.80 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo explain format = 'cost_trace' select * from t limit 1; id estRows estCost costFormula task access object operator info -Limit_8 1.00 12.97 ((((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00) root offset:0, count:1 -└─IndexReader_13 1.00 12.97 (((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:Limit_12 - └─Limit_12 1.00 162.80 ((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00) cop[tikv] offset:0, count:1 - └─IndexFullScan_11 1.00 162.80 (scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +Limit_7 1.00 12.97 ((((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00) root offset:0, count:1 +└─IndexReader_12 1.00 12.97 (((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:Limit_11 + └─Limit_11 1.00 162.80 ((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00) cop[tikv] offset:0, count:1 + └─IndexFullScan_10 1.00 162.80 (scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo set tidb_enable_non_prepared_plan_cache=DEFAULT; drop table if exists t, t1, t2; CREATE TABLE `t1` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/tests/integrationtest/r/planner/core/plan_cost_ver2.result b/tests/integrationtest/r/planner/core/plan_cost_ver2.result index ad80f4a28be76..5ddbf4080fede 100644 --- a/tests/integrationtest/r/planner/core/plan_cost_ver2.result +++ b/tests/integrationtest/r/planner/core/plan_cost_ver2.result @@ -4,18 +4,18 @@ insert into t values (1); analyze table t all columns; explain format='verbose' select /*+ limit_to_cop() */ * from t where a=1 order by a limit 1; id estRows estCost task access object operator info -TopN_9 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1 -└─TableReader_17 1.00 19.11 root data:TopN_16 - └─TopN_16 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1 - └─Selection_15 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) - └─TableFullScan_14 1.00 203.50 cop[tikv] table:t keep order:false +TopN_8 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1 +└─TableReader_16 1.00 19.11 root data:TopN_15 + └─TopN_15 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1 + └─Selection_14 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) + └─TableFullScan_13 1.00 203.50 cop[tikv] table:t keep order:false explain format='verbose' select /*+ limit_to_cop() */ * from t where a=1 order by a limit 1000000000; id estRows estCost task access object operator info -TopN_9 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 -└─TableReader_17 1.00 19.11 root data:TopN_16 - └─TopN_16 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 - └─Selection_15 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) - └─TableFullScan_14 1.00 203.50 cop[tikv] table:t keep order:false +TopN_8 1.00 20.71 root planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 +└─TableReader_16 1.00 19.11 root data:TopN_15 + └─TopN_15 1.00 255.00 cop[tikv] planner__core__plan_cost_ver2.t.a, offset:0, count:1000000000 + └─Selection_14 1.00 253.40 cop[tikv] eq(planner__core__plan_cost_ver2.t.a, 1) + └─TableFullScan_13 1.00 203.50 cop[tikv] table:t keep order:false drop table if exists t; create table t (a int primary key, b int, c int, key(b)); insert into t values (0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5), (6, 6, 6), (7, 7, 7), (8, 8, 8), (9, 9, 9), (10, 10, 10), (11, 11, 11), (12, 12, 12), (13, 13, 13), (14, 14, 14), (15, 15, 15), (16, 16, 16), (17, 17, 17), (18, 18, 18), (19, 19, 19), (20, 20, 20), (21, 21, 21), (22, 22, 22), (23, 23, 23), (24, 24, 24), (25, 25, 25), (26, 26, 26), (27, 27, 27), (28, 28, 28), (29, 29, 29), (30, 30, 30), (31, 31, 31), (32, 32, 32), (33, 33, 33), (34, 34, 34), (35, 35, 35), (36, 36, 36), (37, 37, 37), (38, 38, 38), (39, 39, 39), (40, 40, 40), (41, 41, 41), (42, 42, 42), (43, 43, 43), (44, 44, 44), (45, 45, 45), (46, 46, 46), (47, 47, 47), (48, 48, 48), (49, 49, 49), (50, 50, 50), (51, 51, 51), (52, 52, 52), (53, 53, 53), (54, 54, 54), (55, 55, 55), (56, 56, 56), (57, 57, 57), (58, 58, 58), (59, 59, 59), (60, 60, 60), (61, 61, 61), (62, 62, 62), (63, 63, 63), (64, 64, 64), (65, 65, 65), (66, 66, 66), (67, 67, 67), (68, 68, 68), (69, 69, 69), (70, 70, 70), (71, 71, 71), (72, 72, 72), (73, 73, 73), (74, 74, 74), (75, 75, 75), (76, 76, 76), (77, 77, 77), (78, 78, 78), (79, 79, 79), (80, 80, 80), (81, 81, 81), (82, 82, 82), (83, 83, 83), (84, 84, 84), (85, 85, 85), (86, 86, 86), (87, 87, 87), (88, 88, 88), (89, 89, 89), (90, 90, 90), (91, 91, 91), (92, 92, 92), (93, 93, 93), (94, 94, 94), (95, 95, 95), (96, 96, 96), (97, 97, 97), (98, 98, 98), (99, 99, 99); @@ -241,12 +241,12 @@ create table t(a int, b int, c int, d int, index ia(a), index ibc(b,c)); set @@tidb_cost_model_version=1; explain select * from t where a between 1 and 5 and b != 200 and c = 20 limit 100000; id estRows task access object operator info -Limit_10 0.17 root offset:0, count:100000 -└─IndexLookUp_23 0.17 root - ├─IndexRangeScan_15(Build) 250.00 cop[tikv] table:t, index:ia(a) range:[1,5], keep order:false, stats:pseudo - └─Limit_22(Probe) 0.17 cop[tikv] offset:0, count:100000 - └─Selection_17 0.17 cop[tikv] eq(planner__core__plan_cost_ver2.t.c, 20), ne(planner__core__plan_cost_ver2.t.b, 200) - └─TableRowIDScan_16 250.00 cop[tikv] table:t keep order:false, stats:pseudo +Limit_9 0.17 root offset:0, count:100000 +└─IndexLookUp_22 0.17 root + ├─IndexRangeScan_14(Build) 250.00 cop[tikv] table:t, index:ia(a) range:[1,5], keep order:false, stats:pseudo + └─Limit_21(Probe) 0.17 cop[tikv] offset:0, count:100000 + └─Selection_16 0.17 cop[tikv] eq(planner__core__plan_cost_ver2.t.c, 20), ne(planner__core__plan_cost_ver2.t.b, 200) + └─TableRowIDScan_15 250.00 cop[tikv] table:t keep order:false, stats:pseudo drop table if exists t; create table t (a int); set @@tidb_cost_model_version=2; diff --git a/tests/integrationtest/r/planner/core/rule_result_reorder.result b/tests/integrationtest/r/planner/core/rule_result_reorder.result index 7abfbf0d2ea18..24cefea1ff4c7 100644 --- a/tests/integrationtest/r/planner/core/rule_result_reorder.result +++ b/tests/integrationtest/r/planner/core/rule_result_reorder.result @@ -22,19 +22,19 @@ drop table if exists t; create table t (a int primary key, b int, c int, d int, key(b)); explain select * from t where a > 0 limit 1; id estRows task access object operator info -Limit_13 1.00 root offset:0, count:1 -└─TableReader_23 1.00 root data:Limit_22 - └─Limit_22 1.00 cop[tikv] offset:0, count:1 - └─TableRangeScan_21 1.00 cop[tikv] table:t range:(0,+inf], keep order:true, stats:pseudo +Limit_12 1.00 root offset:0, count:1 +└─TableReader_22 1.00 root data:Limit_21 + └─Limit_21 1.00 cop[tikv] offset:0, count:1 + └─TableRangeScan_20 1.00 cop[tikv] table:t range:(0,+inf], keep order:true, stats:pseudo create session binding for select * from t where a>0 limit 1 using select * from t use index(b) where a>0 limit 1; explain select * from t where a > 0 limit 1; id estRows task access object operator info -TopN_10 1.00 root planner__core__rule_result_reorder.t.a, offset:0, count:1 -└─IndexLookUp_20 1.00 root - ├─TopN_19(Build) 1.00 cop[tikv] planner__core__rule_result_reorder.t.a, offset:0, count:1 - │ └─Selection_18 3333.33 cop[tikv] gt(planner__core__rule_result_reorder.t.a, 0) - │ └─IndexFullScan_16 10000.00 cop[tikv] table:t, index:b(b) keep order:false, stats:pseudo - └─TableRowIDScan_17(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo +TopN_9 1.00 root planner__core__rule_result_reorder.t.a, offset:0, count:1 +└─IndexLookUp_19 1.00 root + ├─TopN_18(Build) 1.00 cop[tikv] planner__core__rule_result_reorder.t.a, offset:0, count:1 + │ └─Selection_17 3333.33 cop[tikv] gt(planner__core__rule_result_reorder.t.a, 0) + │ └─IndexFullScan_15 10000.00 cop[tikv] table:t, index:b(b) keep order:false, stats:pseudo + └─TableRowIDScan_16(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo set tidb_enable_ordered_result_mode=DEFAULT; set tidb_opt_limit_push_down_threshold=DEFAULT; set tidb_enable_ordered_result_mode=1; diff --git a/tests/integrationtest/r/topn_push_down.result b/tests/integrationtest/r/topn_push_down.result index 671492cb0023a..5c8f9e2dae86b 100644 --- a/tests/integrationtest/r/topn_push_down.result +++ b/tests/integrationtest/r/topn_push_down.result @@ -186,8 +186,8 @@ Limit 0.00 root offset:0, count:5 └─IndexRangeScan 0.00 cop[tikv] table:p, index:payment_relate_id(relate_id) range: decided by [eq(topn_push_down.p.relate_id, topn_push_down.tr.id)], keep order:false, stats:pseudo desc select 1 as a from dual order by a limit 1; id estRows task access object operator info -Projection_7 1.00 root 1->Column#1 -└─TableDual_8 1.00 root rows:1 +Projection_6 1.00 root 1->Column#1 +└─TableDual_7 1.00 root rows:1 drop table if exists t1; drop table if exists t2; create table t1(a bigint, b bigint); @@ -206,16 +206,16 @@ Apply_15 9990.00 root semi join, left side:TableReader_18, equal:[eq(topn_push_ └─TableFullScan_22 12487.50 cop[tikv] table:t2 keep order:false, stats:pseudo desc select * from t1 where t1.a in (select a from (select t2.a as a, t1.b as b from t2 where t2.b > t1.b) x order by b limit 1); id estRows task access object operator info -Apply_18 9990.00 root semi join, left side:TableReader_21, equal:[eq(topn_push_down.t1.a, topn_push_down.t2.a)] -├─TableReader_21(Build) 9990.00 root data:Selection_20 -│ └─Selection_20 9990.00 cop[tikv] not(isnull(topn_push_down.t1.a)) -│ └─TableFullScan_19 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -└─Selection_22(Probe) 7992.00 root not(isnull(topn_push_down.t2.a)) - └─Limit_24 9990.00 root offset:0, count:1 - └─TableReader_29 9990.00 root data:Limit_28 - └─Limit_28 9990.00 cop[tikv] offset:0, count:1 - └─Selection_27 9990.00 cop[tikv] gt(topn_push_down.t2.b, topn_push_down.t1.b) - └─TableFullScan_26 12487.50 cop[tikv] table:t2 keep order:false, stats:pseudo +Apply_17 9990.00 root semi join, left side:TableReader_20, equal:[eq(topn_push_down.t1.a, topn_push_down.t2.a)] +├─TableReader_20(Build) 9990.00 root data:Selection_19 +│ └─Selection_19 9990.00 cop[tikv] not(isnull(topn_push_down.t1.a)) +│ └─TableFullScan_18 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─Selection_21(Probe) 7992.00 root not(isnull(topn_push_down.t2.a)) + └─Limit_23 9990.00 root offset:0, count:1 + └─TableReader_28 9990.00 root data:Limit_27 + └─Limit_27 9990.00 cop[tikv] offset:0, count:1 + └─Selection_26 9990.00 cop[tikv] gt(topn_push_down.t2.b, topn_push_down.t1.b) + └─TableFullScan_25 12487.50 cop[tikv] table:t2 keep order:false, stats:pseudo drop table if exists t; create table t(a int not null, index idx(a)); explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5; From ad9ed2c959529bb4681d5b9570a97b0af435780d Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 15:50:13 +0800 Subject: [PATCH 28/31] update Signed-off-by: Weizhen Wang --- .../testdata/ann_index_suite_in.json | 22 +-- .../testdata/ann_index_suite_out.json | 152 +++++++++--------- 2 files changed, 87 insertions(+), 87 deletions(-) diff --git a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json index ff47cd7e28673..3fd08fe7a0619 100644 --- a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json +++ b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json @@ -48,19 +48,19 @@ { "name": "TestVectorSearchWithPKAuto", "cases": [ - "explain select id from t1", + "explain format = 'brief' select id from t1", - "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", - "explain select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", + "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", - "explain select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", - "explain select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10" + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", + "explain format = 'brief' select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", + "explain format = 'brief' select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10" ] }, { diff --git a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json index 6e0233e74e708..b003cd040331a 100644 --- a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json +++ b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_out.json @@ -436,133 +436,133 @@ "Name": "TestVectorSearchWithPKAuto", "Cases": [ { - "SQL": "explain select id from t1", + "SQL": "explain format = 'brief' select id from t1", "Plan": [ - "TableReader_14 6000.00 root MppVersion: 3, data:ExchangeSender_13", - "└─ExchangeSender_13 6000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TableFullScan_11 6000.00 mpp[tiflash] table:t1 keep order:false" + "TableReader 6000.00 root MppVersion: 3, data:ExchangeSender", + "└─ExchangeSender 6000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_11 10.00 root Column#11, offset:0, count:10", - "└─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#11, offset:0, count:10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#11" + "TopN 10.00 root Column#11, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#11, offset:0, count:10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#11" ], "Warn": null }, { - "SQL": "explain select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", + "SQL": "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", "Plan": [ - "Projection_5 6000.00 root test.t1.id", - "└─Projection_14 6000.00 root test.t1.id, test.t1.vec", - " └─Sort_7 6000.00 root Column#8", - " └─Projection_15 6000.00 root test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", - " └─TableReader_12 6000.00 root MppVersion: 3, data:ExchangeSender_11", - " └─ExchangeSender_11 6000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TableFullScan_10 6000.00 mpp[tiflash] table:t1 keep order:false" + "Projection 6000.00 root test.t1.id", + "└─Projection 6000.00 root test.t1.id, test.t1.vec", + " └─Sort 6000.00 root Column#8", + " └─Projection 6000.00 root test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#8", + " └─TableReader 6000.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 6000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_11 10.00 root Column#9, offset:0, count:10", - "└─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#9, offset:0, count:10", - " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#9", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "TopN 10.00 root Column#9, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#9, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#9", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { - "SQL": "explain select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "TopN_11 10.00 root Column#13, offset:0, count:10", - "└─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#13, offset:0, count:10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#13" + "TopN 10.00 root Column#13, offset:0, count:10", + "└─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#13, offset:0, count:10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#13" ], "Warn": null }, { - "SQL": "explain select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "SQL": "explain format = 'brief' select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "Plan": [ - "Projection_7 10.00 root test.t1.a, test.t1.id, test.t1.b", - "└─TopN_11 10.00 root Column#13, offset:0, count:10", - " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#13, offset:0, count:10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#13" + "Projection 10.00 root test.t1.a, test.t1.id, test.t1.b", + "└─TopN 10.00 root Column#13, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#13, offset:0, count:10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)->Column#13" ], "Warn": null }, { - "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_7 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_11 10.00 root Column#10, offset:0, count:10", - " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#10, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { - "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", + "SQL": "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", "Plan": [ - "Sort_4 6000.00 root Column#7", - "└─TableReader_17 6000.00 root MppVersion: 3, data:ExchangeSender_16", - " └─ExchangeSender_16 6000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection_7 6000.00 mpp[tiflash] test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - " └─TableFullScan_14 6000.00 mpp[tiflash] table:t1 keep order:false" + "Sort 6000.00 root Column#7", + "└─TableReader 6000.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 6000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 6000.00 mpp[tiflash] test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + " └─TableFullScan 6000.00 mpp[tiflash] table:t1 keep order:false" ], "Warn": null }, { - "SQL": "explain select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_7 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_11 10.00 root Column#10, offset:0, count:10", - " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection 10.00 root test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#10, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, test.t1.c, test.t1.d, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { - "SQL": "explain select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", "Plan": [ - "Projection_7 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7, test.t1.a, test.t1.b", - "└─TopN_11 10.00 root Column#10, offset:0, count:10", - " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection 10.00 root test.t1.id, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7, test.t1.a, test.t1.b", + "└─TopN 10.00 root Column#10, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null }, { - "SQL": "explain select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "SQL": "explain format = 'brief' select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "Plan": [ - "Projection_7 10.00 root test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", - "└─TopN_11 10.00 root Column#10, offset:0, count:10", - " └─TableReader_29 10.00 root MppVersion: 3, data:ExchangeSender_28", - " └─ExchangeSender_28 10.00 mpp[tiflash] ExchangeType: PassThrough", - " └─TopN_27 10.00 mpp[tiflash] Column#10, offset:0, count:10", - " └─Projection_26 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", - " └─TableFullScan_25 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" + "Projection 10.00 root test.t1.id, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#7", + "└─TopN 10.00 root Column#10, offset:0, count:10", + " └─TableReader 10.00 root MppVersion: 3, data:ExchangeSender", + " └─ExchangeSender 10.00 mpp[tiflash] ExchangeType: PassThrough", + " └─TopN 10.00 mpp[tiflash] Column#10, offset:0, count:10", + " └─Projection 10.00 mpp[tiflash] test.t1.id, test.t1.vec, test.t1.a, test.t1.b, vec_cosine_distance(test.t1.vec, [1,1,1])->Column#10", + " └─TableFullScan 10.00 mpp[tiflash] table:t1, index:idx_embedding(vec) keep order:false, annIndex:COSINE(vec..[1,1,1], limit:10)" ], "Warn": null } From 27a2146eb8401748524078caec9e2d0093a1f1b9 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 16:53:09 +0800 Subject: [PATCH 29/31] update Signed-off-by: Weizhen Wang --- .../casetest/testdata/integration_suite_out.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/planner/core/casetest/testdata/integration_suite_out.json b/pkg/planner/core/casetest/testdata/integration_suite_out.json index f3428175e89ae..b5a8786148bda 100644 --- a/pkg/planner/core/casetest/testdata/integration_suite_out.json +++ b/pkg/planner/core/casetest/testdata/integration_suite_out.json @@ -66,19 +66,19 @@ { "SQL": "explain format = 'verbose' select * from t3 order by a limit 1", "Plan": [ - "TopN_8 1.00 53.10 root test.t3.a, offset:0, count:1", - "└─TableReader_17 1.00 49.90 root data:TopN_16", - " └─TopN_16 1.00 685.12 cop[tikv] test.t3.a, offset:0, count:1", - " └─TableFullScan_15 3.00 681.92 cop[tikv] table:t3 keep order:false" + "TopN_7 1.00 53.10 root test.t3.a, offset:0, count:1", + "└─TableReader_16 1.00 49.90 root data:TopN_15", + " └─TopN_15 1.00 685.12 cop[tikv] test.t3.a, offset:0, count:1", + " └─TableFullScan_14 3.00 681.92 cop[tikv] table:t3 keep order:false" ] }, { "SQL": "explain format = 'verbose' select * from t3 order by b limit 1", "Plan": [ - "TopN_8 1.00 53.10 root test.t3.b, offset:0, count:1", - "└─TableReader_17 1.00 49.90 root data:TopN_16", - " └─TopN_16 1.00 685.12 cop[tikv] test.t3.b, offset:0, count:1", - " └─TableFullScan_15 3.00 681.92 cop[tikv] table:t3 keep order:false" + "TopN_7 1.00 53.10 root test.t3.b, offset:0, count:1", + "└─TableReader_16 1.00 49.90 root data:TopN_15", + " └─TopN_15 1.00 685.12 cop[tikv] test.t3.b, offset:0, count:1", + " └─TableFullScan_14 3.00 681.92 cop[tikv] table:t3 keep order:false" ] }, { From 3cb18dd72a5d331a047fc51b55569f34cd10d96d Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 7 May 2025 17:13:35 +0800 Subject: [PATCH 30/31] update Signed-off-by: Weizhen Wang --- pkg/executor/testdata/prepare_suite_out.json | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/executor/testdata/prepare_suite_out.json b/pkg/executor/testdata/prepare_suite_out.json index ade15d5d3e615..69271a0bc6195 100644 --- a/pkg/executor/testdata/prepare_suite_out.json +++ b/pkg/executor/testdata/prepare_suite_out.json @@ -1173,10 +1173,10 @@ "6 6 6" ], "Plan": [ - "Limit_8 10.00 root offset:0, count:10", - "└─TableReader_12 10.00 root data:Limit_11", - " └─Limit_11 10.00 cop[tikv] offset:0, count:10", - " └─TableFullScan_10 10.00 cop[tikv] table:t keep order:false, stats:pseudo" + "Limit_7 10.00 root offset:0, count:10", + "└─TableReader_11 10.00 root data:Limit_10", + " └─Limit_10 10.00 cop[tikv] offset:0, count:10", + " └─TableFullScan_9 10.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, @@ -1190,10 +1190,10 @@ "6 6 6" ], "Plan": [ - "Limit_8 20.00 root offset:0, count:20", - "└─TableReader_12 20.00 root data:Limit_11", - " └─Limit_11 20.00 cop[tikv] offset:0, count:20", - " └─TableFullScan_10 20.00 cop[tikv] table:t keep order:false, stats:pseudo" + "Limit_7 20.00 root offset:0, count:20", + "└─TableReader_11 20.00 root data:Limit_10", + " └─Limit_10 20.00 cop[tikv] offset:0, count:20", + " └─TableFullScan_9 20.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, @@ -1207,10 +1207,10 @@ "1 1 1" ], "Plan": [ - "TopN_8 1.00 root test.t.b, offset:0, count:1", - "└─TableReader_15 1.00 root data:TopN_14", - " └─TopN_14 1.00 cop[tikv] test.t.b, offset:0, count:1", - " └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TopN_7 1.00 root test.t.b, offset:0, count:1", + "└─TableReader_14 1.00 root data:TopN_13", + " └─TopN_13 1.00 cop[tikv] test.t.b, offset:0, count:1", + " └─TableFullScan_12 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, @@ -1223,10 +1223,10 @@ "5 5 5" ], "Plan": [ - "TopN_8 5.00 root test.t.b, offset:0, count:5", - "└─TableReader_15 5.00 root data:TopN_14", - " └─TopN_14 5.00 cop[tikv] test.t.b, offset:0, count:5", - " └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TopN_7 5.00 root test.t.b, offset:0, count:5", + "└─TableReader_14 5.00 root data:TopN_13", + " └─TopN_13 5.00 cop[tikv] test.t.b, offset:0, count:5", + " └─TableFullScan_12 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "FromCache": "0" }, From ecb5e202a6405b41a616bdaf6d1e6acc31fc8381 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 8 May 2025 00:37:31 +0800 Subject: [PATCH 31/31] update Signed-off-by: Weizhen Wang --- .../testdata/ann_index_suite_in.json | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json index 3fd08fe7a0619..1f46b52b2ec2d 100644 --- a/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json +++ b/pkg/planner/core/casetest/vectorsearch/testdata/ann_index_suite_in.json @@ -49,13 +49,11 @@ "name": "TestVectorSearchWithPKAuto", "cases": [ "explain format = 'brief' select id from t1", - "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "explain format = 'brief' select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "explain format = 'brief' select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", "explain format = 'brief' select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", @@ -66,19 +64,17 @@ { "name": "TestVectorSearchWithPKForceTiKV", "cases": [ - "explain format = 'brief' select id from t1", - - "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", - "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain format = 'brief' select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - "explain format = 'brief' select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", - - "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", - "explain format = 'brief' select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", - "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", - "explain format = 'brief' select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10" + "explain format = 'brief' select id from t1", + "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id from t1 order by vec_cosine_distance(vec, '[1,1,1]')", + "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id, a, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select a, id, b from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d", + "explain format = 'brief' select *, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", + "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d, a, b from t1 order by d limit 10", + "explain format = 'brief' select id, a, b, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10" ] }, { @@ -91,7 +87,6 @@ "explain format = 'brief' select id from t1 order by vec_dims(vec) limit 10", "explain format = 'brief' select id from t1 order by vec_l2_norm(vec) limit 10", "explain format = 'brief' select id from t1 order by MOD(a, 3) limit 10", - "explain format = 'brief' select id, vec_cosine_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "explain format = 'brief' select id, vec_l1_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", "explain format = 'brief' select id, vec_l2_distance(vec, '[1,1,1]') as d from t1 order by d limit 10", @@ -99,7 +94,6 @@ "explain format = 'brief' select id, vec_dims(vec) as d from t1 order by d limit 10", "explain format = 'brief' select id, vec_l2_norm(vec) as d from t1 order by d limit 10", "explain format = 'brief' select id, MOD(a, 3) as d from t1 order by d limit 10", - "explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '[1,1,1]') limit 10", "explain format = 'brief' select * from t1 order by vec_l1_distance(vec, '[1,1,1]') limit 10", "explain format = 'brief' select * from t1 order by vec_l2_distance(vec, '[1,1,1]') limit 10",