From 790c819a8f57993e5e27bb213a30f79903c00786 Mon Sep 17 00:00:00 2001 From: tangenta Date: Thu, 11 Mar 2021 21:39:51 +0800 Subject: [PATCH 01/16] *: deprecate alter-primary-key configuration --- config/config.go | 4 +- config/config.toml.example | 5 - config/config_test.go | 2 - ddl/db_change_test.go | 16 +- ddl/db_integration_test.go | 32 ++-- ddl/db_test.go | 48 ++---- ddl/ddl_api.go | 72 ++++----- ddl/ddl_test.go | 2 - ddl/serial_test.go | 203 +++++++++++--------------- executor/ddl_test.go | 30 ++-- executor/insert_test.go | 24 +-- executor/seqtest/seq_executor_test.go | 16 +- executor/show_test.go | 6 +- go.mod | 2 + go.sum | 2 + infoschema/tables_test.go | 7 +- meta/autoid/errors.go | 4 +- session/clustered_index_test.go | 58 +++----- util/testutil/testutil.go | 29 +--- 19 files changed, 206 insertions(+), 356 deletions(-) diff --git a/config/config.go b/config/config.go index a6ba012727b28..6b93e2b40d4bf 100644 --- a/config/config.go +++ b/config/config.go @@ -125,8 +125,6 @@ type Config struct { IndexLimit int `toml:"index-limit" json:"index-limit"` TableColumnCountLimit uint32 `toml:"table-column-count-limit" json:"table-column-count-limit"` GracefulWaitBeforeShutdown int `toml:"graceful-wait-before-shutdown" json:"graceful-wait-before-shutdown"` - // AlterPrimaryKey is used to control alter primary key feature. - AlterPrimaryKey bool `toml:"alter-primary-key" json:"alter-primary-key"` // TreatOldVersionUTF8AsUTF8MB4 is use to treat old version table/column UTF8 charset as UTF8MB4. This is for compatibility. // Currently not support dynamic modify, because this need to reload all old version schema. TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"` @@ -554,7 +552,6 @@ var defaultConf = Config{ MaxIndexLength: 3072, IndexLimit: 64, TableColumnCountLimit: 1017, - AlterPrimaryKey: false, TreatOldVersionUTF8AsUTF8MB4: true, EnableTableLock: false, DelayCleanTableLock: 0, @@ -700,6 +697,7 @@ var deprecatedConfig = map[string]struct{}{ "experimental.allow-auto-random": {}, "enable-redact-log": {}, // use variable tidb_redact_log instead "tikv-client.copr-cache.enable": {}, + "alter-primary-key": {}, // use NONCLUSTERED keyword instead } func isAllDeprecatedConfigItems(items []string) bool { diff --git a/config/config.toml.example b/config/config.toml.example index 60e86c847f205..227836889f597 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -86,11 +86,6 @@ delay-clean-table-lock = 0 # Maximum number of the splitting region, which is used by the split region statement. split-region-max-num = 1000 -# alter-primary-key is used to control alter primary key feature. Default is false, indicate the alter primary key feature is disabled. -# If it is true, we can add the primary key by "alter table". However, if a table already exists before the switch is turned true and the data type of its primary key column is an integer, -# the primary key cannot be dropped. -alter-primary-key = false - # server-version is used to change the version string of TiDB in the following scenarios: # 1. the server version returned by builtin-function `VERSION()`. # 2. the server version filled in handshake packets of MySQL Connection Protocol, see https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake for more details. diff --git a/config/config_test.go b/config/config_test.go index 59dfcffb24a6f..ba734dce06dae 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -184,7 +184,6 @@ unrecognized-option-test = true _, err = f.WriteString(` token-limit = 0 enable-table-lock = true -alter-primary-key = true delay-clean-table-lock = 5 split-region-max-num=10000 enable-batch-dml = true @@ -242,7 +241,6 @@ spilled-file-encryption-method = "plaintext" // Test that the value will be overwritten by the config file. c.Assert(conf.Performance.TxnTotalSizeLimit, Equals, uint64(2000)) - c.Assert(conf.AlterPrimaryKey, Equals, true) c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s") c.Assert(conf.TiKVClient.AsyncCommit.KeysLimit, Equals, uint(123)) diff --git a/ddl/db_change_test.go b/ddl/db_change_test.go index a7cbdc050c92b..b303a160b2962 100644 --- a/ddl/db_change_test.go +++ b/ddl/db_change_test.go @@ -580,16 +580,11 @@ func (s *serialTestStateChangeSuite) TestWriteReorgForModifyColumnWithPKIsHandle s.se.GetSessionVars().EnableChangeColumnType = true defer func() { s.se.GetSessionVars().EnableChangeColumnType = enableChangeColumnType - config.RestoreFunc()() }() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) - _, err := s.se.Execute(context.Background(), "use test_db_state") c.Assert(err, IsNil) - _, err = s.se.Execute(context.Background(), `create table tt (a int not null, b int default 1, c int not null default 0, unique index idx(c), primary key idx1(a), index idx2(a, c))`) + _, err = s.se.Execute(context.Background(), `create table tt (a int not null, b int default 1, c int not null default 0, unique index idx(c), primary key idx1(a) clustered, index idx2(a, c))`) c.Assert(err, IsNil) _, err = s.se.Execute(context.Background(), "insert into tt (a, c) values(-1, -11)") c.Assert(err, IsNil) @@ -1018,12 +1013,7 @@ func (s *testStateChangeSuite) TestParallelAlterModifyColumn(c *C) { s.testControlParallelExecSQL(c, sql, sql, f) } -func (s *serialTestStateChangeSuite) TestParallelAlterModifyColumnAndAddPK(c *C) { - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = true - }) - +func (s *testStateChangeSuite) TestParallelAlterModifyColumnAndAddPK(c *C) { _, err := s.se.Execute(context.Background(), "set global tidb_enable_change_column_type = 1") c.Assert(err, IsNil) defer func() { @@ -1032,7 +1022,7 @@ func (s *serialTestStateChangeSuite) TestParallelAlterModifyColumnAndAddPK(c *C) }() domain.GetDomain(s.se).GetGlobalVarsCache().Disable() - sql1 := "ALTER TABLE t ADD PRIMARY KEY (b);" + sql1 := "ALTER TABLE t ADD PRIMARY KEY (b) NONCLUSTERED;" sql2 := "ALTER TABLE t MODIFY COLUMN b tinyint;" f := func(c *C, err1, err2 error) { c.Assert(err1, IsNil) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 8aa31771e7f8f..7e27382395dd3 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -127,6 +127,7 @@ type testIntegrationSuite5 struct{ *testIntegrationSuite } type testIntegrationSuite6 struct{ *testIntegrationSuite } type testIntegrationSuite7 struct{ *testIntegrationSuite } type testIntegrationSuite8 struct{ *testIntegrationSuite } +type testIntegrationSuite9 struct{ *testIntegrationSuite } func (s *testIntegrationSuite5) TestNoZeroDateMode(c *C) { tk := testkit.NewTestKit(c, s.store) @@ -1262,7 +1263,7 @@ func (s *testIntegrationSuite3) TestMultiRegionGetTableEndHandle(c *C) { tk.MustExec("create database test_get_endhandle") tk.MustExec("use test_get_endhandle") - tk.MustExec("create table t(a bigint PRIMARY KEY, b int)") + tk.MustExec("create table t(a bigint PRIMARY KEY nonclustered, b int)") for i := 0; i < 1000; i++ { tk.MustExec(fmt.Sprintf("insert into t values(%v, %v)", i, i)) } @@ -1572,7 +1573,7 @@ func (s *testIntegrationSuite3) TestAlterColumn(c *C) { // The followings tests whether adding constraints via change / modify column // is forbidden as expected. tk.MustExec("drop table if exists mc") - tk.MustExec("create table mc(a int key, b int, c int)") + tk.MustExec("create table mc(a int key nonclustered, b int, c int)") _, err = tk.Exec("alter table mc modify column a int key") // Adds a new primary key c.Assert(err, NotNil) _, err = tk.Exec("alter table mc modify column c int unique") // Adds a new unique key @@ -1584,7 +1585,7 @@ func (s *testIntegrationSuite3) TestAlterColumn(c *C) { // Change / modify column should preserve index options. tk.MustExec("drop table if exists mc") - tk.MustExec("create table mc(a int key, b int, c int unique)") + tk.MustExec("create table mc(a int key nonclustered, b int, c int unique)") tk.MustExec("alter table mc modify column a bigint") // NOT NULL & PRIMARY KEY should be preserved tk.MustExec("alter table mc modify column b bigint") tk.MustExec("alter table mc modify column c bigint") // Unique should be preserved @@ -1595,7 +1596,7 @@ func (s *testIntegrationSuite3) TestAlterColumn(c *C) { // Dropping or keeping auto_increment is allowed, however adding is not allowed. tk.MustExec("drop table if exists mc") - tk.MustExec("create table mc(a int key auto_increment, b int)") + tk.MustExec("create table mc(a int key nonclustered auto_increment, b int)") tk.MustExec("alter table mc modify column a bigint auto_increment") // Keeps auto_increment result = tk.MustQuery("show create table mc") createSQL = result.Rows()[0][1] @@ -2228,19 +2229,18 @@ func (s *testIntegrationSuite7) TestCreateExpressionIndexError(c *C) { defer config.RestoreFunc()() config.UpdateGlobal(func(conf *config.Config) { conf.Experimental.AllowsExpressionIndex = true - conf.AlterPrimaryKey = true }) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists t;") tk.MustExec("create table t (a int, b real);") - tk.MustGetErrCode("alter table t add primary key ((a+b));", errno.ErrFunctionalIndexPrimaryKey) + tk.MustGetErrCode("alter table t add primary key ((a+b)) nonclustered;", errno.ErrFunctionalIndexPrimaryKey) // Test for error tk.MustExec("drop table if exists t;") tk.MustExec("create table t (a int, b real);") - tk.MustGetErrCode("alter table t add primary key ((a+b));", errno.ErrFunctionalIndexPrimaryKey) + tk.MustGetErrCode("alter table t add primary key ((a+b)) nonclustered;", errno.ErrFunctionalIndexPrimaryKey) tk.MustGetErrCode("alter table t add index ((rand()));", errno.ErrFunctionalIndexFunctionIsNotAllowed) tk.MustGetErrCode("alter table t add index ((now()+1));", errno.ErrFunctionalIndexFunctionIsNotAllowed) @@ -2265,7 +2265,7 @@ func (s *testIntegrationSuite7) TestCreateExpressionIndexError(c *C) { tk.MustExec("create table t (j json, key k ((j+1),(j+1)))") tk.MustGetErrCode("create table t1 (col1 int, index ((concat(''))));", errno.ErrWrongKeyColumnFunctionalIndex) - tk.MustGetErrCode("CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))));", errno.ErrFunctionalIndexPrimaryKey) + tk.MustGetErrCode("CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);", errno.ErrFunctionalIndexPrimaryKey) } func (s *testIntegrationSuite7) TestAddExpressionIndexOnPartition(c *C) { @@ -2307,7 +2307,7 @@ func (s *testIntegrationSuite3) TestCreateTableWithAutoIdCache(c *C) { tk.MustExec("drop table if exists t1;") // Test primary key is handle. - tk.MustExec("create table t(a int auto_increment key) auto_id_cache 100") + tk.MustExec("create table t(a int auto_increment key clustered) auto_id_cache 100") tblInfo, err := s.dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) c.Assert(tblInfo.Meta().AutoIdCache, Equals, int64(100)) @@ -2371,13 +2371,15 @@ func (s *testIntegrationSuite3) TestCreateTableWithAutoIdCache(c *C) { tk.MustExec("drop table if exists t;") tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(a int auto_increment key) auto_id_cache 3") + tk.MustExec("create table t(a int auto_increment key clustered) auto_id_cache 3") tblInfo, err = s.dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) c.Assert(err, IsNil) c.Assert(tblInfo.Meta().AutoIdCache, Equals, int64(3)) // Test insert batch size(4 here) greater than the customized autoid step(3 here). - tk.MustExec("insert into t(a) values(NULL),(NULL),(NULL),(NULL)") + tk.MustExec("insert into t(a) values(NULL),(NULL),(NULL)") + // Cache 3 more values. We can't merge this two lines because the batch allocation overrides autoid step. + tk.MustExec("insert into t(a) values(NULL)") tk.MustQuery("select a from t").Check(testkit.Rows("1", "2", "3", "4")) tk.MustExec("delete from t") @@ -2522,17 +2524,12 @@ func (s *testIntegrationSuite5) TestDropLastVisibleColumns(c *C) { func (s *testIntegrationSuite7) TestAutoIncrementTableOption(c *C) { tk := testkit.NewTestKit(c, s.store) - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - // Make sure the integer primary key is the handle(PkIsHandle). - conf.AlterPrimaryKey = false - }) tk.MustExec("drop database if exists test_auto_inc_table_opt;") tk.MustExec("create database test_auto_inc_table_opt;") tk.MustExec("use test_auto_inc_table_opt;") // Empty auto_inc allocator should not cause error. - tk.MustExec("create table t (a bigint primary key) auto_increment = 10;") + tk.MustExec("create table t (a bigint primary key clustered) auto_increment = 10;") tk.MustExec("alter table t auto_increment = 10;") tk.MustExec("alter table t auto_increment = 12345678901234567890;") @@ -2640,7 +2637,6 @@ func (s *testIntegrationSuite7) TestDuplicateErrorMessage(c *C) { restoreConfig := config.RestoreFunc() config.UpdateGlobal(func(conf *config.Config) { conf.EnableGlobalIndex = globalIndex - conf.AlterPrimaryKey = false }) for _, clusteredIndex := range []bool{false, true} { tk.Se.GetSessionVars().EnableClusteredIndex = clusteredIndex diff --git a/ddl/db_test.go b/ddl/db_test.go index 1f83765a48b47..e18b7d06efc45 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -146,7 +146,7 @@ type testDBSuite6 struct{ *testDBSuite } type testDBSuite7 struct{ *testDBSuite } type testSerialDBSuite struct{ *testDBSuite } -func testAddIndexWithPK(tk *testkit.TestKit, s *testSerialDBSuite, c *C) { +func testAddIndexWithPK(tk *testkit.TestKit) { tk.MustExec("drop table if exists test_add_index_with_pk") tk.MustExec("create table test_add_index_with_pk(a int not null, b int not null default '0', primary key(a))") tk.MustExec("insert into test_add_index_with_pk values(1, 2)") @@ -173,17 +173,13 @@ func testAddIndexWithPK(tk *testkit.TestKit, s *testSerialDBSuite, c *C) { tk.MustExec("create index idx on t (a, b);") } -func (s *testSerialDBSuite) TestAddIndexWithPK(c *C) { +func (s *testDBSuite7) TestAddIndexWithPK(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use " + s.schemaName) - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) - testAddIndexWithPK(tk, s, c) + testAddIndexWithPK(tk) tk.Se.GetSessionVars().EnableClusteredIndex = true - testAddIndexWithPK(tk, s, c) + testAddIndexWithPK(tk) } func (s *testDBSuite5) TestAddIndexWithDupIndex(c *C) { @@ -1140,11 +1136,7 @@ func (s *testDBSuite4) TestAddIndex4(c *C) { partition p4 values less than maxvalue)`, "") } -func (s *testSerialDBSuite) TestAddIndex5(c *C) { - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) +func (s *testDBSuite5) TestAddIndex5(c *C) { testAddIndex(c, s.store, s.lease, testClusteredIndex, `create table test_add_index (c1 bigint, c2 bigint, c3 bigint, primary key(c2, c3))`, "") } @@ -1414,7 +1406,7 @@ func (s *testDBSuite1) TestCancelAddTableAndDropTablePartition(c *C) { func (s *testDBSuite1) TestDropPrimaryKey(c *C) { idxName := "primary" - createSQL := "create table test_drop_index (c1 int, c2 int, c3 int, unique key(c1), primary key(c3))" + createSQL := "create table test_drop_index (c1 int, c2 int, c3 int, unique key(c1), primary key(c3) nonclustered)" dropIdxSQL := "alter table test_drop_index drop primary key;" testDropIndex(c, s.store, s.lease, createSQL, dropIdxSQL, idxName) } @@ -1435,7 +1427,7 @@ func testDropIndex(c *C, store kv.Storage, lease time.Duration, createSQL, dropI tk.MustExec("delete from test_drop_index") num := 100 - // add some rows + // add some rows for i := 0; i < num; i++ { tk.MustExec("insert into test_drop_index values (?, ?, ?)", i, i, i) } @@ -1953,7 +1945,6 @@ func (s *testSerialDBSuite) TestAddGlobalIndex(c *C) { defer config.RestoreFunc()() config.UpdateGlobal(func(conf *config.Config) { conf.EnableGlobalIndex = true - conf.AlterPrimaryKey = true }) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test_db") @@ -1994,7 +1985,7 @@ func (s *testSerialDBSuite) TestAddGlobalIndex(c *C) { " (partition p0 values less than (10), " + " partition p1 values less than (maxvalue));") tk.MustExec("insert test_t2 values (1, 1)") - tk.MustExec("alter table test_t2 add primary key (a);") + tk.MustExec("alter table test_t2 add primary key (a) nonclustered;") tk.MustExec("insert test_t2 values (2, 11)") t = s.testGetTable(c, "test_t2") tblInfo = t.Meta() @@ -2432,6 +2423,7 @@ func (s *testDBSuite7) TestSelectInViewFromAnotherDB(c *C) { _, _ = s.s.Execute(context.Background(), "create database test_db2") tk := testkit.NewTestKit(c, s.store) tk.MustExec("use " + s.schemaName) + tk.MustExec("drop table t if exists t;") tk.MustExec("create table t(a int)") tk.MustExec("use test_db2") tk.MustExec("create sql security invoker view v as select * from " + s.schemaName + ".t") @@ -2672,16 +2664,12 @@ func (s *testSerialDBSuite) TestRepairTable(c *C) { defer func() { c.Assert(failpoint.Disable("github.com/pingcap/tidb/infoschema/repairFetchCreateTable"), IsNil) }() - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = true - }) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists t, other_table, origin") // Test repair table when TiDB is not in repair mode. - tk.MustExec("CREATE TABLE t (a int primary key, b varchar(10));") + tk.MustExec("CREATE TABLE t (a int primary key nonclustered, b varchar(10));") _, err := tk.Exec("admin repair table t CREATE TABLE t (a float primary key, b varchar(5));") c.Assert(err, NotNil) c.Assert(err.Error(), Equals, "[ddl:8215]Failed to repair table: TiDB is not in REPAIR MODE") @@ -2757,7 +2745,7 @@ func (s *testSerialDBSuite) TestRepairTable(c *C) { turnRepairModeAndInit(true) defer turnRepairModeAndInit(false) // Domain reload the tableInfo and add it into repairInfo. - tk.MustExec("CREATE TABLE origin (a int primary key auto_increment, b varchar(10), c int);") + tk.MustExec("CREATE TABLE origin (a int primary key nonclustered auto_increment, b varchar(10), c int);") // Repaired tableInfo has been filtered by `domain.InfoSchema()`, so get it in repairInfo. originTableInfo, _ := domainutil.RepairInfo.GetRepairedTableInfoByTableName("test", "origin") @@ -2788,7 +2776,7 @@ func (s *testSerialDBSuite) TestRepairTable(c *C) { s.dom.DDL().(ddl.DDLForTest).SetHook(hook) // Exec the repair statement to override the tableInfo. - tk.MustExec("admin repair table origin CREATE TABLE origin (a int primary key auto_increment, b varchar(5), c int);") + tk.MustExec("admin repair table origin CREATE TABLE origin (a int primary key nonclustered auto_increment, b varchar(5), c int);") c.Assert(repairErr, IsNil) // Check the repaired tableInfo is exactly the same with old one in tableID, indexID, colID. @@ -4501,7 +4489,7 @@ func (s *testDBSuite4) TestIfExists(c *C) { tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Note|1507|Error in list of partitions to p1")) } -func testAddIndexForGeneratedColumn(tk *testkit.TestKit, s *testSerialDBSuite, c *C) { +func testAddIndexForGeneratedColumn(tk *testkit.TestKit, s *testDBSuite5, c *C) { tk.MustExec("use test_db") tk.MustExec("drop table if exists t") tk.MustExec("create table t(y year NOT NULL DEFAULT '2155')") @@ -4541,15 +4529,9 @@ func testAddIndexForGeneratedColumn(tk *testkit.TestKit, s *testSerialDBSuite, c tk.MustQuery("select id1 from gcai_table use index(idx1)").Check(testkit.Rows("6")) tk.MustExec("admin check table gcai_table") } -func (s *testSerialDBSuite) TestAddIndexForGeneratedColumn(c *C) { - tk := testkit.NewTestKit(c, s.store) - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) - testAddIndexForGeneratedColumn(tk, s, c) - tk.Se.GetSessionVars().EnableClusteredIndex = true +func (s *testDBSuite5) TestAddIndexForGeneratedColumn(c *C) { + tk := testkit.NewTestKit(c, s.store) testAddIndexForGeneratedColumn(tk, s, c) } diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 5dfd135bcddec..9553379a1c218 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -1425,36 +1425,13 @@ func buildTableInfo( if err != nil { return nil, err } - pkTp := model.PrimaryKeyTypeDefault - if constr.Option != nil { - pkTp = constr.Option.PrimaryKeyTp - } - noBinlog := ctx.GetSessionVars().BinlogClient == nil - switch pkTp { - case model.PrimaryKeyTypeNonClustered: - break - case model.PrimaryKeyTypeClustered: - if isSingleIntPK(constr, lastCol) { + isIntPK := isSingleIntPK(constr, lastCol) + if ShouldBuildClusteredIndex(ctx, constr.Option, isIntPK) { + if isIntPK { tbInfo.PKIsHandle = true } else { - tbInfo.IsCommonHandle = noBinlog - if tbInfo.IsCommonHandle { - tbInfo.CommonHandleVersion = 1 - } - if !noBinlog { - errMsg := "cannot build clustered index table because the binlog is ON" - ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf(errMsg)) - } - } - case model.PrimaryKeyTypeDefault: - alterPKConf := config.GetGlobalConfig().AlterPrimaryKey - if isSingleIntPK(constr, lastCol) { - tbInfo.PKIsHandle = !alterPKConf - } else { - tbInfo.IsCommonHandle = !alterPKConf && ctx.GetSessionVars().EnableClusteredIndex && noBinlog - if tbInfo.IsCommonHandle { - tbInfo.CommonHandleVersion = 1 - } + tbInfo.IsCommonHandle = true + tbInfo.CommonHandleVersion = 1 } } if tbInfo.PKIsHandle || tbInfo.IsCommonHandle { @@ -1530,6 +1507,34 @@ func isSingleIntPK(constr *ast.Constraint, lastCol *model.ColumnInfo) bool { return false } +// ShouldBuildClusteredIndex is used to determine whether the CREATE TABLE statement should build a clustered index table. +func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption, isIntPK bool) bool { + if opt == nil || opt.PrimaryKeyTp == model.PrimaryKeyTypeDefault { + if isIntPK { + return true + } + return ctx.GetSessionVars().EnableClusteredIndex + } + switch opt.PrimaryKeyTp { + case model.PrimaryKeyTypeClustered: + if isIntPK { + return true + } + hasBinlog := ctx.GetSessionVars().BinlogClient != nil + if hasBinlog { + errMsg := "cannot build clustered index table because the binlog is ON" + ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf(errMsg)) + return false + } + return true + case model.PrimaryKeyTypeNonClustered: + return false + default: // should never reach here + logutil.BgLogger().Error("Unknown primary key type") + return false + } +} + // checkTableInfoValidExtra is like checkTableInfoValid, but also assumes the // table info comes from untrusted source and performs further checks such as // name length and column count. @@ -4754,11 +4759,10 @@ func getAnonymousIndex(t table.Table, colName model.CIStr, idxName model.CIStr) func (d *ddl) CreatePrimaryKey(ctx sessionctx.Context, ti ast.Ident, indexName model.CIStr, indexPartSpecifications []*ast.IndexPartSpecification, indexOption *ast.IndexOption) error { - if !config.GetGlobalConfig().AlterPrimaryKey { - return ErrUnsupportedModifyPrimaryKey.GenWithStack("Unsupported add primary key, alter-primary-key is false. " + - "Please check the documentation for the tidb-server configuration files") + if indexOption != nil && indexOption.PrimaryKeyTp == model.PrimaryKeyTypeClustered { + return ErrUnsupportedModifyPrimaryKey.GenWithStack("Adding clustered primary key is not supported. " + + "Please consider adding NONCLUSTERED primary key instead") } - schema, t, err := d.getSchemaAndTableByIdent(ctx, ti) if err != nil { return errors.Trace(err) @@ -5168,10 +5172,6 @@ func (d *ddl) DropIndex(ctx sessionctx.Context, ti ast.Ident, indexName model.CI isPK = true } if isPK { - if !config.GetGlobalConfig().AlterPrimaryKey { - return ErrUnsupportedModifyPrimaryKey.GenWithStack("Unsupported drop primary key when alter-primary-key is false") - - } // If the table's PKIsHandle is true, we can't find the index from the table. So we check the value of PKIsHandle. if indexInfo == nil && !t.Meta().PKIsHandle { return ErrCantDropFieldOrKey.GenWithStack("Can't DROP 'PRIMARY'; check that column/key exists") diff --git a/ddl/ddl_test.go b/ddl/ddl_test.go index a2bca47ee382e..90a8a091fe3c8 100644 --- a/ddl/ddl_test.go +++ b/ddl/ddl_test.go @@ -79,8 +79,6 @@ func TestT(t *testing.T) { // Test for table lock. conf.EnableTableLock = true conf.Log.SlowThreshold = 10000 - // Test for add/drop primary key. - conf.AlterPrimaryKey = true conf.TiKVClient.AsyncCommit.SafeWindow = 0 conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0 }) diff --git a/ddl/serial_test.go b/ddl/serial_test.go index e5d84c90776a9..43b4773cadc85 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -53,6 +53,9 @@ import ( // Make it serial because config is modified in test cases. var _ = SerialSuites(&testSerialSuite{}) +// TODO(tangenta): Move all the parallel tests out of this file. +var _ = Suite(&testIntegrationSuite9{&testIntegrationSuite{}}) + type testSerialSuite struct { CommonHandleSuite store kv.Storage @@ -64,8 +67,7 @@ func (s *testSerialSuite) SetUpSuite(c *C) { session.SetSchemaLease(200 * time.Millisecond) session.DisableStats4Test() config.UpdateGlobal(func(conf *config.Config) { - // Test for add/drop primary key. - conf.AlterPrimaryKey = false + // Update config here. }) ddl.SetWaitTimeWhenErrorOccurred(1 * time.Microsecond) @@ -110,81 +112,72 @@ func (s *testSerialSuite) TestChangeMaxIndexLength(c *C) { tk.MustExec("drop table t, t1") } -func (s *testSerialSuite) TestPrimaryKey(c *C) { +func (s *testIntegrationSuite9) TestPrimaryKey(c *C) { tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") + tk.MustExec("drop database if exists test_primary_key;") + tk.MustExec("create database test_primary_key;") + tk.MustExec("use test_primary_key;") tk.Se.GetSessionVars().EnableClusteredIndex = false - tk.MustExec("create table primary_key_test (a int, b varchar(10))") - tk.MustExec("create table primary_key_test_1 (a int, b varchar(10), primary key(a))") - _, err := tk.Exec("alter table primary_key_test add primary key(a)") - c.Assert(ddl.ErrUnsupportedModifyPrimaryKey.Equal(err), IsTrue) - _, err = tk.Exec("alter table primary_key_test drop primary key") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported drop primary key when alter-primary-key is false") - // for "drop index `primary` on ..." syntax - _, err = tk.Exec("drop index `primary` on primary_key_test") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported drop primary key when alter-primary-key is false") - _, err = tk.Exec("drop index `primary` on primary_key_test_1") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported drop primary key when alter-primary-key is false") - - // Change the value of AlterPrimaryKey. - tk.MustExec("create table primary_key_test1 (a int, b varchar(10), primary key(a))") - tk.MustExec("create table primary_key_test2 (a int, b varchar(10), primary key(b))") - tk.MustExec("create table primary_key_test3 (a int, b varchar(10))") - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = true - }) - - _, err = tk.Exec("alter table primary_key_test2 add primary key(a)") - c.Assert(infoschema.ErrMultiplePriKey.Equal(err), IsTrue) - // We can't add a primary key when the table's pk_is_handle is true. - _, err = tk.Exec("alter table primary_key_test1 add primary key(a)") - c.Assert(infoschema.ErrMultiplePriKey.Equal(err), IsTrue) - _, err = tk.Exec("alter table primary_key_test1 add primary key(b)") - c.Assert(infoschema.ErrMultiplePriKey.Equal(err), IsTrue) - - _, err = tk.Exec("alter table primary_key_test1 drop primary key") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported drop primary key when the table's pkIsHandle is true") - tk.MustExec("alter table primary_key_test2 drop primary key") - _, err = tk.Exec("alter table primary_key_test3 drop primary key") - c.Assert(err.Error(), Equals, "[ddl:1091]Can't DROP 'PRIMARY'; check that column/key exists") - - // for "drop index `primary` on ..." syntax - tk.MustExec("create table primary_key_test4 (a int, b varchar(10), primary key(a))") - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) - _, err = tk.Exec("drop index `primary` on primary_key_test4") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported drop primary key when alter-primary-key is false") - // for the index name is `primary` - tk.MustExec("create table tt(`primary` int);") - tk.MustExec("alter table tt add index (`primary`);") - _, err = tk.Exec("drop index `primary` on tt") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported drop primary key when alter-primary-key is false") + // Test add/drop primary key on a plain table. + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t (a int, b varchar(10));") + tk.MustGetErrCode("alter table t add primary key(a) clustered;", errno.ErrUnsupportedDDLOperation) + tk.MustExec("alter table t add primary key(a) nonclustered;") + tk.MustExec("alter table t drop primary key;") + tk.MustExec("alter table t add primary key(a) nonclustered;") + tk.MustExec("drop index `primary` on t;") + tk.MustExec("alter table t add primary key(a);") // implicit nonclustered + tk.MustExec("drop index `primary` on t;") + tk.MustGetErrCode("drop index `primary` on t;", errno.ErrCantDropFieldOrKey) + + // Test add/drop primary key on a PKIsHandle table. + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t (a int, b varchar(10), primary key(a) clustered);") + tk.MustGetErrCode("alter table t drop primary key;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(a) clustered;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(a) nonclustered;", mysql.ErrMultiplePriKey) + tk.MustGetErrCode("alter table t add primary key(a);", errno.ErrMultiplePriKey) // implicit nonclustered + tk.MustGetErrCode("alter table t add primary key(b) clustered;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(b) nonclustered;", errno.ErrMultiplePriKey) + tk.MustGetErrCode("alter table t add primary key(b);", errno.ErrMultiplePriKey) // implicit nonclustered + + // Test add/drop primary key on a nonclustered primary key table. + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t (a int, b varchar(10), primary key(a) nonclustered);") + tk.MustGetErrCode("alter table t add primary key(a) clustered;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(a) nonclustered;", errno.ErrMultiplePriKey) + tk.MustGetErrCode("alter table t add primary key(a);", errno.ErrMultiplePriKey) // implicit nonclustered + tk.MustGetErrCode("alter table t add primary key(b) clustered;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(b) nonclustered;", errno.ErrMultiplePriKey) + tk.MustGetErrCode("alter table t add primary key(b);", errno.ErrMultiplePriKey) // implicit nonclustered + tk.MustExec("alter table t drop primary key;") + + // Test add/drop primary key on a CommonHandle key table. + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t (a int, b varchar(10), primary key(b) clustered);") + tk.MustGetErrCode("alter table t drop primary key;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(a) clustered;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(a) nonclustered;", errno.ErrMultiplePriKey) + tk.MustGetErrCode("alter table t add primary key(a);", errno.ErrMultiplePriKey) // implicit nonclustered + tk.MustGetErrCode("alter table t add primary key(b) clustered;", errno.ErrUnsupportedDDLOperation) + tk.MustGetErrCode("alter table t add primary key(b) nonclustered;", errno.ErrMultiplePriKey) + tk.MustGetErrCode("alter table t add primary key(b);", errno.ErrMultiplePriKey) // implicit nonclustered + + // Test add/drop primary key when the column&index name is `primary`. + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t (`primary` int);") + tk.MustExec("alter table t add index (`primary`);") + tk.MustGetErrCode("drop index `primary` on t;", errno.ErrCantDropFieldOrKey) // The primary key cannot be invisible, for the case pk_is_handle. - tk.MustExec("drop table if exists t1, t2;") - _, err = tk.Exec("create table t1(c1 int not null, primary key(c1) invisible);") - c.Assert(ddl.ErrPKIndexCantBeInvisible.Equal(err), IsTrue) - tk.MustExec("create table t2 (a int, b int not null, primary key(a), unique(b) invisible);") - - // Test drop clustered primary key. - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) tk.MustExec("drop table if exists t;") - tk.Se.GetSessionVars().EnableClusteredIndex = true - tk.MustExec("create table t(a int, b varchar(64), primary key(b));") - tk.MustExec("insert into t values(1,'a'), (2, 'b');") - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = true - }) - errMsg := "[ddl:8200]Unsupported drop primary key when the table is using clustered index" - tk.MustGetErrMsg("alter table t drop primary key;", errMsg) + tk.MustGetErrCode("create table t(c1 int not null, primary key(c1) invisible);", errno.ErrPKIndexCantBeInvisible) + tk.MustExec("create table t (a int, b int not null, primary key(a), unique(b) invisible);") + tk.MustExec("drop table t;") } -func (s *testSerialSuite) TestDropAutoIncrementIndex(c *C) { +func (s *testIntegrationSuite9) TestDropAutoIncrementIndex(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists t1") @@ -192,7 +185,7 @@ func (s *testSerialSuite) TestDropAutoIncrementIndex(c *C) { tk.MustExec("alter table t1 drop index a") } -func (s *testSerialSuite) TestMultiRegionGetTableEndHandle(c *C) { +func (s *testIntegrationSuite9) TestMultiRegionGetTableEndHandle(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("drop database if exists test_get_endhandle") tk.MustExec("create database test_get_endhandle") @@ -235,7 +228,7 @@ func (s *testSerialSuite) TestMultiRegionGetTableEndHandle(c *C) { c.Assert(maxHandle, Equals, kv.IntHandle(10000)) } -func (s *testSerialSuite) TestGetTableEndHandle(c *C) { +func (s *testIntegrationSuite9) TestGetTableEndHandle(c *C) { // TestGetTableEndHandle test ddl.GetTableMaxHandle method, which will return the max row id of the table. tk := testkit.NewTestKit(c, s.store) tk.MustExec("drop database if exists test_get_endhandle") @@ -327,7 +320,7 @@ func (s *testSerialSuite) TestGetTableEndHandle(c *C) { c.Assert(emptyTable, IsFalse) } -func (s *testSerialSuite) TestMultiRegionGetTableEndCommonHandle(c *C) { +func (s *testIntegrationSuite9) TestMultiRegionGetTableEndCommonHandle(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("drop database if exists test_get_endhandle") tk.MustExec("create database test_get_endhandle") @@ -371,7 +364,7 @@ func (s *testSerialSuite) TestMultiRegionGetTableEndCommonHandle(c *C) { c.Assert(maxHandle, HandleEquals, MustNewCommonHandle(c, "a", 1, 1)) } -func (s *testSerialSuite) TestGetTableEndCommonHandle(c *C) { +func (s *testIntegrationSuite9) TestGetTableEndCommonHandle(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("drop database if exists test_get_endhandle") tk.MustExec("create database test_get_endhandle") @@ -987,9 +980,6 @@ func (s *testSerialSuite) TestAutoRandom(c *C) { tk.MustExec("drop table t") } - ConfigTestUtils.SetupAutoRandomTestConfig() - defer ConfigTestUtils.RestoreAutoRandomTestConfig() - // Only bigint column can set auto_random assertBigIntOnly("create table t (a char primary key auto_random(3), b int)", "char") assertBigIntOnly("create table t (a varchar(255) primary key auto_random(3), b int)", "varchar") @@ -1006,16 +996,10 @@ func (s *testSerialSuite) TestAutoRandom(c *C) { assertPKIsNotHandle("create table t (a bigint auto_random(3), b bigint, primary key (a, b))", "a") assertPKIsNotHandle("create table t (a bigint auto_random(3), b int, c char, primary key (a, c))", "a") - // PKIsNotHandle: table is created when alter-primary-key = true. - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = true - }) - assertPKIsNotHandle("create table t (a bigint auto_random(3) primary key, b int)", "a") - assertPKIsNotHandle("create table t (a bigint auto_random(3) primary key, b int)", "a") - assertPKIsNotHandle("create table t (a int, b bigint auto_random(3) primary key)", "b") - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) + // PKIsNotHandle: nonclustered integer primary key. + assertPKIsNotHandle("create table t (a bigint auto_random(3) primary key nonclustered, b int)", "a") + assertPKIsNotHandle("create table t (a bigint auto_random(3) primary key nonclustered, b int)", "a") + assertPKIsNotHandle("create table t (a int, b bigint auto_random(3) primary key nonclustered)", "b") // Can not set auto_random along with auto_increment. assertWithAutoInc("create table t (a bigint auto_random(3) primary key auto_increment)") @@ -1158,14 +1142,11 @@ func (s *testSerialSuite) TestAutoRandom(c *C) { }) } -func (s *testSerialSuite) TestAutoRandomExchangePartition(c *C) { +func (s *testIntegrationSuite9) TestAutoRandomExchangePartition(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists auto_random_db") defer tk.MustExec("drop database if exists auto_random_db") - ConfigTestUtils.SetupAutoRandomTestConfig() - defer ConfigTestUtils.RestoreAutoRandomTestConfig() - tk.MustExec("use auto_random_db") tk.MustExec("set @@tidb_enable_exchange_partition=1") @@ -1173,7 +1154,7 @@ func (s *testSerialSuite) TestAutoRandomExchangePartition(c *C) { tk.MustExec("drop table if exists e1, e2, e3, e4;") - tk.MustExec("create table e1 (a bigint primary key auto_random(3)) partition by hash(a) partitions 1;") + tk.MustExec("create table e1 (a bigint primary key clustered auto_random(3)) partition by hash(a) partitions 1;") tk.MustExec("create table e2 (a bigint primary key);") tk.MustGetErrCode("alter table e1 exchange partition p0 with table e2;", errno.ErrTablesDifferentMetadata) @@ -1195,19 +1176,16 @@ func (s *testSerialSuite) TestAutoRandomExchangePartition(c *C) { tk.MustQuery("select count(*) from e4").Check(testkit.Rows("4")) } -func (s *testSerialSuite) TestAutoRandomIncBitsIncrementAndOffset(c *C) { +func (s *testIntegrationSuite9) TestAutoRandomIncBitsIncrementAndOffset(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists auto_random_db") defer tk.MustExec("drop database if exists auto_random_db") tk.MustExec("use auto_random_db") tk.MustExec("drop table if exists t") - ConfigTestUtils.SetupAutoRandomTestConfig() - defer ConfigTestUtils.RestoreAutoRandomTestConfig() - recreateTable := func() { tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a bigint auto_random(6) primary key)") + tk.MustExec("create table t (a bigint auto_random(6) primary key clustered)") } truncateTable := func() { _, _ = tk.Exec("delete from t") @@ -1262,15 +1240,13 @@ func (s *testSerialSuite) TestAutoRandomWithPreSplitRegion(c *C) { tk.MustExec("use auto_random_db;") tk.MustExec("drop table if exists t;") - ConfigTestUtils.SetupAutoRandomTestConfig() - defer ConfigTestUtils.RestoreAutoRandomTestConfig() origin := atomic.LoadUint32(&ddl.EnableSplitTableRegion) atomic.StoreUint32(&ddl.EnableSplitTableRegion, 1) defer atomic.StoreUint32(&ddl.EnableSplitTableRegion, origin) tk.MustExec("set @@global.tidb_scatter_region=1;") // Test pre-split table region for auto_random table. - tk.MustExec("create table t (a bigint auto_random(2) primary key, b int) pre_split_regions=2;") + tk.MustExec("create table t (a bigint auto_random(2) primary key clustered, b int) pre_split_regions=2;") re := tk.MustQuery("show table t regions;") rows := re.Rows() c.Assert(len(rows), Equals, 4) @@ -1352,7 +1328,7 @@ func (s *testSerialSuite) TestForbidUnsupportedCollations(c *C) { // mustGetUnsupportedCollation("alter table t convert to collate utf8mb4_unicode_ci", "utf8mb4_unicode_ci") } -func (s *testSerialSuite) TestInvisibleIndex(c *C) { +func (s *testIntegrationSuite9) TestInvisibleIndex(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -1391,17 +1367,12 @@ func (s *testSerialSuite) TestInvisibleIndex(c *C) { tk.MustExec("insert into t values (11, 12)") tk.MustQuery("select * from t").Check(testkit.Rows("1 2", "3 4", "5 6", "7 8", "9 10", "11 12")) - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = true - }) - // Limitation: Primary key cannot be invisible index - tk.MustGetErrCode("create table t1 (a int, primary key (a) invisible)", errno.ErrPKIndexCantBeInvisible) - tk.MustGetErrCode("create table t1 (a int, b int, primary key (a, b) invisible)", errno.ErrPKIndexCantBeInvisible) + tk.MustGetErrCode("create table t1 (a int, primary key (a) nonclustered invisible)", errno.ErrPKIndexCantBeInvisible) + tk.MustGetErrCode("create table t1 (a int, b int, primary key (a, b) nonclustered invisible)", errno.ErrPKIndexCantBeInvisible) tk.MustExec("create table t1 (a int, b int)") - tk.MustGetErrCode("alter table t1 add primary key(a) invisible", errno.ErrPKIndexCantBeInvisible) - tk.MustGetErrCode("alter table t1 add primary key(a, b) invisible", errno.ErrPKIndexCantBeInvisible) + tk.MustGetErrCode("alter table t1 add primary key(a) nonclustered invisible", errno.ErrPKIndexCantBeInvisible) + tk.MustGetErrCode("alter table t1 add primary key(a, b) nonclustered invisible", errno.ErrPKIndexCantBeInvisible) // Implicit primary key cannot be invisible index // Create a implicit primary key @@ -1423,7 +1394,7 @@ func (s *testSerialSuite) TestInvisibleIndex(c *C) { tk.MustGetErrCode("alter table t5 drop index a", errno.ErrPKIndexCantBeInvisible) tk.MustGetErrCode("alter table t5 modify column a int null", errno.ErrPKIndexCantBeInvisible) // If these is a explicit primary key, no key will become implicit primary key - tk.MustExec("create table t6 (a int not null, b int, unique (a) invisible, primary key(b))") + tk.MustExec("create table t6 (a int not null, b int, unique (a) invisible, primary key(b) nonclustered)") showIndexes = "select index_name, is_visible from information_schema.statistics where table_schema = 'test' and table_name = 't6'" tk.MustQuery(showIndexes).Check(testkit.Rows("a NO", "PRIMARY YES")) tk.MustExec("insert into t6 values (1, 2)") @@ -1433,7 +1404,7 @@ func (s *testSerialSuite) TestInvisibleIndex(c *C) { c.Check(len(res.Rows()), Equals, 1) } -func (s *testSerialSuite) TestCreateClusteredIndex(c *C) { +func (s *testIntegrationSuite9) TestCreateClusteredIndex(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) tk.Se.GetSessionVars().EnableClusteredIndex = true tk.MustExec("CREATE TABLE t1 (a int primary key, b int)") @@ -1456,11 +1427,8 @@ func (s *testSerialSuite) TestCreateClusteredIndex(c *C) { c.Assert(err, IsNil) c.Assert(tbl.Meta().IsCommonHandle, IsFalse) - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = true - }) - tk.MustExec("CREATE TABLE t5 (a varchar(255) primary key, b int)") - tk.MustExec("CREATE TABLE t6 (a int, b int, c int, primary key (a, b))") + tk.MustExec("CREATE TABLE t5 (a varchar(255) primary key nonclustered, b int)") + tk.MustExec("CREATE TABLE t6 (a int, b int, c int, primary key (a, b) nonclustered)") is = domain.GetDomain(ctx).InfoSchema() tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t5")) c.Assert(err, IsNil) @@ -1468,9 +1436,6 @@ func (s *testSerialSuite) TestCreateClusteredIndex(c *C) { tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t6")) c.Assert(err, IsNil) c.Assert(tbl.Meta().IsCommonHandle, IsFalse) - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) tk.MustExec("CREATE TABLE t21 like t2") tk.MustExec("CREATE TABLE t31 like t3") diff --git a/executor/ddl_test.go b/executor/ddl_test.go index bc848091998a9..b530f7cd0d3a1 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -862,14 +862,6 @@ type testAutoRandomSuite struct { *baseTestSuite } -func (s *testAutoRandomSuite) SetUpTest(c *C) { - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() -} - -func (s *testAutoRandomSuite) TearDownTest(c *C) { - testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() -} - func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { tk := testkit.NewTestKit(c, s.store) @@ -886,7 +878,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { tk.MustExec("set @@allow_auto_random_explicit_insert = true") - tk.MustExec("create table t (a bigint primary key auto_random(15), b int)") + tk.MustExec("create table t (a bigint primary key clustered auto_random(15), b int)") for i := 0; i < 100; i++ { tk.MustExec("insert into t(b) values (?)", i) } @@ -902,7 +894,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { } c.Assert(allZero, IsFalse) // Test non-shard-bits part of auto random id is monotonic increasing and continuous. - orderedHandles := testutil.ConfigTestUtils.MaskSortHandles(allHandles, 15, mysql.TypeLonglong) + orderedHandles := testutil.MaskSortHandles(allHandles, 15, mysql.TypeLonglong) size := int64(len(allHandles)) for i := int64(1); i <= size; i++ { c.Assert(i, Equals, orderedHandles[i-1]) @@ -910,7 +902,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { // Test explicit insert. autoRandBitsUpperBound := 2<<47 - 1 - tk.MustExec("create table t (a bigint primary key auto_random(15), b int)") + tk.MustExec("create table t (a bigint primary key clustered auto_random(15), b int)") for i := -10; i < 10; i++ { tk.MustExec(fmt.Sprintf("insert into t values(%d, %d)", i+autoRandBitsUpperBound, i)) } @@ -944,7 +936,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { tk.MustExec("insert into t(a, b) values (?, ?)", -i, i) } // orderedHandles should be [-100, -99, ..., -2, -1, 1, 2, ..., 99, 100] - orderedHandles = testutil.ConfigTestUtils.MaskSortHandles(extractAllHandles(), 15, mysql.TypeLonglong) + orderedHandles = testutil.MaskSortHandles(extractAllHandles(), 15, mysql.TypeLonglong) size = int64(len(allHandles)) for i := int64(0); i < 100; i++ { c.Assert(orderedHandles[i], Equals, i-100) @@ -1015,7 +1007,7 @@ func (s *testAutoRandomSuite) TestAutoRandomTableOption(c *C) { c.Assert(err, IsNil) c.Assert(len(allHandles), Equals, 5) // Test non-shard-bits part of auto random id is monotonic increasing and continuous. - orderedHandles := testutil.ConfigTestUtils.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) + orderedHandles := testutil.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) size := int64(len(allHandles)) for i := int64(0); i < size; i++ { c.Assert(i+1000, Equals, orderedHandles[i]) @@ -1029,7 +1021,7 @@ func (s *testAutoRandomSuite) TestAutoRandomTableOption(c *C) { tk.MustExec("insert into alter_table_auto_random_option values(),(),(),(),()") allHandles, err = ddltestutil.ExtractAllTableHandles(tk.Se, "test", "alter_table_auto_random_option") c.Assert(err, IsNil) - orderedHandles = testutil.ConfigTestUtils.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) + orderedHandles = testutil.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) size = int64(len(allHandles)) for i := int64(0); i < size; i++ { c.Assert(orderedHandles[i], Equals, i+1) @@ -1047,7 +1039,7 @@ func (s *testAutoRandomSuite) TestAutoRandomTableOption(c *C) { tk.MustExec("insert into alter_table_auto_random_option values(),(),(),(),()") allHandles, err = ddltestutil.ExtractAllTableHandles(tk.Se, "test", "alter_table_auto_random_option") c.Assert(err, IsNil) - orderedHandles = testutil.ConfigTestUtils.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) + orderedHandles = testutil.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) size = int64(len(allHandles)) for i := int64(0); i < size; i++ { c.Assert(orderedHandles[i], Equals, i+3000000) @@ -1079,7 +1071,7 @@ func (s *testAutoRandomSuite) TestFilterDifferentAllocators(c *C) { allHandles, err := ddltestutil.ExtractAllTableHandles(tk.Se, "test", "t") c.Assert(err, IsNil) c.Assert(len(allHandles), Equals, 1) - orderedHandles := testutil.ConfigTestUtils.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) + orderedHandles := testutil.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) c.Assert(orderedHandles[0], Equals, int64(1)) tk.MustExec("delete from t") @@ -1090,7 +1082,7 @@ func (s *testAutoRandomSuite) TestFilterDifferentAllocators(c *C) { allHandles, err = ddltestutil.ExtractAllTableHandles(tk.Se, "test", "t") c.Assert(err, IsNil) c.Assert(len(allHandles), Equals, 1) - orderedHandles = testutil.ConfigTestUtils.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) + orderedHandles = testutil.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) c.Assert(orderedHandles[0], Equals, int64(2)) tk.MustExec("delete from t") @@ -1101,7 +1093,7 @@ func (s *testAutoRandomSuite) TestFilterDifferentAllocators(c *C) { allHandles, err = ddltestutil.ExtractAllTableHandles(tk.Se, "test", "t") c.Assert(err, IsNil) c.Assert(len(allHandles), Equals, 1) - orderedHandles = testutil.ConfigTestUtils.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) + orderedHandles = testutil.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) c.Assert(orderedHandles[0], Equals, int64(3000000)) tk.MustExec("delete from t") @@ -1115,7 +1107,7 @@ func (s *testAutoRandomSuite) TestFilterDifferentAllocators(c *C) { allHandles, err = ddltestutil.ExtractAllTableHandles(tk.Se, "test", "t1") c.Assert(err, IsNil) c.Assert(len(allHandles), Equals, 1) - orderedHandles = testutil.ConfigTestUtils.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) + orderedHandles = testutil.MaskSortHandles(allHandles, 5, mysql.TypeLonglong) c.Assert(orderedHandles[0], Greater, int64(3000001)) } diff --git a/executor/insert_test.go b/executor/insert_test.go index 467e9e022c77e..891a74f495660 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -1126,20 +1126,17 @@ func (s *testSuite3) TestAutoIDIncrementAndOffset(c *C) { c.Assert(err.Error(), Equals, "[autoid:8060]Invalid auto_increment settings: auto_increment_increment: 65536, auto_increment_offset: 65536, both of them must be in range [1..65535]") } -var _ = SerialSuites(&testSuite9{&baseTestSuite{}}) +var _ = Suite(&testSuite9{&baseTestSuite{}}) type testSuite9 struct { *baseTestSuite } func (s *testSuite9) TestAutoRandomID(c *C) { - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() - tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test`) tk.MustExec(`drop table if exists ar`) - tk.MustExec(`create table ar (id bigint key auto_random, name char(10))`) + tk.MustExec(`create table ar (id bigint key clustered auto_random, name char(10))`) tk.MustExec(`insert into ar(id) values (null)`) rs := tk.MustQuery(`select id from ar`) @@ -1168,7 +1165,7 @@ func (s *testSuite9) TestAutoRandomID(c *C) { tk.MustQuery(`select last_insert_id()`).Check(testkit.Rows(fmt.Sprintf("%d", firstValue))) tk.MustExec(`drop table ar`) - tk.MustExec(`create table ar (id bigint key auto_random(15), name char(10))`) + tk.MustExec(`create table ar (id bigint key clustered auto_random(15), name char(10))`) overflowVal := 1 << (64 - 5) errMsg := fmt.Sprintf(autoid.AutoRandomRebaseOverflow, overflowVal, 1<<(64-16)-1) _, err = tk.Exec(fmt.Sprintf("alter table ar auto_random_base = %d", overflowVal)) @@ -1177,13 +1174,10 @@ func (s *testSuite9) TestAutoRandomID(c *C) { } func (s *testSuite9) TestMultiAutoRandomID(c *C) { - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() - tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test`) tk.MustExec(`drop table if exists ar`) - tk.MustExec(`create table ar (id bigint key auto_random, name char(10))`) + tk.MustExec(`create table ar (id bigint key clustered auto_random, name char(10))`) tk.MustExec(`insert into ar(id) values (null),(null),(null)`) rs := tk.MustQuery(`select id from ar order by id`) @@ -1221,13 +1215,10 @@ func (s *testSuite9) TestMultiAutoRandomID(c *C) { } func (s *testSuite9) TestAutoRandomIDAllowZero(c *C) { - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() - tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test`) tk.MustExec(`drop table if exists ar`) - tk.MustExec(`create table ar (id bigint key auto_random, name char(10))`) + tk.MustExec(`create table ar (id bigint key clustered auto_random, name char(10))`) rs := tk.MustQuery(`select @@session.sql_mode`) sqlMode := rs.Rows()[0][0].(string) @@ -1254,15 +1245,12 @@ func (s *testSuite9) TestAutoRandomIDAllowZero(c *C) { } func (s *testSuite9) TestAutoRandomIDExplicit(c *C) { - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() - tk := testkit.NewTestKit(c, s.store) tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec(`use test`) tk.MustExec(`drop table if exists ar`) - tk.MustExec(`create table ar (id bigint key auto_random, name char(10))`) + tk.MustExec(`create table ar (id bigint key clustered auto_random, name char(10))`) tk.MustExec(`insert into ar(id) values (1)`) tk.MustQuery(`select id from ar`).Check(testkit.Rows("1")) diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index ef1909bfad487..fc6be951b58a3 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -848,12 +848,10 @@ func HelperTestAdminShowNextID(c *C, s *seqTestSuite, str string) { r.Check(testkit.Rows("test1 tt id 41 AUTO_INCREMENT")) tk.MustExec("drop table tt") - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() tk.MustExec("set @@allow_auto_random_explicit_insert = true") // Test for a table with auto_random primary key. - tk.MustExec("create table t3(id bigint primary key auto_random(5), c int)") + tk.MustExec("create table t3(id bigint primary key clustered auto_random(5), c int)") // Start handle is 1. r = tk.MustQuery(str + " t3 next_row_id") r.Check(testkit.Rows("test1 t3 id 1 AUTO_RANDOM")) @@ -1381,17 +1379,15 @@ func (s *seqTestSuite) TestInsertFromSelectConflictRetryAutoID(c *C) { func (s *seqTestSuite) TestAutoRandIDRetry(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() tk.MustExec("create database if not exists auto_random_retry") tk.MustExec("use auto_random_retry") tk.MustExec("drop table if exists t") - tk.MustExec("create table t (id bigint auto_random(3) primary key)") + tk.MustExec("create table t (id bigint auto_random(3) primary key clustered)") extractMaskedOrderedHandles := func() []int64 { handles, err := ddltestutil.ExtractAllTableHandles(tk.Se, "auto_random_retry", "t") c.Assert(err, IsNil) - return testutil.ConfigTestUtils.MaskSortHandles(handles, 3, mysql.TypeLong) + return testutil.MaskSortHandles(handles, 3, mysql.TypeLong) } tk.MustExec("set @@tidb_disable_txn_auto_retry = 0") @@ -1425,8 +1421,6 @@ func (s *seqTestSuite) TestAutoRandIDRetry(c *C) { func (s *seqTestSuite) TestAutoRandRecoverTable(c *C) { tk := testkit.NewTestKit(c, s.store) - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() tk.MustExec("create database if not exists test_recover") tk.MustExec("use test_recover") tk.MustExec("drop table if exists t_recover_auto_rand") @@ -1462,14 +1456,14 @@ func (s *seqTestSuite) TestAutoRandRecoverTable(c *C) { defer autoid.SetStep(stp) // Check rebase auto_random id. - tk.MustExec("create table t_recover_auto_rand (a bigint auto_random(5) primary key);") + tk.MustExec("create table t_recover_auto_rand (a bigint auto_random(5) primary key clustered);") tk.MustExec("insert into t_recover_auto_rand values (),(),()") tk.MustExec("drop table t_recover_auto_rand") tk.MustExec("recover table t_recover_auto_rand") tk.MustExec("insert into t_recover_auto_rand values (),(),()") hs, err := ddltestutil.ExtractAllTableHandles(tk.Se, "test_recover", "t_recover_auto_rand") c.Assert(err, IsNil) - ordered := testutil.ConfigTestUtils.MaskSortHandles(hs, 5, mysql.TypeLong) + ordered := testutil.MaskSortHandles(hs, 5, mysql.TypeLong) c.Assert(ordered, DeepEquals, []int64{1, 2, 3, autoRandIDStep + 1, autoRandIDStep + 2, autoRandIDStep + 3}) } diff --git a/executor/show_test.go b/executor/show_test.go index b6d0c2937872a..75dc6f84f52cd 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -1025,16 +1025,14 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { )) } -func (s *testSerialSuite) TestAutoRandomWithLargeSignedShowTableRegions(c *C) { +func (s *testSuite5) TestAutoRandomWithLargeSignedShowTableRegions(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists auto_random_db;") defer tk.MustExec("drop database if exists auto_random_db;") tk.MustExec("use auto_random_db;") tk.MustExec("drop table if exists t;") - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() - tk.MustExec("create table t (a bigint unsigned auto_random primary key);") + tk.MustExec("create table t (a bigint unsigned auto_random primary key clustered);") tk.MustExec("set @@global.tidb_scatter_region=1;") // 18446744073709541615 is MaxUint64 - 10000. // 18446744073709551615 is the MaxUint64. diff --git a/go.mod b/go.mod index b42ff2ea6b384..a8573db171f23 100644 --- a/go.mod +++ b/go.mod @@ -86,3 +86,5 @@ require ( ) go 1.13 + +replace github.com/pingcap/br => github.com/tangenta/br v4.0.0-beta.2.0.20210303063657-f838d8fbe7ac+incompatible diff --git a/go.sum b/go.sum index 7c152071e31fd..50d7b9feae2cc 100644 --- a/go.sum +++ b/go.sum @@ -517,6 +517,8 @@ github.com/swaggo/swag v1.6.3/go.mod h1:wcc83tB4Mb2aNiL/HP4MFeQdpHUrca+Rp/DRNgWA github.com/swaggo/swag v1.6.6-0.20200529100950-7c765ddd0476/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 h1:1oFLiOyVl+W7bnBzGhf7BbIv9loSFQcieWWYIjLqcAw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= +github.com/tangenta/br v4.0.0-beta.2.0.20210303063657-f838d8fbe7ac+incompatible h1:aH9d3Maq5vdeBtU2DUNTz+xrF0Qs9z7n1eMVM/XlknA= +github.com/tangenta/br v4.0.0-beta.2.0.20210303063657-f838d8fbe7ac+incompatible/go.mod h1:Lr5a4EIcfsa6DiKvhHP68hsbTo+epSC9bvja/NiJqG4= github.com/thoas/go-funk v0.7.0/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 699a2caa2caed..b6d7ac9102ee5 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -641,13 +641,10 @@ func (s *testTableSuite) TestTableRowIDShardingInfo(c *C) { testFunc("performance_schema", nil) testFunc("uucc", "NOT_SHARDED") - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() - - tk.MustExec("CREATE TABLE `sharding_info_test_db`.`t4` (a bigint key auto_random)") + tk.MustExec("CREATE TABLE `sharding_info_test_db`.`t4` (a bigint key clustered auto_random)") assertShardingInfo("t4", "PK_AUTO_RANDOM_BITS=5") - tk.MustExec("CREATE TABLE `sharding_info_test_db`.`t5` (a bigint key auto_random(1))") + tk.MustExec("CREATE TABLE `sharding_info_test_db`.`t5` (a bigint key clustered auto_random(1))") assertShardingInfo("t5", "PK_AUTO_RANDOM_BITS=1") tk.MustExec("DROP DATABASE `sharding_info_test_db`") diff --git a/meta/autoid/errors.go b/meta/autoid/errors.go index ad0b1bcf5d12b..dbc279c0641a2 100644 --- a/meta/autoid/errors.go +++ b/meta/autoid/errors.go @@ -29,8 +29,8 @@ var ( ) const ( - // AutoRandomPKisNotHandleErrMsg indicates the auto_random column attribute is defined on a non-primary key column, or the table's primary key is not a single integer column. - AutoRandomPKisNotHandleErrMsg = "column %s is not the integer primary key, or table is created with alter-primary-key enabled" + // AutoRandomPKisNotHandleErrMsg indicates the auto_random column attribute is defined on a non-primary key column, or the primary key is nonclustered. + AutoRandomPKisNotHandleErrMsg = "column %s is not the integer primary key, or the primary key is nonclustered" // AutoRandomIncompatibleWithAutoIncErrMsg is reported when auto_random and auto_increment are specified on the same column. AutoRandomIncompatibleWithAutoIncErrMsg = "auto_random is incompatible with auto_increment" // AutoRandomIncompatibleWithDefaultValueErrMsg is reported when auto_random and default are specified on the same column. diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index d189f12a2ccbd..b449134606b75 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -15,7 +15,6 @@ package session_test import ( . "github.com/pingcap/check" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/store/tikv" "github.com/pingcap/tidb/util/collate" @@ -397,7 +396,7 @@ func (s *testClusteredSuite) TestClusteredIndexSelectWhereInNull(c *C) { tk.MustQuery("select * from t where a in (null);").Check(testkit.Rows( /* empty result */ )) } -func (s *testClusteredSerialSuite) TestClusteredIndexSyntax(c *C) { +func (s *testClusteredSuite) TestClusteredIndexSyntax(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) const showPKType = `select tidb_pk_type from information_schema.tables where table_schema = 'test' and table_name = 't';` const nonClustered, clustered = `NON-CLUSTERED`, `CLUSTERED` @@ -407,43 +406,30 @@ func (s *testClusteredSerialSuite) TestClusteredIndexSyntax(c *C) { tk.MustQuery(showPKType).Check(testkit.Rows(pkType)) } - defer config.RestoreFunc()() - for _, allowAlterPK := range []bool{true, false} { - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = allowAlterPK - }) - // Test single integer column as the primary key. - clusteredDefault := clustered - if allowAlterPK { - clusteredDefault = nonClustered - } - assertPkType("create table t (a int primary key, b int);", clusteredDefault) - assertPkType("create table t (a int, b int, primary key(a) clustered);", clustered) - assertPkType("create table t (a int, b int, primary key(a) /*T![clustered_index] clustered */);", clustered) - assertPkType("create table t (a int, b int, primary key(a) nonclustered);", nonClustered) - assertPkType("create table t (a int, b int, primary key(a) /*T![clustered_index] nonclustered */);", nonClustered) - - // Test for clustered index. - tk.Se.GetSessionVars().EnableClusteredIndex = false - assertPkType("create table t (a int, b varchar(255), primary key(b, a));", nonClustered) - assertPkType("create table t (a int, b varchar(255), primary key(b, a) nonclustered);", nonClustered) - assertPkType("create table t (a int, b varchar(255), primary key(b, a) clustered);", clustered) - tk.Se.GetSessionVars().EnableClusteredIndex = true - assertPkType("create table t (a int, b varchar(255), primary key(b, a));", clusteredDefault) - assertPkType("create table t (a int, b varchar(255), primary key(b, a) nonclustered);", nonClustered) - assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] nonclustered */);", nonClustered) - assertPkType("create table t (a int, b varchar(255), primary key(b, a) clustered);", clustered) - assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] clustered */);", clustered) - } + // Test single integer column as the primary key. + clusteredDefault := clustered + assertPkType("create table t (a int primary key, b int);", clusteredDefault) + assertPkType("create table t (a int, b int, primary key(a) clustered);", clustered) + assertPkType("create table t (a int, b int, primary key(a) /*T![clustered_index] clustered */);", clustered) + assertPkType("create table t (a int, b int, primary key(a) nonclustered);", nonClustered) + assertPkType("create table t (a int, b int, primary key(a) /*T![clustered_index] nonclustered */);", nonClustered) + + // Test for clustered index. + tk.Se.GetSessionVars().EnableClusteredIndex = false + assertPkType("create table t (a int, b varchar(255), primary key(b, a));", nonClustered) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) nonclustered);", nonClustered) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) clustered);", clustered) + tk.Se.GetSessionVars().EnableClusteredIndex = true + assertPkType("create table t (a int, b varchar(255), primary key(b, a));", clusteredDefault) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) nonclustered);", nonClustered) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] nonclustered */);", nonClustered) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) clustered);", clustered) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] clustered */);", clustered) } // https://github.com/pingcap/tidb/issues/23106 func (s *testClusteredSerialSuite) TestClusteredIndexDecodeRestoredDataV5(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) defer collate.SetNewCollationEnabledForTest(false) collate.SetNewCollationEnabledForTest(true) tk.MustExec("use test") @@ -468,10 +454,6 @@ func (s *testClusteredSerialSuite) TestPrefixedClusteredIndexUniqueKeyWithNewCol defer collate.SetNewCollationEnabledForTest(false) collate.SetNewCollationEnabledForTest(true) tk := testkit.NewTestKitWithInit(c, s.store) - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.AlterPrimaryKey = false - }) tk.MustExec("use test;") tk.Se.GetSessionVars().EnableClusteredIndex = true tk.MustExec("create table t (a text collate utf8mb4_general_ci not null, b int(11) not null, " + diff --git a/util/testutil/testutil.go b/util/testutil/testutil.go index eb2c9ad565282..d1ecd061a5624 100644 --- a/util/testutil/testutil.go +++ b/util/testutil/testutil.go @@ -32,7 +32,6 @@ import ( "github.com/pingcap/check" "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" @@ -409,34 +408,8 @@ func (t *TestData) GenerateOutputIfNeeded() error { return err } -// ConfigTestUtils contains a set of set-up/restore methods related to config used in tests. -var ConfigTestUtils configTestUtils - -type configTestUtils struct { - autoRandom -} - -type autoRandom struct { - originAlterPrimaryKey bool -} - -// SetupAutoRandomTestConfig set alter-primary-key to false and save its origin values. -// This method should only be used for the tests in SerialSuite. -func (a *autoRandom) SetupAutoRandomTestConfig() { - globalCfg := config.GetGlobalConfig() - a.originAlterPrimaryKey = globalCfg.AlterPrimaryKey - globalCfg.AlterPrimaryKey = false -} - -// RestoreAutoRandomTestConfig restore the values had been saved in SetupTestConfig. -// This method should only be used for the tests in SerialSuite. -func (a *autoRandom) RestoreAutoRandomTestConfig() { - globalCfg := config.GetGlobalConfig() - globalCfg.AlterPrimaryKey = a.originAlterPrimaryKey -} - // MaskSortHandles sorts the handles by lowest (fieldTypeBits - 1 - shardBitsCount) bits. -func (a *autoRandom) MaskSortHandles(handles []int64, shardBitsCount int, fieldType byte) []int64 { +func MaskSortHandles(handles []int64, shardBitsCount int, fieldType byte) []int64 { typeBitsLength := mysql.DefaultLengthOfMysqlTypes[fieldType] * 8 const signBitCount = 1 shiftBitsCount := 64 - typeBitsLength + shardBitsCount + signBitCount From b74b55a390aeb229e1139f02649a7229972fb0b5 Mon Sep 17 00:00:00 2001 From: tangenta Date: Thu, 11 Mar 2021 21:43:20 +0800 Subject: [PATCH 02/16] ddl: disable PKIsHandle by default --- ddl/ddl_api.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 9553379a1c218..76f396540a545 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -1425,9 +1425,8 @@ func buildTableInfo( if err != nil { return nil, err } - isIntPK := isSingleIntPK(constr, lastCol) - if ShouldBuildClusteredIndex(ctx, constr.Option, isIntPK) { - if isIntPK { + if ShouldBuildClusteredIndex(ctx, constr.Option) { + if isSingleIntPK(constr, lastCol) { tbInfo.PKIsHandle = true } else { tbInfo.IsCommonHandle = true @@ -1508,18 +1507,12 @@ func isSingleIntPK(constr *ast.Constraint, lastCol *model.ColumnInfo) bool { } // ShouldBuildClusteredIndex is used to determine whether the CREATE TABLE statement should build a clustered index table. -func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption, isIntPK bool) bool { +func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption) bool { if opt == nil || opt.PrimaryKeyTp == model.PrimaryKeyTypeDefault { - if isIntPK { - return true - } return ctx.GetSessionVars().EnableClusteredIndex } switch opt.PrimaryKeyTp { case model.PrimaryKeyTypeClustered: - if isIntPK { - return true - } hasBinlog := ctx.GetSessionVars().BinlogClient != nil if hasBinlog { errMsg := "cannot build clustered index table because the binlog is ON" From a36467800976274f65b38ad9669c96f08dabd9a3 Mon Sep 17 00:00:00 2001 From: tangenta Date: Mon, 15 Mar 2021 16:14:39 +0800 Subject: [PATCH 03/16] bring back AlterPrimaryKey to Config to help BR's PR merge --- config/config.go | 3 +++ go.mod | 2 -- go.sum | 3 --- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 6b93e2b40d4bf..36ae15d9db7a5 100644 --- a/config/config.go +++ b/config/config.go @@ -125,6 +125,8 @@ type Config struct { IndexLimit int `toml:"index-limit" json:"index-limit"` TableColumnCountLimit uint32 `toml:"table-column-count-limit" json:"table-column-count-limit"` GracefulWaitBeforeShutdown int `toml:"graceful-wait-before-shutdown" json:"graceful-wait-before-shutdown"` + // AlterPrimaryKey is used to control alter primary key feature. + AlterPrimaryKey bool `toml:"alter-primary-key" json:"alter-primary-key"` // TreatOldVersionUTF8AsUTF8MB4 is use to treat old version table/column UTF8 charset as UTF8MB4. This is for compatibility. // Currently not support dynamic modify, because this need to reload all old version schema. TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"` @@ -552,6 +554,7 @@ var defaultConf = Config{ MaxIndexLength: 3072, IndexLimit: 64, TableColumnCountLimit: 1017, + AlterPrimaryKey: false, TreatOldVersionUTF8AsUTF8MB4: true, EnableTableLock: false, DelayCleanTableLock: 0, diff --git a/go.mod b/go.mod index a8573db171f23..b42ff2ea6b384 100644 --- a/go.mod +++ b/go.mod @@ -86,5 +86,3 @@ require ( ) go 1.13 - -replace github.com/pingcap/br => github.com/tangenta/br v4.0.0-beta.2.0.20210303063657-f838d8fbe7ac+incompatible diff --git a/go.sum b/go.sum index 50d7b9feae2cc..eb1fdc8363302 100644 --- a/go.sum +++ b/go.sum @@ -466,7 +466,6 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44 h1:tB9NOR21++IjLyVx3/PCPhWMwqGNCMQEH96A6dMZ/gc= github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v2.19.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M= @@ -517,8 +516,6 @@ github.com/swaggo/swag v1.6.3/go.mod h1:wcc83tB4Mb2aNiL/HP4MFeQdpHUrca+Rp/DRNgWA github.com/swaggo/swag v1.6.6-0.20200529100950-7c765ddd0476/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 h1:1oFLiOyVl+W7bnBzGhf7BbIv9loSFQcieWWYIjLqcAw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= -github.com/tangenta/br v4.0.0-beta.2.0.20210303063657-f838d8fbe7ac+incompatible h1:aH9d3Maq5vdeBtU2DUNTz+xrF0Qs9z7n1eMVM/XlknA= -github.com/tangenta/br v4.0.0-beta.2.0.20210303063657-f838d8fbe7ac+incompatible/go.mod h1:Lr5a4EIcfsa6DiKvhHP68hsbTo+epSC9bvja/NiJqG4= github.com/thoas/go-funk v0.7.0/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= From b4a15ff6b81c1dfd7e22e9e26d866fa4f3ffd845 Mon Sep 17 00:00:00 2001 From: tangenta Date: Mon, 15 Mar 2021 18:02:44 +0800 Subject: [PATCH 04/16] throw an error when binlog is enabled during creating clustered index --- ddl/ddl_api.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 76f396540a545..8aea6df281e56 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -39,6 +39,7 @@ import ( field_types "github.com/pingcap/parser/types" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" + "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -54,6 +55,7 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/collate" + "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/domainutil" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/mock" @@ -1425,7 +1427,11 @@ func buildTableInfo( if err != nil { return nil, err } - if ShouldBuildClusteredIndex(ctx, constr.Option) { + clustered, err := ShouldBuildClusteredIndex(ctx, constr.Option) + if err != nil { + return nil, err + } + if clustered { if isSingleIntPK(constr, lastCol) { tbInfo.PKIsHandle = true } else { @@ -1507,24 +1513,23 @@ func isSingleIntPK(constr *ast.Constraint, lastCol *model.ColumnInfo) bool { } // ShouldBuildClusteredIndex is used to determine whether the CREATE TABLE statement should build a clustered index table. -func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption) bool { +func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption) (bool, error) { if opt == nil || opt.PrimaryKeyTp == model.PrimaryKeyTypeDefault { - return ctx.GetSessionVars().EnableClusteredIndex + return ctx.GetSessionVars().EnableClusteredIndex, nil } switch opt.PrimaryKeyTp { case model.PrimaryKeyTypeClustered: hasBinlog := ctx.GetSessionVars().BinlogClient != nil if hasBinlog { - errMsg := "cannot build clustered index table because the binlog is ON" - ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf(errMsg)) - return false + msg := mysql.Message("Cannot create clustered index table when the binlog is ON", nil) + return false, dbterror.ClassDDL.NewStdErr(errno.ErrUnsupportedDDLOperation, msg) } - return true + return true, nil case model.PrimaryKeyTypeNonClustered: - return false + return false, nil default: // should never reach here logutil.BgLogger().Error("Unknown primary key type") - return false + return false, nil } } From f4e0c389d34470e717ab74f5f5ee6b4f17e360aa Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 16 Mar 2021 10:54:31 +0800 Subject: [PATCH 05/16] remove session variable tidb_enable_clustered_index --- expression/integration_test.go | 5 ++--- sessionctx/variable/sysvar.go | 2 +- statistics/selectivity_test.go | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index f19afccb3d906..a045ea50a1681 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7946,7 +7946,7 @@ func (s *testIntegrationSerialSuite) TestClusteredIndexAndNewCollationIndexEncod tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists t") - tk.MustExec("set @@tidb_enable_clustered_index=1;") + tk.Se.GetSessionVars().EnableClusteredIndex = true tk.MustExec("create table t(a int, b char(10) collate utf8mb4_bin, c char(10) collate utf8mb4_general_ci," + "d varchar(10) collate utf8mb4_bin, e varchar(10) collate utf8mb4_general_ci, f char(10) collate utf8mb4_unicode_ci, g varchar(10) collate utf8mb4_unicode_ci, " + "primary key(a, b, c, d, e, f, g), key a(a), unique key ua(a), key b(b), unique key ub(b), key c(c), unique key uc(c)," + @@ -8909,9 +8909,8 @@ func (s *testIntegrationSuite) TestClusteredIndexCorCol(c *C) { // For issue 23076 tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") - tk.MustExec("set @@tidb_enable_clustered_index=1;") tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) , key(c_int) );") + tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) clustered, key(c_int) );") tk.MustExec("create table t2 like t1 ;") tk.MustExec("insert into t1 values (1, 'crazy lumiere'), (10, 'goofy mestorf');") tk.MustExec("insert into t2 select * from t1 ;") diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index c8aae167e6b34..a1038c77f9272 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -767,7 +767,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeSession, Name: TiDBFoundInBinding, Value: BoolToOnOff(DefTiDBFoundInBinding), Type: TypeBool, ReadOnly: true}, {Scope: ScopeSession, Name: TiDBEnableCollectExecutionInfo, Value: BoolToOnOff(DefTiDBEnableCollectExecutionInfo), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBAllowAutoRandExplicitInsert, Value: BoolToOnOff(DefTiDBAllowAutoRandExplicitInsert), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableClusteredIndex, Value: BoolToOnOff(DefTiDBEnableClusteredIndex), Type: TypeBool}, + {Scope: ScopeGlobal, Name: TiDBEnableClusteredIndex, Value: BoolToOnOff(DefTiDBEnableClusteredIndex), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBPartitionPruneMode, Value: string(Static), Type: TypeStr, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { mode := PartitionPruneMode(normalizedValue).Update() if !mode.Valid() { diff --git a/statistics/selectivity_test.go b/statistics/selectivity_test.go index d5aca3cf8a6e0..c19935e3375bd 100644 --- a/statistics/selectivity_test.go +++ b/statistics/selectivity_test.go @@ -607,9 +607,8 @@ func (s *testStatsSuite) TestStatsVer2(c *C) { testKit.MustExec("analyze table tprefix with 2 topn, 3 buckets") // test with clustered index - testKit.MustExec("set @@tidb_enable_clustered_index = 1") testKit.MustExec("drop table if exists ct1") - testKit.MustExec("create table ct1 (a int, pk varchar(10), primary key(pk))") + testKit.MustExec("create table ct1 (a int, pk varchar(10), primary key(pk) clustered)") testKit.MustExec("insert into ct1 values (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8')") testKit.MustExec("analyze table ct1 with 2 topn, 3 buckets") From 2e917476d7ba737e04a5453cbd8c417930f7c2a6 Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 16 Mar 2021 12:11:35 +0800 Subject: [PATCH 06/16] enable clustered index in explain test --- cmd/explaintest/main.go | 2 +- cmd/explaintest/r/clustered_index.result | 62 ++-- cmd/explaintest/r/explain.result | 12 +- cmd/explaintest/r/explain_complex.result | 10 +- .../r/explain_complex_stats.result | 18 +- cmd/explaintest/r/explain_easy.result | 291 +++++++++--------- cmd/explaintest/r/explain_easy_stats.result | 73 +++-- cmd/explaintest/r/explain_indexmerge.result | 110 ++++--- cmd/explaintest/r/explain_join_stats.result | 12 +- cmd/explaintest/r/partition_pruning.result | 272 ++++++++-------- cmd/explaintest/r/select.result | 19 +- cmd/explaintest/r/subquery.result | 17 +- cmd/explaintest/r/tpch.result | 170 +++++----- cmd/explaintest/r/window_function.result | 8 +- cmd/explaintest/t/clustered_index.test | 22 +- 15 files changed, 560 insertions(+), 538 deletions(-) diff --git a/cmd/explaintest/main.go b/cmd/explaintest/main.go index 3fff10a5f8415..b46883096a1d7 100644 --- a/cmd/explaintest/main.go +++ b/cmd/explaintest/main.go @@ -657,7 +657,7 @@ func main() { "set @@tidb_window_concurrency=4", "set @@tidb_projection_concurrency=4", "set @@tidb_distsql_scan_concurrency=15", - "set @@global.tidb_enable_clustered_index=0;", + "set @@global.tidb_enable_clustered_index=1;", } for _, sql := range resets { if _, err = mdb.Exec(sql); err != nil { diff --git a/cmd/explaintest/r/clustered_index.result b/cmd/explaintest/r/clustered_index.result index 2dded83f272bd..b6040f2a0eec3 100644 --- a/cmd/explaintest/r/clustered_index.result +++ b/cmd/explaintest/r/clustered_index.result @@ -3,24 +3,22 @@ create database with_cluster_index; drop database if exists wout_cluster_index; create database wout_cluster_index; use with_cluster_index; -set @@tidb_enable_clustered_index = 1; -create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) , unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; -create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) , unique key idx_7 ( col_5 ) ) ; -create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) , key idx_9 ( col_11 ) ) ; -create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) , key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; -create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) , key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; +create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) clustered, unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; +create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) clustered, unique key idx_7 ( col_5 ) ) ; +create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) clustered, key idx_9 ( col_11 ) ) ; +create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) clustered, key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; +create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) clustered, key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; load stats 's/with_cluster_index_tbl_0.json'; load stats 's/with_cluster_index_tbl_1.json'; load stats 's/with_cluster_index_tbl_2.json'; load stats 's/with_cluster_index_tbl_3.json'; load stats 's/with_cluster_index_tbl_4.json'; use wout_cluster_index; -set @@tidb_enable_clustered_index = 0; -create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) , unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; -create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) , unique key idx_7 ( col_5 ) ) ; -create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) , key idx_9 ( col_11 ) ) ; -create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) , key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; -create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) , key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; +create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) nonclustered, key idx_1 ( col_3 ) , unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; +create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) nonclustered, unique key idx_7 ( col_5 ) ) ; +create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) nonclustered, key idx_9 ( col_11 ) ) ; +create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) nonclustered, key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; +create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) nonclustered, key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; load stats 's/wout_cluster_index_tbl_0.json'; load stats 's/wout_cluster_index_tbl_1.json'; load stats 's/wout_cluster_index_tbl_2.json'; @@ -28,9 +26,9 @@ load stats 's/wout_cluster_index_tbl_3.json'; load stats 's/wout_cluster_index_tbl_4.json'; explain select count(*) from with_cluster_index.tbl_0 where col_0 < 5429 ; id estRows task access object operator info -StreamAgg_17 1.00 root funcs:count(Column#8)->Column#6 +StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 └─IndexReader_18 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 └─IndexRangeScan_16 798.90 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,5429), keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 < 5429 ; id estRows task access object operator info @@ -40,9 +38,9 @@ StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 └─IndexRangeScan_16 798.90 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,5429), keep order:false explain select count(*) from with_cluster_index.tbl_0 where col_0 < 41 ; id estRows task access object operator info -StreamAgg_17 1.00 root funcs:count(Column#8)->Column#6 +StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 └─IndexReader_18 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 └─IndexRangeScan_16 41.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,41), keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 < 41 ; id estRows task access object operator info @@ -63,10 +61,11 @@ Projection_4 4509.00 root wout_cluster_index.tbl_2.col_14 └─TableFullScan_5 4673.00 cop[tikv] table:tbl_2 keep order:false explain select sum( col_4 ) from with_cluster_index.tbl_0 where col_3 != '1993-12-02' ; id estRows task access object operator info -StreamAgg_17 1.00 root funcs:sum(Column#8)->Column#6 -└─TableReader_18 1.00 root data:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:sum(with_cluster_index.tbl_0.col_4)->Column#8 - └─TableRangeScan_16 2244.00 cop[tikv] table:tbl_0 range:[-inf,1993-12-02 00:00:00), (1993-12-02 00:00:00,+inf], keep order:false +StreamAgg_37 1.00 root funcs:sum(Column#20)->Column#7 +└─TableReader_38 1.00 root data:StreamAgg_9 + └─StreamAgg_9 1.00 cop[tikv] funcs:sum(with_cluster_index.tbl_0.col_4)->Column#20 + └─Selection_36 2244.00 cop[tikv] ne(with_cluster_index.tbl_0.col_3, 1993-12-02 00:00:00.000000) + └─TableFullScan_35 2244.00 cop[tikv] table:tbl_0 keep order:false explain select sum( col_4 ) from wout_cluster_index.tbl_0 where col_3 != '1993-12-02' ; id estRows task access object operator info StreamAgg_37 1.00 root funcs:sum(Column#20)->Column#7 @@ -84,19 +83,20 @@ IndexReader_6 1.00 root index:IndexRangeScan_5 └─IndexRangeScan_5 1.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,0], keep order:false explain select col_3 from with_cluster_index.tbl_0 where col_3 >= '1981-09-15' ; id estRows task access object operator info -TableReader_6 1859.31 root data:TableRangeScan_5 -└─TableRangeScan_5 1859.31 cop[tikv] table:tbl_0 range:[1981-09-15 00:00:00,+inf], keep order:false +IndexReader_10 1859.31 root index:IndexRangeScan_9 +└─IndexRangeScan_9 1859.31 cop[tikv] table:tbl_0, index:idx_2(col_3) range:[1981-09-15 00:00:00,+inf], keep order:false explain select col_3 from wout_cluster_index.tbl_0 where col_3 >= '1981-09-15' ; id estRows task access object operator info IndexReader_10 1859.31 root index:IndexRangeScan_9 └─IndexRangeScan_9 1859.31 cop[tikv] table:tbl_0, index:idx_2(col_3) range:[1981-09-15 00:00:00,+inf], keep order:false explain select tbl_2.col_14 , tbl_0.col_1 from with_cluster_index.tbl_2 right join with_cluster_index.tbl_0 on col_3 = col_11 ; id estRows task access object operator info -MergeJoin_6 2533.51 root right outer join, left key:with_cluster_index.tbl_2.col_11, right key:with_cluster_index.tbl_0.col_3 -├─IndexReader_21(Build) 4509.00 root index:IndexFullScan_20 -│ └─IndexFullScan_20 4509.00 cop[tikv] table:tbl_2, index:idx_9(col_11) keep order:true -└─TableReader_23(Probe) 2244.00 root data:TableFullScan_22 - └─TableFullScan_22 2244.00 cop[tikv] table:tbl_0 keep order:true +IndexJoin_10 2533.51 root right outer join, inner:IndexReader_9, outer key:with_cluster_index.tbl_0.col_3, inner key:with_cluster_index.tbl_2.col_11, equal cond:eq(with_cluster_index.tbl_0.col_3, with_cluster_index.tbl_2.col_11) +├─TableReader_35(Build) 2244.00 root data:TableFullScan_34 +│ └─TableFullScan_34 2244.00 cop[tikv] table:tbl_0 keep order:false +└─IndexReader_9(Probe) 1.13 root index:Selection_8 + └─Selection_8 1.13 cop[tikv] not(isnull(with_cluster_index.tbl_2.col_11)) + └─IndexRangeScan_7 1.17 cop[tikv] table:tbl_2, index:idx_9(col_11) range: decided by [eq(with_cluster_index.tbl_2.col_11, with_cluster_index.tbl_0.col_3)], keep order:false explain select tbl_2.col_14 , tbl_0.col_1 from wout_cluster_index.tbl_2 right join wout_cluster_index.tbl_0 on col_3 = col_11 ; id estRows task access object operator info HashJoin_22 2533.51 root right outer join, equal:[eq(wout_cluster_index.tbl_2.col_11, wout_cluster_index.tbl_0.col_3)] @@ -107,9 +107,9 @@ HashJoin_22 2533.51 root right outer join, equal:[eq(wout_cluster_index.tbl_2.c └─TableFullScan_41 4673.00 cop[tikv] table:tbl_2 keep order:false explain select count(*) from with_cluster_index.tbl_0 where col_0 <= 0 ; id estRows task access object operator info -StreamAgg_16 1.00 root funcs:count(Column#8)->Column#6 +StreamAgg_16 1.00 root funcs:count(Column#9)->Column#7 └─IndexReader_17 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 └─IndexRangeScan_11 1.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,0], keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 <= 0 ; id estRows task access object operator info @@ -119,9 +119,9 @@ StreamAgg_16 1.00 root funcs:count(Column#9)->Column#7 └─IndexRangeScan_11 1.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,0], keep order:false explain select count(*) from with_cluster_index.tbl_0 where col_0 >= 803163 ; id estRows task access object operator info -StreamAgg_17 1.00 root funcs:count(Column#8)->Column#6 +StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 └─IndexReader_18 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 └─IndexRangeScan_16 109.70 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[803163,+inf], keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 >= 803163 ; id estRows task access object operator info diff --git a/cmd/explaintest/r/explain.result b/cmd/explaintest/r/explain.result index 259a7c49be9ea..43a79435b1d84 100644 --- a/cmd/explaintest/r/explain.result +++ b/cmd/explaintest/r/explain.result @@ -28,16 +28,16 @@ set session tidb_hashagg_partial_concurrency = 1; set session tidb_hashagg_final_concurrency = 1; explain format = 'brief' select group_concat(a) from t group by id; id estRows task access object operator info -StreamAgg 8000.00 root group by:Column#6, funcs:group_concat(Column#5 separator ",")->Column#4 -└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, test.t.id +HashAgg 8000.00 root group by:Column#9, funcs:group_concat(Column#8 separator ",")->Column#5 +└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#8, test.t.id └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t keep order:true, stats:pseudo + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select group_concat(a, b) from t group by id; id estRows task access object operator info -StreamAgg 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6 separator ",")->Column#4 -└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id +HashAgg 8000.00 root group by:Column#10, funcs:group_concat(Column#8, Column#9 separator ",")->Column#5 +└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#8, cast(test.t.b, var_string(20))->Column#9, test.t.id └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t keep order:true, stats:pseudo + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo drop table t; drop view if exists v; create view v as select cast(replace(substring_index(substring_index("",',',1),':',-1),'"','') as CHAR(32)) as event_id; diff --git a/cmd/explaintest/r/explain_complex.result b/cmd/explaintest/r/explain_complex.result index b3c79948a142e..4e7e0d430d1a2 100644 --- a/cmd/explaintest/r/explain_complex.result +++ b/cmd/explaintest/r/explain_complex.result @@ -105,12 +105,12 @@ PRIMARY KEY (`aid`,`dic`) ); explain format = 'brief' SELECT `ds`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6_md5`, `p7_md5`, count(dic) as install_device FROM `dt` use index (cmi) WHERE (`ds` >= '2016-09-01') AND (`ds` <= '2016-11-03') AND (`cm` IN ('1062', '1086', '1423', '1424', '1425', '1426', '1427', '1428', '1429', '1430', '1431', '1432', '1433', '1434', '1435', '1436', '1437', '1438', '1439', '1440', '1441', '1442', '1443', '1444', '1445', '1446', '1447', '1448', '1449', '1450', '1451', '1452', '1488', '1489', '1490', '1491', '1492', '1493', '1494', '1495', '1496', '1497', '1550', '1551', '1552', '1553', '1554', '1555', '1556', '1557', '1558', '1559', '1597', '1598', '1599', '1600', '1601', '1602', '1603', '1604', '1605', '1606', '1607', '1608', '1609', '1610', '1611', '1612', '1613', '1614', '1615', '1616', '1623', '1624', '1625', '1626', '1627', '1628', '1629', '1630', '1631', '1632', '1709', '1719', '1720', '1843', '2813', '2814', '2815', '2816', '2817', '2818', '2819', '2820', '2821', '2822', '2823', '2824', '2825', '2826', '2827', '2828', '2829', '2830', '2831', '2832', '2833', '2834', '2835', '2836', '2837', '2838', '2839', '2840', '2841', '2842', '2843', '2844', '2845', '2846', '2847', '2848', '2849', '2850', '2851', '2852', '2853', '2854', '2855', '2856', '2857', '2858', '2859', '2860', '2861', '2862', '2863', '2864', '2865', '2866', '2867', '2868', '2869', '2870', '2871', '2872', '3139', '3140', '3141', '3142', '3143', '3144', '3145', '3146', '3147', '3148', '3149', '3150', '3151', '3152', '3153', '3154', '3155', '3156', '3157', '3158', '3386', '3387', '3388', '3389', '3390', '3391', '3392', '3393', '3394', '3395', '3664', '3665', '3666', '3667', '3668', '3670', '3671', '3672', '3673', '3674', '3676', '3677', '3678', '3679', '3680', '3681', '3682', '3683', '3684', '3685', '3686', '3687', '3688', '3689', '3690', '3691', '3692', '3693', '3694', '3695', '3696', '3697', '3698', '3699', '3700', '3701', '3702', '3703', '3704', '3705', '3706', '3707', '3708', '3709', '3710', '3711', '3712', '3713', '3714', '3715', '3960', '3961', '3962', '3963', '3964', '3965', '3966', '3967', '3968', '3978', '3979', '3980', '3981', '3982', '3983', '3984', '3985', '3986', '3987', '4208', '4209', '4210', '4211', '4212', '4304', '4305', '4306', '4307', '4308', '4866', '4867', '4868', '4869', '4870', '4871', '4872', '4873', '4874', '4875')) GROUP BY `ds`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6_md5`, `p7_md5` ORDER BY `ds2` DESC; id estRows task access object operator info -Projection 53.00 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#21 +Projection 53.00 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#22 └─Sort 53.00 root test.dt.ds2:desc - └─HashAgg 53.00 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#32)->Column#21, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#34)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 + └─HashAgg 53.00 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#33)->Column#22, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#35)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 └─IndexLookUp 53.00 root ├─IndexRangeScan(Build) 2650.00 cop[tikv] table:dt, index:cmi(cm) range:[1062,1062], [1086,1086], [1423,1423], [1424,1424], [1425,1425], [1426,1426], [1427,1427], [1428,1428], [1429,1429], [1430,1430], [1431,1431], [1432,1432], [1433,1433], [1434,1434], [1435,1435], [1436,1436], [1437,1437], [1438,1438], [1439,1439], [1440,1440], [1441,1441], [1442,1442], [1443,1443], [1444,1444], [1445,1445], [1446,1446], [1447,1447], [1448,1448], [1449,1449], [1450,1450], [1451,1451], [1452,1452], [1488,1488], [1489,1489], [1490,1490], [1491,1491], [1492,1492], [1493,1493], [1494,1494], [1495,1495], [1496,1496], [1497,1497], [1550,1550], [1551,1551], [1552,1552], [1553,1553], [1554,1554], [1555,1555], [1556,1556], [1557,1557], [1558,1558], [1559,1559], [1597,1597], [1598,1598], [1599,1599], [1600,1600], [1601,1601], [1602,1602], [1603,1603], [1604,1604], [1605,1605], [1606,1606], [1607,1607], [1608,1608], [1609,1609], [1610,1610], [1611,1611], [1612,1612], [1613,1613], [1614,1614], [1615,1615], [1616,1616], [1623,1623], [1624,1624], [1625,1625], [1626,1626], [1627,1627], [1628,1628], [1629,1629], [1630,1630], [1631,1631], [1632,1632], [1709,1709], [1719,1719], [1720,1720], [1843,1843], [2813,2813], [2814,2814], [2815,2815], [2816,2816], [2817,2817], [2818,2818], [2819,2819], [2820,2820], [2821,2821], [2822,2822], [2823,2823], [2824,2824], [2825,2825], [2826,2826], [2827,2827], [2828,2828], [2829,2829], [2830,2830], [2831,2831], [2832,2832], [2833,2833], [2834,2834], [2835,2835], [2836,2836], [2837,2837], [2838,2838], [2839,2839], [2840,2840], [2841,2841], [2842,2842], [2843,2843], [2844,2844], [2845,2845], [2846,2846], [2847,2847], [2848,2848], [2849,2849], [2850,2850], [2851,2851], [2852,2852], [2853,2853], [2854,2854], [2855,2855], [2856,2856], [2857,2857], [2858,2858], [2859,2859], [2860,2860], [2861,2861], [2862,2862], [2863,2863], [2864,2864], [2865,2865], [2866,2866], [2867,2867], [2868,2868], [2869,2869], [2870,2870], [2871,2871], [2872,2872], [3139,3139], [3140,3140], [3141,3141], [3142,3142], [3143,3143], [3144,3144], [3145,3145], [3146,3146], [3147,3147], [3148,3148], [3149,3149], [3150,3150], [3151,3151], [3152,3152], [3153,3153], [3154,3154], [3155,3155], [3156,3156], [3157,3157], [3158,3158], [3386,3386], [3387,3387], [3388,3388], [3389,3389], [3390,3390], [3391,3391], [3392,3392], [3393,3393], [3394,3394], [3395,3395], [3664,3664], [3665,3665], [3666,3666], [3667,3667], [3668,3668], [3670,3670], [3671,3671], [3672,3672], [3673,3673], [3674,3674], [3676,3676], [3677,3677], [3678,3678], [3679,3679], [3680,3680], [3681,3681], [3682,3682], [3683,3683], [3684,3684], [3685,3685], [3686,3686], [3687,3687], [3688,3688], [3689,3689], [3690,3690], [3691,3691], [3692,3692], [3693,3693], [3694,3694], [3695,3695], [3696,3696], [3697,3697], [3698,3698], [3699,3699], [3700,3700], [3701,3701], [3702,3702], [3703,3703], [3704,3704], [3705,3705], [3706,3706], [3707,3707], [3708,3708], [3709,3709], [3710,3710], [3711,3711], [3712,3712], [3713,3713], [3714,3714], [3715,3715], [3960,3960], [3961,3961], [3962,3962], [3963,3963], [3964,3964], [3965,3965], [3966,3966], [3967,3967], [3968,3968], [3978,3978], [3979,3979], [3980,3980], [3981,3981], [3982,3982], [3983,3983], [3984,3984], [3985,3985], [3986,3986], [3987,3987], [4208,4208], [4209,4209], [4210,4210], [4211,4211], [4212,4212], [4304,4304], [4305,4305], [4306,4306], [4307,4307], [4308,4308], [4866,4866], [4867,4867], [4868,4868], [4869,4869], [4870,4870], [4871,4871], [4872,4872], [4873,4873], [4874,4874], [4875,4875], keep order:false, stats:pseudo - └─HashAgg(Probe) 53.00 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#32, funcs:firstrow(test.dt.ds2)->Column#34 + └─HashAgg(Probe) 53.00 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#33, funcs:firstrow(test.dt.ds2)->Column#35 └─Selection 66.25 cop[tikv] ge(test.dt.ds, 2016-09-01 00:00:00.000000), le(test.dt.ds, 2016-11-03 00:00:00.000000) └─TableRowIDScan 2650.00 cop[tikv] table:dt keep order:false, stats:pseudo explain format = 'brief' select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext, gad.t as gtime from st gad join (select id, aid, pt, dic, ip, t from dd where pt = 'android' and bm = 0 and t > 1478143908) sdk on gad.aid = sdk.aid and gad.ip = sdk.ip and sdk.t > gad.t where gad.t > 1478143908 and gad.pt = 'android' group by gad.aid, sdk.dic limit 2500; @@ -143,8 +143,8 @@ Projection 0.00 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd.d └─TableRowIDScan 10000.00 cop[tikv] table:sdk keep order:false, stats:pseudo explain format = 'brief' SELECT cm, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(1) as click_pv, count(DISTINCT ip) as click_ip FROM st WHERE (t between 1478188800 and 1478275200) and aid='cn.sbkcq' and pt='android' GROUP BY cm, p1, p2, p3, p4, p5, p6_md5, p7_md5; id estRows task access object operator info -Projection 1.00 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#20, Column#21 -└─HashAgg 1.00 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#20, funcs:count(distinct test.st.ip)->Column#21, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 +Projection 1.00 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#21, Column#22 +└─HashAgg 1.00 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#21, funcs:count(distinct test.st.ip)->Column#22, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 └─IndexLookUp 0.00 root ├─IndexRangeScan(Build) 250.00 cop[tikv] table:st, index:t(t) range:[1478188800,1478275200], keep order:false, stats:pseudo └─Selection(Probe) 0.00 cop[tikv] eq(test.st.aid, "cn.sbkcq"), eq(test.st.pt, "android") diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index 46fed25d76094..8b527a62be75c 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -115,12 +115,12 @@ PRIMARY KEY (aid,dic) load stats 's/explain_complex_stats_rr.json'; explain format = 'brief' SELECT ds, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(dic) as install_device FROM dt use index (cm) WHERE (ds >= '2016-09-01') AND (ds <= '2016-11-03') AND (cm IN ('1062', '1086', '1423', '1424', '1425', '1426', '1427', '1428', '1429', '1430', '1431', '1432', '1433', '1434', '1435', '1436', '1437', '1438', '1439', '1440', '1441', '1442', '1443', '1444', '1445', '1446', '1447', '1448', '1449', '1450', '1451', '1452', '1488', '1489', '1490', '1491', '1492', '1493', '1494', '1495', '1496', '1497', '1550', '1551', '1552', '1553', '1554', '1555', '1556', '1557', '1558', '1559', '1597', '1598', '1599', '1600', '1601', '1602', '1603', '1604', '1605', '1606', '1607', '1608', '1609', '1610', '1611', '1612', '1613', '1614', '1615', '1616', '1623', '1624', '1625', '1626', '1627', '1628', '1629', '1630', '1631', '1632', '1709', '1719', '1720', '1843', '2813', '2814', '2815', '2816', '2817', '2818', '2819', '2820', '2821', '2822', '2823', '2824', '2825', '2826', '2827', '2828', '2829', '2830', '2831', '2832', '2833', '2834', '2835', '2836', '2837', '2838', '2839', '2840', '2841', '2842', '2843', '2844', '2845', '2846', '2847', '2848', '2849', '2850', '2851', '2852', '2853', '2854', '2855', '2856', '2857', '2858', '2859', '2860', '2861', '2862', '2863', '2864', '2865', '2866', '2867', '2868', '2869', '2870', '2871', '2872', '3139', '3140', '3141', '3142', '3143', '3144', '3145', '3146', '3147', '3148', '3149', '3150', '3151', '3152', '3153', '3154', '3155', '3156', '3157', '3158', '3386', '3387', '3388', '3389', '3390', '3391', '3392', '3393', '3394', '3395', '3664', '3665', '3666', '3667', '3668', '3670', '3671', '3672', '3673', '3674', '3676', '3677', '3678', '3679', '3680', '3681', '3682', '3683', '3684', '3685', '3686', '3687', '3688', '3689', '3690', '3691', '3692', '3693', '3694', '3695', '3696', '3697', '3698', '3699', '3700', '3701', '3702', '3703', '3704', '3705', '3706', '3707', '3708', '3709', '3710', '3711', '3712', '3713', '3714', '3715', '3960', '3961', '3962', '3963', '3964', '3965', '3966', '3967', '3968', '3978', '3979', '3980', '3981', '3982', '3983', '3984', '3985', '3986', '3987', '4208', '4209', '4210', '4211', '4212', '4304', '4305', '4306', '4307', '4308', '4866', '4867', '4868', '4869', '4870', '4871', '4872', '4873', '4874', '4875')) GROUP BY ds, p1, p2, p3, p4, p5, p6_md5, p7_md5 ORDER BY ds2 DESC; id estRows task access object operator info -Projection 21.53 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#21 +Projection 21.53 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#22 └─Sort 21.53 root test.dt.ds2:desc - └─HashAgg 21.53 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#32)->Column#21, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#34)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 + └─HashAgg 21.53 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#33)->Column#22, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#35)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 └─IndexLookUp 21.53 root ├─IndexRangeScan(Build) 128.32 cop[tikv] table:dt, index:cm(cm) range:[1062,1062], [1086,1086], [1423,1423], [1424,1424], [1425,1425], [1426,1426], [1427,1427], [1428,1428], [1429,1429], [1430,1430], [1431,1431], [1432,1432], [1433,1433], [1434,1434], [1435,1435], [1436,1436], [1437,1437], [1438,1438], [1439,1439], [1440,1440], [1441,1441], [1442,1442], [1443,1443], [1444,1444], [1445,1445], [1446,1446], [1447,1447], [1448,1448], [1449,1449], [1450,1450], [1451,1451], [1452,1452], [1488,1488], [1489,1489], [1490,1490], [1491,1491], [1492,1492], [1493,1493], [1494,1494], [1495,1495], [1496,1496], [1497,1497], [1550,1550], [1551,1551], [1552,1552], [1553,1553], [1554,1554], [1555,1555], [1556,1556], [1557,1557], [1558,1558], [1559,1559], [1597,1597], [1598,1598], [1599,1599], [1600,1600], [1601,1601], [1602,1602], [1603,1603], [1604,1604], [1605,1605], [1606,1606], [1607,1607], [1608,1608], [1609,1609], [1610,1610], [1611,1611], [1612,1612], [1613,1613], [1614,1614], [1615,1615], [1616,1616], [1623,1623], [1624,1624], [1625,1625], [1626,1626], [1627,1627], [1628,1628], [1629,1629], [1630,1630], [1631,1631], [1632,1632], [1709,1709], [1719,1719], [1720,1720], [1843,1843], [2813,2813], [2814,2814], [2815,2815], [2816,2816], [2817,2817], [2818,2818], [2819,2819], [2820,2820], [2821,2821], [2822,2822], [2823,2823], [2824,2824], [2825,2825], [2826,2826], [2827,2827], [2828,2828], [2829,2829], [2830,2830], [2831,2831], [2832,2832], [2833,2833], [2834,2834], [2835,2835], [2836,2836], [2837,2837], [2838,2838], [2839,2839], [2840,2840], [2841,2841], [2842,2842], [2843,2843], [2844,2844], [2845,2845], [2846,2846], [2847,2847], [2848,2848], [2849,2849], [2850,2850], [2851,2851], [2852,2852], [2853,2853], [2854,2854], [2855,2855], [2856,2856], [2857,2857], [2858,2858], [2859,2859], [2860,2860], [2861,2861], [2862,2862], [2863,2863], [2864,2864], [2865,2865], [2866,2866], [2867,2867], [2868,2868], [2869,2869], [2870,2870], [2871,2871], [2872,2872], [3139,3139], [3140,3140], [3141,3141], [3142,3142], [3143,3143], [3144,3144], [3145,3145], [3146,3146], [3147,3147], [3148,3148], [3149,3149], [3150,3150], [3151,3151], [3152,3152], [3153,3153], [3154,3154], [3155,3155], [3156,3156], [3157,3157], [3158,3158], [3386,3386], [3387,3387], [3388,3388], [3389,3389], [3390,3390], [3391,3391], [3392,3392], [3393,3393], [3394,3394], [3395,3395], [3664,3664], [3665,3665], [3666,3666], [3667,3667], [3668,3668], [3670,3670], [3671,3671], [3672,3672], [3673,3673], [3674,3674], [3676,3676], [3677,3677], [3678,3678], [3679,3679], [3680,3680], [3681,3681], [3682,3682], [3683,3683], [3684,3684], [3685,3685], [3686,3686], [3687,3687], [3688,3688], [3689,3689], [3690,3690], [3691,3691], [3692,3692], [3693,3693], [3694,3694], [3695,3695], [3696,3696], [3697,3697], [3698,3698], [3699,3699], [3700,3700], [3701,3701], [3702,3702], [3703,3703], [3704,3704], [3705,3705], [3706,3706], [3707,3707], [3708,3708], [3709,3709], [3710,3710], [3711,3711], [3712,3712], [3713,3713], [3714,3714], [3715,3715], [3960,3960], [3961,3961], [3962,3962], [3963,3963], [3964,3964], [3965,3965], [3966,3966], [3967,3967], [3968,3968], [3978,3978], [3979,3979], [3980,3980], [3981,3981], [3982,3982], [3983,3983], [3984,3984], [3985,3985], [3986,3986], [3987,3987], [4208,4208], [4209,4209], [4210,4210], [4211,4211], [4212,4212], [4304,4304], [4305,4305], [4306,4306], [4307,4307], [4308,4308], [4866,4866], [4867,4867], [4868,4868], [4869,4869], [4870,4870], [4871,4871], [4872,4872], [4873,4873], [4874,4874], [4875,4875], keep order:false - └─HashAgg(Probe) 21.53 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#32, funcs:firstrow(test.dt.ds2)->Column#34 + └─HashAgg(Probe) 21.53 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#33, funcs:firstrow(test.dt.ds2)->Column#35 └─Selection 21.56 cop[tikv] ge(test.dt.ds, 2016-09-01 00:00:00.000000), le(test.dt.ds, 2016-11-03 00:00:00.000000) └─TableRowIDScan 128.32 cop[tikv] table:dt keep order:false explain format = 'brief' select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext, gad.t as gtime from st gad join (select id, aid, pt, dic, ip, t from dd where pt = 'android' and bm = 0 and t > 1478143908) sdk on gad.aid = sdk.aid and gad.ip = sdk.ip and sdk.t > gad.t where gad.t > 1478143908 and gad.bm = 0 and gad.pt = 'android' group by gad.aid, sdk.dic limit 2500; @@ -131,10 +131,10 @@ Projection 424.00 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd └─HashJoin 424.00 root inner join, equal:[eq(test.st.aid, test.dd.aid) eq(test.st.ip, test.dd.ip)], other cond:gt(test.dd.t, test.st.t) ├─TableReader(Build) 424.00 root data:Selection │ └─Selection 424.00 cop[tikv] eq(test.st.bm, 0), eq(test.st.pt, "android"), gt(test.st.t, 1478143908), not(isnull(test.st.ip)) - │ └─TableRangeScan 1999.00 cop[tikv] table:gad range:[0,+inf], keep order:false + │ └─TableFullScan 1999.00 cop[tikv] table:gad keep order:false └─TableReader(Probe) 455.80 root data:Selection └─Selection 455.80 cop[tikv] eq(test.dd.bm, 0), eq(test.dd.pt, "android"), gt(test.dd.t, 1478143908), not(isnull(test.dd.ip)), not(isnull(test.dd.t)) - └─TableRangeScan 2000.00 cop[tikv] table:dd range:[0,+inf], keep order:false + └─TableFullScan 2000.00 cop[tikv] table:dd keep order:false explain format = 'brief' select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext from st gad join dd sdk on gad.aid = sdk.aid and gad.dic = sdk.mac and gad.t < sdk.t where gad.t > 1477971479 and gad.bm = 0 and gad.pt = 'ios' and gad.dit = 'mac' and sdk.t > 1477971479 and sdk.bm = 0 and sdk.pt = 'ios' limit 3000; id estRows task access object operator info Projection 170.34 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd.dic, test.dd.ip, test.dd.t, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, test.st.ext @@ -142,15 +142,15 @@ Projection 170.34 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd └─IndexJoin 170.34 root inner join, inner:IndexLookUp, outer key:test.st.aid, inner key:test.dd.aid, equal cond:eq(test.st.aid, test.dd.aid), eq(test.st.dic, test.dd.mac), other cond:lt(test.st.t, test.dd.t) ├─TableReader(Build) 170.34 root data:Selection │ └─Selection 170.34 cop[tikv] eq(test.st.bm, 0), eq(test.st.dit, "mac"), eq(test.st.pt, "ios"), gt(test.st.t, 1477971479), not(isnull(test.st.dic)) - │ └─TableRangeScan 1999.00 cop[tikv] table:gad range:[0,+inf], keep order:false + │ └─TableFullScan 1999.00 cop[tikv] table:gad keep order:false └─IndexLookUp(Probe) 1.00 root ├─IndexRangeScan(Build) 3.93 cop[tikv] table:sdk, index:aid(aid, dic) range: decided by [eq(test.dd.aid, test.st.aid)], keep order:false └─Selection(Probe) 1.00 cop[tikv] eq(test.dd.bm, 0), eq(test.dd.pt, "ios"), gt(test.dd.t, 1477971479), not(isnull(test.dd.mac)), not(isnull(test.dd.t)) └─TableRowIDScan 3.93 cop[tikv] table:sdk keep order:false explain format = 'brief' SELECT cm, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(1) as click_pv, count(DISTINCT ip) as click_ip FROM st WHERE (t between 1478188800 and 1478275200) and aid='cn.sbkcq' and pt='android' GROUP BY cm, p1, p2, p3, p4, p5, p6_md5, p7_md5; id estRows task access object operator info -Projection 39.28 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#20, Column#21 -└─HashAgg 39.28 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#20, funcs:count(distinct test.st.ip)->Column#21, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 +Projection 39.28 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#21, Column#22 +└─HashAgg 39.28 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#21, funcs:count(distinct test.st.ip)->Column#22, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 └─IndexLookUp 39.38 root ├─IndexRangeScan(Build) 160.23 cop[tikv] table:st, index:t(t) range:[1478188800,1478275200], keep order:false └─Selection(Probe) 39.38 cop[tikv] eq(test.st.aid, "cn.sbkcq"), eq(test.st.pt, "android") @@ -162,7 +162,7 @@ Projection 428.32 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.d └─IndexJoin 428.32 root inner join, inner:IndexLookUp, outer key:test.dt.aid, test.dt.dic, inner key:test.rr.aid, test.rr.dic, equal cond:eq(test.dt.aid, test.rr.aid), eq(test.dt.dic, test.rr.dic) ├─TableReader(Build) 428.32 root data:Selection │ └─Selection 428.32 cop[tikv] eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592), not(isnull(test.dt.dic)) - │ └─TableRangeScan 2000.00 cop[tikv] table:dt range:[0,+inf], keep order:false + │ └─TableFullScan 2000.00 cop[tikv] table:dt keep order:false └─IndexLookUp(Probe) 1.00 root ├─IndexRangeScan(Build) 1.00 cop[tikv] table:rr, index:PRIMARY(aid, dic) range: decided by [eq(test.rr.aid, test.dt.aid) eq(test.rr.dic, test.dt.dic)], keep order:false └─Selection(Probe) 1.00 cop[tikv] eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592) diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index 0d7bc00eccddb..2f18d9590900a 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -27,9 +27,10 @@ TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c2; id estRows task access object operator info -IndexLookUp 10000.00 root -├─IndexFullScan(Build) 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:true, stats:pseudo -└─TableRowIDScan(Probe) 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection 10000.00 root test.t1.c1, test.t1.c2, test.t1.c3 +└─IndexLookUp 10000.00 root + ├─IndexFullScan(Build) 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t2 order by c2; id estRows task access object operator info Sort 10000.00 root test.t2.c2 @@ -37,24 +38,27 @@ Sort 10000.00 root test.t2.c2 └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where t1.c1 > 0; id estRows task access object operator info -TableReader 3333.33 root data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(0,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root data:Selection +└─Selection 3333.33 cop[tikv] gt(test.t1.c1, 0) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select t1.c1, t1.c2 from t1 where t1.c2 = 1; id estRows task access object operator info -IndexReader 10.00 root index:IndexRangeScan -└─IndexRangeScan 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo +IndexLookUp 10.00 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id estRows task access object operator info HashJoin 4166.67 root left outer join, equal:[eq(test.t1.c2, test.t2.c1)] -├─TableReader(Build) 3333.33 root data:TableRangeScan -│ └─TableRangeScan 3333.33 cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo +├─TableReader(Build) 3333.33 root data:Selection +│ └─Selection 3333.33 cop[tikv] gt(test.t1.c1, 1) +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) 9990.00 root data:Selection └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c1)) └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' update t1 set t1.c2 = 2 where t1.c1 = 1; id estRows task access object operator info Update N/A root N/A -└─Point_Get 1.00 root table:t1 handle:1 +└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) explain format = 'brief' delete from t1 where t1.c2 = 1; id estRows task access object operator info Delete N/A root N/A @@ -63,15 +67,15 @@ Delete N/A root N/A └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id estRows task access object operator info -Projection 9990.00 root cast(Column#8, bigint(21) BINARY)->Column#7 +Projection 9990.00 root cast(Column#9, bigint(21) BINARY)->Column#8 └─HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] - ├─HashAgg(Build) 7992.00 root group by:test.t2.c2, funcs:count(Column#9)->Column#8, funcs:firstrow(test.t2.c2)->test.t2.c2 + ├─HashAgg(Build) 7992.00 root group by:test.t2.c2, funcs:count(Column#10)->Column#9, funcs:firstrow(test.t2.c2)->test.t2.c2 │ └─TableReader 7992.00 root data:HashAgg - │ └─HashAgg 7992.00 cop[tikv] group by:test.t2.c2, funcs:count(test.t2.c2)->Column#9 + │ └─HashAgg 7992.00 cop[tikv] group by:test.t2.c2, funcs:count(test.t2.c2)->Column#10 │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 10000.00 cop[tikv] table:b keep order:false, stats:pseudo - └─TableReader(Probe) 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:a keep order:false, stats:pseudo + └─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:a, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select * from t2 order by t2.c2 limit 0, 1; id estRows task access object operator info TopN 1.00 root test.t2.c2, offset:0, count:1 @@ -80,23 +84,23 @@ TopN 1.00 root test.t2.c2, offset:0, count:1 └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where c1 > 1 and c2 = 1 and c3 < 1; id estRows task access object operator info -IndexLookUp 11.08 root -├─IndexRangeScan(Build) 33.33 cop[tikv] table:t1, index:c2(c2) range:(1 1,1 +inf], keep order:false, stats:pseudo -└─Selection(Probe) 11.08 cop[tikv] lt(test.t1.c3, 1) - └─TableRowIDScan 33.33 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexLookUp 1.11 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 1.11 cop[tikv] gt(test.t1.c1, 1), lt(test.t1.c3, 1) + └─TableRowIDScan 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where c1 = 1 and c2 > 1; id estRows task access object operator info Selection 0.33 root gt(test.t1.c2, 1) -└─Point_Get 1.00 root table:t1 handle:1 +└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#10)->Column#9 +└─Projection 10000.00 root cast(Column#8, decimal(65,0) BINARY)->Column#10 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo - └─TableReader(Probe) 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select c1 from t1 where c1 in (select c2 from t2); id estRows task access object operator info HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] @@ -104,23 +108,23 @@ HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] │ └─TableReader 9990.00 root data:Selection │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader(Probe) 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select (select count(1) k from t1 s where s.c1 = t1.c1 having k != 0) from t1; id estRows task access object operator info -Projection 10000.00 root ifnull(Column#7, 0)->Column#7 +Projection 10000.00 root ifnull(Column#9, 0)->Column#9 └─MergeJoin 10000.00 root left outer join, left key:test.t1.c1, right key:test.t1.c1 - ├─Projection(Build) 8000.00 root 1->Column#7, test.t1.c1 - │ └─TableReader 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:s keep order:true, stats:pseudo - └─TableReader(Probe) 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo + ├─Projection(Build) 8000.00 root 1->Column#9, test.t1.c1 + │ └─IndexReader 10000.00 root index:IndexFullScan + │ └─IndexFullScan 10000.00 cop[tikv] table:s, index:PRIMARY(c1) keep order:true, stats:pseudo + └─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:true, stats:pseudo explain format = 'brief' select * from information_schema.columns; id estRows task access object operator info MemTableScan 10000.00 root table:COLUMNS explain format = 'brief' select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1; id estRows task access object operator info -Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#8 +Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#9 └─Apply 10000.00 root CARTESIAN left outer join ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo @@ -131,10 +135,11 @@ Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#8 └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c1 desc limit 1; id estRows task access object operator info -Limit 1.00 root offset:0, count:1 -└─TableReader 1.00 root data:Limit - └─Limit 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan 1.00 cop[tikv] table:t1 keep order:true, desc, stats:pseudo +Projection 1.00 root test.t1.c1, test.t1.c2, test.t1.c3 +└─IndexLookUp 1.00 root limit embedded(offset:0, count:1) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexFullScan 1.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:true, desc, stats:pseudo + └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t4 use index(idx) where a > 1 and b > 1 and c > 1 limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 @@ -149,16 +154,16 @@ id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─TableReader 1.00 root data:Limit └─Limit 1.00 cop[tikv] offset:0, count:1 - └─Selection 1.00 cop[tikv] gt(test.t4.c, 1) - └─TableRangeScan 3.00 cop[tikv] table:t4 range:(1,+inf], keep order:false, stats:pseudo + └─Selection 1.00 cop[tikv] gt(test.t4.a, 1), gt(test.t4.c, 1) + └─TableFullScan 9.00 cop[tikv] table:t4 keep order:false, stats:pseudo explain format = 'brief' select ifnull(null, t1.c1) from t1; id estRows task access object operator info -TableReader 10000.00 root data:TableFullScan -└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexReader 10000.00 root index:IndexFullScan +└─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select if(10, t1.c1, t1.c2) from t1; id estRows task access object operator info -TableReader 10000.00 root data:TableFullScan -└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexReader 10000.00 root index:IndexFullScan +└─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select c1 from t2 union select c1 from t2 union all select c1 from t2; id estRows task access object operator info Union 26000.00 root @@ -187,64 +192,64 @@ HashAgg 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#10 └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo select * from information_schema.tidb_indexes where table_name='t4'; TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID IS_VISIBLE -test t4 0 PRIMARY 1 a NULL NULL 0 YES test t4 1 idx 1 a NULL NULL 1 YES test t4 1 idx 2 b NULL NULL 1 YES -test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 2 YES +test t4 0 PRIMARY 1 a NULL NULL 2 YES +test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 3 YES explain format = 'brief' select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#5 -└─StreamAgg 1.00 root funcs:firstrow(Column#9)->Column#7 +StreamAgg 1.00 root funcs:count(1)->Column#6 +└─StreamAgg 1.00 root funcs:firstrow(Column#10)->Column#8 └─TableReader 1.00 root data:StreamAgg - └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#9 + └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#10 └─Selection 10.00 cop[tikv] eq(test.t1.c3, 100) └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select 1 from (select count(c2), count(c3) from t1) k; id estRows task access object operator info -Projection 1.00 root 1->Column#6 -└─StreamAgg 1.00 root funcs:firstrow(Column#14)->Column#9 - └─TableReader 1.00 root data:StreamAgg - └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#14 - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection 1.00 root 1->Column#7 +└─StreamAgg 1.00 root funcs:firstrow(Column#18)->Column#10 + └─IndexReader 1.00 root index:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#18 + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select count(1) from (select max(c2), count(c3) as m from t1) k; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#6 -└─StreamAgg 1.00 root funcs:firstrow(Column#13)->Column#8 - └─TableReader 1.00 root data:StreamAgg - └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#13 - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +StreamAgg 1.00 root funcs:count(1)->Column#7 +└─StreamAgg 1.00 root funcs:firstrow(Column#17)->Column#9 + └─IndexReader 1.00 root index:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#17 + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select count(1) from (select count(c2) from t1 group by c3) k; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#5 -└─HashAgg 8000.00 root group by:test.t1.c3, funcs:firstrow(1)->Column#7 +StreamAgg 1.00 root funcs:count(1)->Column#6 +└─HashAgg 8000.00 root group by:test.t1.c3, funcs:firstrow(1)->Column#8 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo set @@session.tidb_opt_insubq_to_join_and_agg=0; explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#10)->Column#9 +└─Projection 10000.00 root cast(Column#8, decimal(65,0) BINARY)->Column#10 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo - └─TableReader(Probe) 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select 1 in (select c2 from t2) from t1; id estRows task access object operator info HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader(Probe) 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format = 'brief' select sum(6 in (select c2 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#12)->Column#9 +└─Projection 10000.00 root cast(Column#8, decimal(65,0) BINARY)->Column#12 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(6, test.t2.c2) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─TableReader(Probe) 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo explain format="dot" select sum(t1.c1 in (select c1 from t2)) from t1; dot contents @@ -255,14 +260,14 @@ color=black label = "root" "StreamAgg_9" -> "Projection_20" "Projection_20" -> "HashJoin_19" -"HashJoin_19" -> "TableReader_12" +"HashJoin_19" -> "IndexReader_14" "HashJoin_19" -> "IndexReader_18" } -subgraph cluster11{ +subgraph cluster13{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_11" +"IndexFullScan_13" } subgraph cluster17{ node [style=filled, color=lightgrey] @@ -270,7 +275,7 @@ color=black label = "cop" "IndexFullScan_17" } -"TableReader_12" -> "TableFullScan_11" +"IndexReader_14" -> "IndexFullScan_13" "IndexReader_18" -> "IndexFullScan_17" } @@ -282,23 +287,23 @@ subgraph cluster7{ node [style=filled, color=lightgrey] color=black label = "root" -"HashJoin_7" -> "TableReader_9" -"HashJoin_7" -> "TableReader_13" +"HashJoin_7" -> "IndexReader_13" +"HashJoin_7" -> "TableReader_15" } -subgraph cluster8{ +subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_8" +"IndexFullScan_12" } -subgraph cluster12{ +subgraph cluster14{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_12" +"TableFullScan_14" } -"TableReader_9" -> "TableFullScan_8" -"TableReader_13" -> "TableFullScan_12" +"IndexReader_13" -> "IndexFullScan_12" +"TableReader_15" -> "TableFullScan_14" } drop table if exists t1, t2, t3, t4; @@ -306,86 +311,87 @@ drop table if exists t; create table t(a int primary key, b int, c int, index idx(b)); explain format = 'brief' select t.c in (select count(*) from t s ignore index(idx), t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection 10000.00 root Column#11 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 10000.00 root Column#14 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 └─MergeJoin 12.50 root inner join, left key:test.t.a, right key:test.t.a - ├─TableReader(Build) 1.00 root data:TableRangeScan - │ └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo - └─TableReader(Probe) 1.00 root data:TableRangeScan - └─TableRangeScan 1.00 cop[tikv] table:s range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo + ├─IndexReader(Build) 10.00 root index:IndexRangeScan + │ └─IndexRangeScan 10.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo + └─IndexReader(Probe) 10.00 root index:IndexRangeScan + └─IndexRangeScan 10.00 cop[tikv] table:s, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection 10000.00 root Column#11 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 10000.00 root Column#14 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 - └─IndexJoin 12.50 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─IndexReader(Build) 10.00 root index:IndexRangeScan - │ └─IndexRangeScan 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo - └─TableReader(Probe) 1.00 root data:TableRangeScan - └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false, stats:pseudo + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─IndexJoin 12.50 root inner join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─IndexLookUp(Build) 10.00 root + │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 10.00 cop[tikv] table:s keep order:false, stats:pseudo + └─IndexReader(Probe) 1.00 root index:IndexRangeScan + └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false, stats:pseudo explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.c = t1.a) from t; id estRows task access object operator info -Projection 10000.00 root Column#11 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 10000.00 root Column#14 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 - └─IndexJoin 12.49 root inner join, inner:TableReader, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─IndexJoin 12.49 root inner join, inner:IndexReader, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) ├─IndexLookUp(Build) 9.99 root │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo │ └─Selection(Probe) 9.99 cop[tikv] not(isnull(test.t.c)) │ └─TableRowIDScan 10.00 cop[tikv] table:s keep order:false, stats:pseudo - └─TableReader(Probe) 1.00 root data:TableRangeScan - └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.c], keep order:false, stats:pseudo + └─IndexReader(Probe) 1.00 root index:IndexRangeScan + └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.c)], keep order:false, stats:pseudo insert into t values(1, 1, 1), (2, 2 ,2), (3, 3, 3), (4, 3, 4),(5,3,5); analyze table t; explain format = 'brief' select t.c in (select count(*) from t s, t t1 where s.b = t.a and s.b = 3 and s.a = t1.a) from t; id estRows task access object operator info -Projection 5.00 root Column#11 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 5.00 root Column#14 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 - └─MergeJoin 2.40 root inner join, left key:test.t.a, right key:test.t.a - ├─TableReader(Build) 4.00 root data:Selection - │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) - │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:true - └─IndexReader(Probe) 2.40 root index:Selection - └─Selection 2.40 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─HashJoin 2.40 root inner join, equal:[eq(test.t.a, test.t.a)] + ├─TableReader(Build) 2.40 root data:Selection + │ └─Selection 2.40 cop[tikv] eq(3, test.t.a), eq(test.t.b, 3) + │ └─TableFullScan 5.00 cop[tikv] table:s keep order:false + └─TableReader(Probe) 4.00 root data:Selection + └─Selection 4.00 cop[tikv] eq(3, test.t.a) + └─TableFullScan 5.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select t.c in (select count(*) from t s left join t t1 on s.a = t1.a where 3 = t.a and s.b = 3) from t; id estRows task access object operator info -Projection 5.00 root Column#11 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 5.00 root Column#14 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 - └─MergeJoin 2.40 root left outer join, left key:test.t.a, right key:test.t.a - ├─TableReader(Build) 4.00 root data:Selection - │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) - │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:true - └─IndexReader(Probe) 2.40 root index:Selection - └─Selection 2.40 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─IndexJoin 2.40 root left outer join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─TableReader(Build) 2.40 root data:Selection + │ └─Selection 2.40 cop[tikv] eq(3, test.t.a), eq(test.t.b, 3) + │ └─TableFullScan 5.00 cop[tikv] table:s keep order:false + └─IndexReader(Probe) 1.00 root index:Selection + └─Selection 1.00 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false explain format = 'brief' select t.c in (select count(*) from t s right join t t1 on s.a = t1.a where 3 = t.a and t1.b = 3) from t; id estRows task access object operator info -Projection 5.00 root Column#11 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 5.00 root Column#14 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 - └─MergeJoin 2.40 root right outer join, left key:test.t.a, right key:test.t.a - ├─TableReader(Build) 4.00 root data:Selection - │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) - │ └─TableFullScan 5.00 cop[tikv] table:s keep order:true - └─IndexReader(Probe) 2.40 root index:Selection - └─Selection 2.40 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan 3.00 cop[tikv] table:t1, index:idx(b) range:[3,3], keep order:true + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─IndexJoin 2.40 root right outer join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─TableReader(Build) 2.40 root data:Selection + │ └─Selection 2.40 cop[tikv] eq(3, test.t.a), eq(test.t.b, 3) + │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:false + └─IndexReader(Probe) 1.00 root index:Selection + └─Selection 1.00 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan 1.00 cop[tikv] table:s, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false drop table if exists t; create table t(a int unsigned); explain format = 'brief' select t.a = '123455' from t; @@ -453,12 +459,12 @@ id estRows task access object operator info TableDual 8000.00 root rows:0 explain format = 'brief' select null or a > 1 from t; id estRows task access object operator info -Projection 10000.00 root or(, gt(test.t.a, 1))->Column#2 -└─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +Projection 10000.00 root or(, gt(test.t.a, 1))->Column#3 +└─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t, index:PRIMARY(a) keep order:false, stats:pseudo explain format = 'brief' select * from t where a = 1 for update; id estRows task access object operator info -Point_Get 1.00 root table:t handle:1, lock +Point_Get 1.00 root table:t, index:PRIMARY(a) lock drop table if exists ta, tb; create table ta (a varchar(20)); create table tb (a varchar(20)); @@ -497,10 +503,10 @@ PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; explain format = 'brief' SELECT COUNT(1) FROM (SELECT COALESCE(b.region_name, '不详') region_name, SUM(a.registration_num) registration_num FROM (SELECT stat_date, show_date, region_id, 0 registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202 UNION ALL SELECT stat_date, show_date, region_id, registration_num registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202) a LEFT JOIN test02 b ON a.region_id = b.id WHERE registration_num > 0 AND a.stat_date >= '20191202' AND a.stat_date <= '20191202' GROUP BY a.stat_date , a.show_date , COALESCE(b.region_name, '不详') ) JLS; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#22 -└─HashAgg 8000.00 root group by:Column#32, Column#33, Column#34, funcs:firstrow(1)->Column#31 - └─Projection 10000.01 root Column#14, Column#15, coalesce(test.test02.region_name, 不详)->Column#34 - └─HashJoin 10000.01 root left outer join, equal:[eq(Column#16, test.test02.id)] +StreamAgg 1.00 root funcs:count(1)->Column#25 +└─HashAgg 8000.00 root group by:Column#38, Column#39, Column#40, funcs:firstrow(1)->Column#34 + └─Projection 10000.01 root Column#16, Column#17, coalesce(test.test02.region_name, 不详)->Column#40 + └─HashJoin 10000.01 root left outer join, equal:[eq(Column#18, test.test02.id)] ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:b keep order:false, stats:pseudo └─Union(Probe) 8000.01 root @@ -687,8 +693,7 @@ insert into t values (1, 1); explain format = 'brief' update t set j = -j where i = 1 and j = 1; id estRows task access object operator info Update N/A root N/A -└─Selection 1.00 root eq(test.t.j, 1) - └─Point_Get 1.00 root table:t handle:1 +└─Point_Get 1.00 root table:t, index:i(i, j) rollback; drop table if exists t; create table t(a int); diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index 92eee10bfc47c..9af4317aea632 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -28,9 +28,10 @@ TableReader 1999.00 root data:TableFullScan └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from t1 order by c2; id estRows task access object operator info -IndexLookUp 1999.00 root -├─IndexFullScan(Build) 1999.00 cop[tikv] table:t1, index:c2(c2) keep order:true -└─TableRowIDScan(Probe) 1999.00 cop[tikv] table:t1 keep order:false +Projection 1999.00 root test.t1.c1, test.t1.c2, test.t1.c3 +└─IndexLookUp 1999.00 root + ├─IndexFullScan(Build) 1999.00 cop[tikv] table:t1, index:c2(c2) keep order:true + └─TableRowIDScan(Probe) 1999.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from t2 order by c2; id estRows task access object operator info Sort 1985.00 root test.t2.c2 @@ -38,24 +39,27 @@ Sort 1985.00 root test.t2.c2 └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false explain format = 'brief' select * from t1 where t1.c1 > 0; id estRows task access object operator info -TableReader 1999.00 root data:TableRangeScan -└─TableRangeScan 1999.00 cop[tikv] table:t1 range:(0,+inf], keep order:false +TableReader 1999.00 root data:Selection +└─Selection 1999.00 cop[tikv] gt(test.t1.c1, 0) + └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select t1.c1, t1.c2 from t1 where t1.c2 = 1; id estRows task access object operator info -IndexReader 0.00 root index:IndexRangeScan -└─IndexRangeScan 0.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false +IndexLookUp 0.00 root +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id estRows task access object operator info HashJoin 2481.25 root left outer join, equal:[eq(test.t1.c2, test.t2.c1)] ├─TableReader(Build) 1985.00 root data:Selection │ └─Selection 1985.00 cop[tikv] not(isnull(test.t2.c1)) │ └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false -└─TableReader(Probe) 1998.00 root data:TableRangeScan - └─TableRangeScan 1998.00 cop[tikv] table:t1 range:(1,+inf], keep order:false +└─TableReader(Probe) 1998.00 root data:Selection + └─Selection 1998.00 cop[tikv] gt(test.t1.c1, 1) + └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false explain format = 'brief' update t1 set t1.c2 = 2 where t1.c1 = 1; id estRows task access object operator info Update N/A root N/A -└─Point_Get 1.00 root table:t1 handle:1 +└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) explain format = 'brief' delete from t1 where t1.c2 = 1; id estRows task access object operator info Delete N/A root N/A @@ -64,14 +68,14 @@ Delete N/A root N/A └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id estRows task access object operator info -Projection 1985.00 root cast(Column#8, bigint(21) BINARY)->Column#7 +Projection 1985.00 root cast(Column#9, bigint(21) BINARY)->Column#8 └─HashJoin 1985.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] - ├─HashAgg(Build) 1985.00 root group by:test.t2.c2, funcs:count(test.t2.c2)->Column#8, funcs:firstrow(test.t2.c2)->test.t2.c2 + ├─HashAgg(Build) 1985.00 root group by:test.t2.c2, funcs:count(test.t2.c2)->Column#9, funcs:firstrow(test.t2.c2)->test.t2.c2 │ └─TableReader 1985.00 root data:Selection │ └─Selection 1985.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 1985.00 cop[tikv] table:b keep order:false - └─TableReader(Probe) 1999.00 root data:TableFullScan - └─TableFullScan 1999.00 cop[tikv] table:a keep order:false + └─IndexReader(Probe) 1999.00 root index:IndexFullScan + └─IndexFullScan 1999.00 cop[tikv] table:a, index:PRIMARY(c1) keep order:false explain format = 'brief' select * from t2 order by t2.c2 limit 0, 1; id estRows task access object operator info TopN 1.00 root test.t2.c2, offset:0, count:1 @@ -81,13 +85,13 @@ TopN 1.00 root test.t2.c2, offset:0, count:1 explain format = 'brief' select * from t1 where c1 > 1 and c2 = 1 and c3 < 1; id estRows task access object operator info IndexLookUp 0.00 root -├─IndexRangeScan(Build) 0.00 cop[tikv] table:t1, index:c2(c2) range:(1 1,1 +inf], keep order:false -└─Selection(Probe) 0.00 cop[tikv] lt(test.t1.c3, 1) +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false +└─Selection(Probe) 0.00 cop[tikv] gt(test.t1.c1, 1), lt(test.t1.c3, 1) └─TableRowIDScan 0.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from t1 where c1 = 1 and c2 > 1; id estRows task access object operator info Selection 0.50 root gt(test.t1.c2, 1) -└─Point_Get 1.00 root table:t1 handle:1 +└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) explain format = 'brief' select c1 from t1 where c1 in (select c2 from t2); id estRows task access object operator info HashJoin 1985.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] @@ -95,14 +99,14 @@ HashJoin 1985.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] │ └─TableReader 1985.00 root data:Selection │ └─Selection 1985.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false -└─TableReader(Probe) 1999.00 root data:TableFullScan - └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false +└─IndexReader(Probe) 1999.00 root index:IndexFullScan + └─IndexFullScan 1999.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false explain format = 'brief' select * from information_schema.columns; id estRows task access object operator info MemTableScan 10000.00 root table:COLUMNS explain format = 'brief' select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1; id estRows task access object operator info -Projection 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#8 +Projection 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#9 └─Apply 1999.00 root CARTESIAN left outer join ├─TableReader(Build) 1999.00 root data:TableFullScan │ └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false @@ -113,18 +117,19 @@ Projection 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#8 └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c1 desc limit 1; id estRows task access object operator info -Limit 1.00 root offset:0, count:1 -└─TableReader 1.00 root data:Limit - └─Limit 1.00 cop[tikv] offset:0, count:1 - └─TableFullScan 1.00 cop[tikv] table:t1 keep order:true, desc +Projection 1.00 root test.t1.c1, test.t1.c2, test.t1.c3 +└─IndexLookUp 1.00 root limit embedded(offset:0, count:1) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexFullScan 1.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:true, desc + └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo set @@session.tidb_opt_insubq_to_join_and_agg=0; explain format = 'brief' select 1 in (select c2 from t2) from t1; id estRows task access object operator info HashJoin 1999.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) ├─TableReader(Build) 1985.00 root data:TableFullScan │ └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false -└─TableReader(Probe) 1999.00 root data:TableFullScan - └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false +└─IndexReader(Probe) 1999.00 root index:IndexFullScan + └─IndexFullScan 1999.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false explain format="dot" select 1 in (select c2 from t2) from t1; dot contents @@ -133,23 +138,23 @@ subgraph cluster7{ node [style=filled, color=lightgrey] color=black label = "root" -"HashJoin_7" -> "TableReader_9" -"HashJoin_7" -> "TableReader_13" +"HashJoin_7" -> "IndexReader_13" +"HashJoin_7" -> "TableReader_15" } -subgraph cluster8{ +subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_8" +"IndexFullScan_12" } -subgraph cluster12{ +subgraph cluster14{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_12" +"TableFullScan_14" } -"TableReader_9" -> "TableFullScan_8" -"TableReader_13" -> "TableFullScan_12" +"IndexReader_13" -> "IndexFullScan_12" +"TableReader_15" -> "TableFullScan_14" } explain format = 'brief' select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 LIMIT 1; diff --git a/cmd/explaintest/r/explain_indexmerge.result b/cmd/explaintest/r/explain_indexmerge.result index 4a048b40da7f7..2abce3c9e76ba 100644 --- a/cmd/explaintest/r/explain_indexmerge.result +++ b/cmd/explaintest/r/explain_indexmerge.result @@ -22,17 +22,19 @@ TableReader 98.00 root data:Selection set session tidb_enable_index_merge = on; explain format = 'brief' select * from t where a < 50 or b < 50; id estRows task access object operator info -IndexMerge 98.00 root -├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false -├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false -└─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false +Projection 98.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 98.00 root + ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false + ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false + └─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where (a < 50 or b < 50) and f > 100; id estRows task access object operator info -IndexMerge 98.00 root -├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false -├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false -└─Selection(Probe) 98.00 cop[tikv] gt(test.t.f, 100) - └─TableRowIDScan 98.00 cop[tikv] table:t keep order:false +Projection 98.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 98.00 root + ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false + ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false + └─Selection(Probe) 98.00 cop[tikv] gt(test.t.f, 100) + └─TableRowIDScan 98.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where a < 50 or b < 5000000; id estRows task access object operator info TableReader 4999999.00 root data:Selection @@ -40,10 +42,11 @@ TableReader 4999999.00 root data:Selection └─TableFullScan 5000000.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where b < 50 or c < 50; id estRows task access object operator info -IndexMerge 98.00 root -├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false -├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false -└─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false +Projection 98.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 98.00 root + ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false + ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false + └─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where b < 50 or c < 5000000; id estRows task access object operator info TableReader 4999999.00 root data:Selection @@ -51,33 +54,35 @@ TableReader 4999999.00 root data:Selection └─TableFullScan 5000000.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where a < 50 or b < 50 or c < 50; id estRows task access object operator info -IndexMerge 147.00 root -├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false -├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false -├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false -└─TableRowIDScan(Probe) 147.00 cop[tikv] table:t keep order:false +Projection 147.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 147.00 root + ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false + ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false + ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false + └─TableRowIDScan(Probe) 147.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10; id estRows task access object operator info -IndexMerge 0.00 root -├─TableRangeScan(Build) 9.00 cop[tikv] table:t range:[-inf,10), keep order:false -├─IndexRangeScan(Build) 9.00 cop[tikv] table:t, index:td(d) range:[-inf,10), keep order:false -└─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.b, 10000), lt(test.t.c, 10000)) - └─TableRowIDScan 18.00 cop[tikv] table:t keep order:false +Projection 0.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 0.00 root + ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tb(b) range:[-inf,10000), keep order:false + ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tc(c) range:[-inf,10000), keep order:false + └─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.a, 10), lt(test.t.d, 10)) + └─TableRowIDScan 19978.00 cop[tikv] table:t keep order:false explain format="dot" select * from t where (a < 50 or b < 50) and f > 100; dot contents -digraph IndexMerge_12 { -subgraph cluster12{ +digraph Projection_4 { +subgraph cluster4{ node [style=filled, color=lightgrey] color=black label = "root" -"IndexMerge_12" +"Projection_4" -> "IndexMerge_12" } subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableRangeScan_8" +"IndexRangeScan_8" } subgraph cluster9{ node [style=filled, color=lightgrey] @@ -91,7 +96,7 @@ color=black label = "cop" "Selection_11" -> "TableRowIDScan_10" } -"IndexMerge_12" -> "TableRangeScan_8" +"IndexMerge_12" -> "IndexRangeScan_8" "IndexMerge_12" -> "IndexRangeScan_9" "IndexMerge_12" -> "Selection_11" } @@ -99,24 +104,27 @@ label = "cop" set session tidb_enable_index_merge = off; explain format = 'brief' select /*+ use_index_merge(t, primary, tb, tc) */ * from t where a <= 500000 or b <= 1000000 or c <= 3000000; id estRows task access object operator info -IndexMerge 3560000.00 root -├─TableRangeScan(Build) 500000.00 cop[tikv] table:t range:[-inf,500000], keep order:false -├─IndexRangeScan(Build) 1000000.00 cop[tikv] table:t, index:tb(b) range:[-inf,1000000], keep order:false -├─IndexRangeScan(Build) 3000000.00 cop[tikv] table:t, index:tc(c) range:[-inf,3000000], keep order:false -└─TableRowIDScan(Probe) 3560000.00 cop[tikv] table:t keep order:false +Projection 3560000.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 3560000.00 root + ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,500000], keep order:false + ├─IndexRangeScan(Build) 1000000.00 cop[tikv] table:t, index:tb(b) range:[-inf,1000000], keep order:false + ├─IndexRangeScan(Build) 3000000.00 cop[tikv] table:t, index:tc(c) range:[-inf,3000000], keep order:false + └─TableRowIDScan(Probe) 3560000.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, tb, tc) */ * from t where b < 50 or c < 5000000; id estRows task access object operator info -IndexMerge 4999999.00 root -├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false -├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tc(c) range:[-inf,5000000), keep order:false -└─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false +Projection 4999999.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 4999999.00 root + ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false + ├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tc(c) range:[-inf,5000000), keep order:false + └─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, tb, tc) */ * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10; id estRows task access object operator info -IndexMerge 0.00 root -├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tb(b) range:[-inf,10000), keep order:false -├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tc(c) range:[-inf,10000), keep order:false -└─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.a, 10), lt(test.t.d, 10)) - └─TableRowIDScan 19978.00 cop[tikv] table:t keep order:false +Projection 0.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 0.00 root + ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tb(b) range:[-inf,10000), keep order:false + ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tc(c) range:[-inf,10000), keep order:false + └─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.a, 10), lt(test.t.d, 10)) + └─TableRowIDScan 19978.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, tb) */ * from t where b < 50 or c < 5000000; id estRows task access object operator info TableReader 4999999.00 root data:Selection @@ -129,10 +137,11 @@ TableReader 4999999.00 root data:Selection └─TableFullScan 5000000.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, primary, tb) */ * from t where a < 50 or b < 5000000; id estRows task access object operator info -IndexMerge 4999999.00 root -├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false -├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tb(b) range:[-inf,5000000), keep order:false -└─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false +Projection 4999999.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f +└─IndexMerge 4999999.00 root + ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false + ├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tb(b) range:[-inf,5000000), keep order:false + └─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false set session tidb_enable_index_merge = on; drop table if exists t; CREATE TABLE t ( @@ -146,7 +155,8 @@ KEY `aid_c2` (`aid`,`c2`) ); desc select /*+ USE_INDEX_MERGE(t, aid_c1, aid_c2) */ * from t where (aid = 1 and c1='aaa') or (aid = 2 and c2='bbb'); id estRows task access object operator info -IndexMerge_8 269.49 root -├─IndexRangeScan_5(Build) 0.10 cop[tikv] table:t, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo -├─IndexRangeScan_6(Build) 0.10 cop[tikv] table:t, index:aid_c2(aid, c2) range:[2 "bbb",2 "bbb"], keep order:false, stats:pseudo -└─TableRowIDScan_7(Probe) 269.49 cop[tikv] table:t keep order:false, stats:pseudo +Projection_4 8.08 root test.t.id, test.t.aid, test.t.c1, test.t.c2 +└─IndexMerge_8 269.49 root + ├─IndexRangeScan_5(Build) 0.10 cop[tikv] table:t, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo + ├─IndexRangeScan_6(Build) 0.10 cop[tikv] table:t, index:aid_c2(aid, c2) range:[2 "bbb",2 "bbb"], keep order:false, stats:pseudo + └─TableRowIDScan_7(Probe) 269.49 cop[tikv] table:t keep order:false, stats:pseudo diff --git a/cmd/explaintest/r/explain_join_stats.result b/cmd/explaintest/r/explain_join_stats.result index 15e68179c5085..7a32346ea4673 100644 --- a/cmd/explaintest/r/explain_join_stats.result +++ b/cmd/explaintest/r/explain_join_stats.result @@ -6,20 +6,20 @@ create table lo(a int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (a)) ENGINE=InnoD load stats 's/explain_join_stats_lo.json'; explain format = 'brief' select count(*) from e, lo where lo.a=e.a and e.b=22336; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#5 +StreamAgg 1.00 root funcs:count(1)->Column#6 └─HashJoin 19977.00 root inner join, equal:[eq(test.lo.a, test.e.a)] - ├─TableReader(Build) 250.00 root data:TableFullScan - │ └─TableFullScan 250.00 cop[tikv] table:lo keep order:false + ├─IndexReader(Build) 250.00 root index:IndexFullScan + │ └─IndexFullScan 250.00 cop[tikv] table:lo, index:PRIMARY(a) keep order:false └─IndexLookUp(Probe) 19977.00 root ├─IndexRangeScan(Build) 19977.00 cop[tikv] table:e, index:idx_b(b) range:[22336,22336], keep order:false └─Selection(Probe) 19977.00 cop[tikv] not(isnull(test.e.a)) └─TableRowIDScan 19977.00 cop[tikv] table:e keep order:false explain format = 'brief' select /*+ TIDB_INLJ(e) */ count(*) from e, lo where lo.a=e.a and e.b=22336; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#5 +StreamAgg 1.00 root funcs:count(1)->Column#6 └─IndexJoin 19977.00 root inner join, inner:IndexLookUp, outer key:test.lo.a, inner key:test.e.a, equal cond:eq(test.lo.a, test.e.a) - ├─TableReader(Build) 250.00 root data:TableFullScan - │ └─TableFullScan 250.00 cop[tikv] table:lo keep order:false + ├─IndexReader(Build) 250.00 root index:IndexFullScan + │ └─IndexFullScan 250.00 cop[tikv] table:lo, index:PRIMARY(a) keep order:false └─IndexLookUp(Probe) 79.91 root ├─Selection(Build) 4080.00 cop[tikv] not(isnull(test.e.a)) │ └─IndexRangeScan 4080.00 cop[tikv] table:e, index:idx_a(a) range: decided by [eq(test.e.a, test.lo.a)], keep order:false diff --git a/cmd/explaintest/r/partition_pruning.result b/cmd/explaintest/r/partition_pruning.result index b3c3a8b3169b9..c306f188eff22 100644 --- a/cmd/explaintest/r/partition_pruning.result +++ b/cmd/explaintest/r/partition_pruning.result @@ -16,16 +16,16 @@ PARTITION max VALUES LESS THAN MAXVALUE); INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8); explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo explain format = 'brief' SELECT * FROM t1 WHERE a < 7; id estRows task access object operator info -TableReader 3333.33 root partition:all data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,7), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:all index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,7), keep order:false, stats:pseudo explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo DROP TABLE t1; # # Bug#49742: Partition Pruning not working correctly for RANGE @@ -46,8 +46,8 @@ a 0 explain format = 'brief' SELECT * FROM t1 WHERE a < 1; id estRows task access object operator info -TableReader 3333.33 root partition:p0 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 2 order by a; a -1 @@ -55,8 +55,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a < 2; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 3 order by a; a -1 @@ -65,8 +65,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a < 3; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 4 order by a; a -1 @@ -76,8 +76,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a < 4; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 5 order by a; a -1 @@ -88,8 +88,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a < 5; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 6 order by a; a -1 @@ -101,8 +101,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a < 6; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3,p4,p5 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3,p4,p5 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 7 order by a; a -1 @@ -115,8 +115,8 @@ a 6 explain format = 'brief' SELECT * FROM t1 WHERE a < 7; id estRows task access object operator info -TableReader 3333.33 root partition:all data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,7), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:all index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,7), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 1 order by a; a -1 @@ -124,8 +124,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 2 order by a; a -1 @@ -134,8 +134,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a <= 2; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 3 order by a; a -1 @@ -145,8 +145,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a <= 3; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 4 order by a; a -1 @@ -157,8 +157,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a <= 4; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 5 order by a; a -1 @@ -170,8 +170,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a <= 5; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3,p4,p5 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3,p4,p5 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 6 order by a; a -1 @@ -184,8 +184,8 @@ a 6 explain format = 'brief' SELECT * FROM t1 WHERE a <= 6; id estRows task access object operator info -TableReader 3333.33 root partition:all data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:all index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 7 order by a; a -1 @@ -199,57 +199,57 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a <= 7; id estRows task access object operator info -TableReader 3333.33 root partition:all data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,7], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:all index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,7], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 1 order by a; a 1 explain format = 'brief' SELECT * FROM t1 WHERE a = 1; id estRows task access object operator info -TableReader 1.00 root partition:p1 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[1,1], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p1 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[1,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 2 order by a; a 2 explain format = 'brief' SELECT * FROM t1 WHERE a = 2; id estRows task access object operator info -TableReader 1.00 root partition:p2 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[2,2], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p2 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[2,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 3 order by a; a 3 explain format = 'brief' SELECT * FROM t1 WHERE a = 3; id estRows task access object operator info -TableReader 1.00 root partition:p3 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[3,3], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p3 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[3,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 4 order by a; a 4 explain format = 'brief' SELECT * FROM t1 WHERE a = 4; id estRows task access object operator info -TableReader 1.00 root partition:p4 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[4,4], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p4 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[4,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 5 order by a; a 5 explain format = 'brief' SELECT * FROM t1 WHERE a = 5; id estRows task access object operator info -TableReader 1.00 root partition:p5 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[5,5], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p5 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[5,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 6 order by a; a 6 explain format = 'brief' SELECT * FROM t1 WHERE a = 6; id estRows task access object operator info -TableReader 1.00 root partition:max data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[6,6], keep order:false, stats:pseudo +IndexReader 1.00 root partition:max index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[6,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 7 order by a; a 7 explain format = 'brief' SELECT * FROM t1 WHERE a = 7; id estRows task access object operator info -TableReader 1.00 root partition:max data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[7,7], keep order:false, stats:pseudo +IndexReader 1.00 root partition:max index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[7,7], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 1 order by a; a 1 @@ -262,8 +262,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 1; id estRows task access object operator info -TableReader 3333.33 root partition:p1,p2,p3,p4,p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[1,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p1,p2,p3,p4,p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 2 order by a; a 2 @@ -275,8 +275,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 2; id estRows task access object operator info -TableReader 3333.33 root partition:p2,p3,p4,p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[2,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p2,p3,p4,p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 3 order by a; a 3 @@ -287,8 +287,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 3; id estRows task access object operator info -TableReader 3333.33 root partition:p3,p4,p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[3,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p3,p4,p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 4 order by a; a 4 @@ -298,8 +298,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 4; id estRows task access object operator info -TableReader 3333.33 root partition:p4,p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[4,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p4,p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 5 order by a; a 5 @@ -308,8 +308,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 5; id estRows task access object operator info -TableReader 3333.33 root partition:p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[5,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 6 order by a; a 6 @@ -317,16 +317,16 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 6; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[6,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[6,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 7 order by a; a 7 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 7; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[7,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[7,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 1 order by a; a 2 @@ -338,8 +338,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 1; id estRows task access object operator info -TableReader 3333.33 root partition:p2,p3,p4,p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p2,p3,p4,p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 2 order by a; a 3 @@ -350,8 +350,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 2; id estRows task access object operator info -TableReader 3333.33 root partition:p3,p4,p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(2,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p3,p4,p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 3 order by a; a 4 @@ -361,8 +361,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 3; id estRows task access object operator info -TableReader 3333.33 root partition:p4,p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(3,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p4,p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 4 order by a; a 5 @@ -371,8 +371,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 4; id estRows task access object operator info -TableReader 3333.33 root partition:p5,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(4,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p5,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 5 order by a; a 6 @@ -380,23 +380,23 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 5; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(5,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 6 order by a; a 7 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 6; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(6,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(6,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 7 order by a; a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 7; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(7,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(7,+inf], keep order:false, stats:pseudo DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY) PARTITION BY RANGE (a) ( @@ -413,8 +413,8 @@ a 0 explain format = 'brief' SELECT * FROM t1 WHERE a < 1; id estRows task access object operator info -TableReader 3333.33 root partition:p0 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 2 order by a; a -1 @@ -422,8 +422,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a < 2; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 3 order by a; a -1 @@ -432,8 +432,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a < 3; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 4 order by a; a -1 @@ -443,8 +443,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a < 4; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 5 order by a; a -1 @@ -455,8 +455,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a < 5; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 6 order by a; a -1 @@ -468,8 +468,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a < 6; id estRows task access object operator info -TableReader 3333.33 root partition:all data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6), keep order:false, stats:pseudo +IndexReader 3323.33 root partition:all index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 1 order by a; a -1 @@ -477,8 +477,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 2 order by a; a -1 @@ -487,8 +487,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a <= 2; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 3 order by a; a -1 @@ -498,8 +498,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a <= 3; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 4 order by a; a -1 @@ -510,8 +510,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a <= 4; id estRows task access object operator info -TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 5 order by a; a -1 @@ -523,8 +523,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a <= 5; id estRows task access object operator info -TableReader 3333.33 root partition:all data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:all index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 6 order by a; a -1 @@ -537,50 +537,50 @@ a 6 explain format = 'brief' SELECT * FROM t1 WHERE a <= 6; id estRows task access object operator info -TableReader 3333.33 root partition:all data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6], keep order:false, stats:pseudo +IndexReader 3323.33 root partition:all index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 1; a 1 explain format = 'brief' SELECT * FROM t1 WHERE a = 1; id estRows task access object operator info -TableReader 1.00 root partition:p1 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[1,1], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p1 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[1,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 2; a 2 explain format = 'brief' SELECT * FROM t1 WHERE a = 2; id estRows task access object operator info -TableReader 1.00 root partition:p2 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[2,2], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p2 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[2,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 3; a 3 explain format = 'brief' SELECT * FROM t1 WHERE a = 3; id estRows task access object operator info -TableReader 1.00 root partition:p3 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[3,3], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p3 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[3,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 4; a 4 explain format = 'brief' SELECT * FROM t1 WHERE a = 4; id estRows task access object operator info -TableReader 1.00 root partition:p4 data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[4,4], keep order:false, stats:pseudo +IndexReader 1.00 root partition:p4 index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[4,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 5; a 5 explain format = 'brief' SELECT * FROM t1 WHERE a = 5; id estRows task access object operator info -TableReader 1.00 root partition:max data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[5,5], keep order:false, stats:pseudo +IndexReader 1.00 root partition:max index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[5,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 6; a 6 explain format = 'brief' SELECT * FROM t1 WHERE a = 6; id estRows task access object operator info -TableReader 1.00 root partition:max data:TableRangeScan -└─TableRangeScan 1.00 cop[tikv] table:t1 range:[6,6], keep order:false, stats:pseudo +IndexReader 1.00 root partition:max index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[6,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 1 order by a; a 1 @@ -592,8 +592,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 1; id estRows task access object operator info -TableReader 3333.33 root partition:p1,p2,p3,p4,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[1,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p1,p2,p3,p4,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 2 order by a; a 2 @@ -604,8 +604,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 2; id estRows task access object operator info -TableReader 3333.33 root partition:p2,p3,p4,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[2,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p2,p3,p4,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 3 order by a; a 3 @@ -615,8 +615,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 3; id estRows task access object operator info -TableReader 3333.33 root partition:p3,p4,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[3,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p3,p4,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 4 order by a; a 4 @@ -625,8 +625,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 4; id estRows task access object operator info -TableReader 3333.33 root partition:p4,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[4,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p4,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 5 order by a; a 5 @@ -634,16 +634,16 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 5; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[5,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 6 order by a; a 6 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 6; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[6,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[6,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 1 order by a; a 2 @@ -654,8 +654,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 1; id estRows task access object operator info -TableReader 3333.33 root partition:p2,p3,p4,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p2,p3,p4,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 2 order by a; a 3 @@ -665,8 +665,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 2; id estRows task access object operator info -TableReader 3333.33 root partition:p3,p4,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(2,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p3,p4,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 3 order by a; a 4 @@ -675,8 +675,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 3; id estRows task access object operator info -TableReader 3333.33 root partition:p4,max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(3,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:p4,max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 4 order by a; a 5 @@ -684,23 +684,23 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 4; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(4,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 5 order by a; a 6 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 5; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(5,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 6 order by a; a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 6; id estRows task access object operator info -TableReader 3333.33 root partition:max data:TableRangeScan -└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(6,+inf], keep order:false, stats:pseudo +IndexReader 3333.33 root partition:max index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(6,+inf], keep order:false, stats:pseudo DROP TABLE t1; # test of RANGE and index CREATE TABLE t1 (a DATE, KEY(a)) diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index 902834b9c3ef3..78b52d24920cd 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -242,9 +242,10 @@ insert into t1 values(9, 10, 11); explain format = 'brief' select a, c from t1 use index(idx) order by a limit 5; id estRows task access object operator info TopN 5.00 root test.t1.a, offset:0, count:5 -└─IndexReader 5.00 root index:TopN - └─TopN 5.00 cop[tikv] test.t1.a, offset:0, count:5 - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:idx(b, c) keep order:false, stats:pseudo +└─IndexLookUp 5.00 root + ├─IndexFullScan(Build) 10000.00 cop[tikv] table:t1, index:idx(b, c) keep order:false, stats:pseudo + └─TopN(Probe) 5.00 cop[tikv] test.t1.a, offset:0, count:5 + └─TableRowIDScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo select c, a from t1 use index(idx) order by a limit 5; c a 3 1 @@ -344,10 +345,10 @@ drop table if exists t; create table t(a bigint primary key, b bigint); desc select * from t where a = 1; id estRows task access object operator info -Point_Get_1 1.00 root table:t handle:1 +Point_Get_1 1.00 root table:t, index:PRIMARY(a) desc select * from t where a = '1'; id estRows task access object operator info -Point_Get_1 1.00 root table:t handle:1 +Point_Get_1 1.00 root table:t, index:PRIMARY(a) desc select sysdate(), sleep(1), sysdate(); id estRows task access object operator info Projection_3 1.00 root sysdate()->Column#1, sleep(1)->Column#2, sysdate()->Column#3 @@ -467,11 +468,11 @@ PRIMARY KEY (`id`) ); explain format = 'brief' select row_number() over( partition by i ) - x as rnk from t; id estRows task access object operator info -Projection 10000.00 root minus(Column#5, test.t.x)->Column#7 -└─Window 10000.00 root row_number()->Column#5 over(partition by test.t.i) +Projection 10000.00 root minus(Column#6, test.t.x)->Column#8 +└─Window 10000.00 root row_number()->Column#6 over(partition by test.t.i) └─Sort 10000.00 root test.t.i - └─TableReader 10000.00 root data:TableRangeScan - └─TableRangeScan 10000.00 cop[tikv] table:t range:[0,+inf], keep order:false, stats:pseudo + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo create table precise_types ( a BIGINT UNSIGNED NOT NULL, b BIGINT NOT NULL, diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index 50c83dc1800f6..524a9effab119 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -17,16 +17,17 @@ insert into t values(1,1,1,1),(2,2,2,2),(3,2,2,2),(4,2,2,2),(5,2,2,2); analyze table t; explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c = 1 and s.d = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection 5.00 root Column#14 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 5.00 root Column#17 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 - └─IndexJoin 0.50 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─IndexReader(Build) 1.00 root index:IndexRangeScan - │ └─IndexRangeScan 1.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) eq(test.t.c, 1) eq(test.t.d, test.t.a)], keep order:false - └─TableReader(Probe) 1.00 root data:TableRangeScan - └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 + └─IndexJoin 0.50 root inner join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─IndexLookUp(Build) 1.00 root + │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) eq(test.t.c, 1) eq(test.t.d, test.t.a)], keep order:false + │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:s keep order:false + └─IndexReader(Probe) 1.00 root index:IndexRangeScan + └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false drop table if exists t; create table t(a int, b int, c int); explain format = 'brief' select a from t t1 where t1.a = (select max(t2.a) from t t2 where t1.b=t2.b and t1.c=t2.b); diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index bb6a2e6201ee0..230157b450607 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -185,7 +185,7 @@ id estRows task access object operator info Projection 100.00 root tpch.supplier.s_acctbal, tpch.supplier.s_name, tpch.nation.n_name, tpch.part.p_partkey, tpch.part.p_mfgr, tpch.supplier.s_address, tpch.supplier.s_phone, tpch.supplier.s_comment └─TopN 100.00 root tpch.supplier.s_acctbal:desc, tpch.nation.n_name, tpch.supplier.s_name, tpch.part.p_partkey, offset:0, count:100 └─Projection 155496.00 root tpch.part.p_partkey, tpch.part.p_mfgr, tpch.supplier.s_name, tpch.supplier.s_address, tpch.supplier.s_phone, tpch.supplier.s_acctbal, tpch.supplier.s_comment, tpch.nation.n_name - └─HashJoin 155496.00 root inner join, equal:[eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) eq(tpch.partsupp.ps_supplycost, Column#50)] + └─HashJoin 155496.00 root inner join, equal:[eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) eq(tpch.partsupp.ps_supplycost, Column#57)] ├─HashJoin(Build) 155496.00 root inner join, equal:[eq(tpch.partsupp.ps_partkey, tpch.part.p_partkey)] │ ├─TableReader(Build) 155496.00 root data:Selection │ │ └─Selection 155496.00 cop[tikv] eq(tpch.part.p_size, 30), like(tpch.part.p_type, "%STEEL", 92) @@ -202,8 +202,8 @@ Projection 100.00 root tpch.supplier.s_acctbal, tpch.supplier.s_name, tpch.nati │ │ └─TableFullScan 500000.00 cop[tikv] table:supplier keep order:false │ └─TableReader(Probe) 40000000.00 root data:TableFullScan │ └─TableFullScan 40000000.00 cop[tikv] table:partsupp keep order:false - └─Selection(Probe) 6524008.35 root not(isnull(Column#50)) - └─HashAgg 8155010.44 root group by:tpch.partsupp.ps_partkey, funcs:min(tpch.partsupp.ps_supplycost)->Column#50, funcs:firstrow(tpch.partsupp.ps_partkey)->tpch.partsupp.ps_partkey + └─Selection(Probe) 6524008.35 root not(isnull(Column#57)) + └─HashAgg 8155010.44 root group by:tpch.partsupp.ps_partkey, funcs:min(tpch.partsupp.ps_supplycost)->Column#57, funcs:firstrow(tpch.partsupp.ps_partkey)->tpch.partsupp.ps_partkey └─HashJoin 8155010.44 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] ├─HashJoin(Build) 100000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ ├─HashJoin(Build) 5.00 root inner join, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] @@ -250,10 +250,10 @@ revenue desc, o_orderdate limit 10; id estRows task access object operator info -Projection 10.00 root tpch.lineitem.l_orderkey, Column#35, tpch.orders.o_orderdate, tpch.orders.o_shippriority -└─TopN 10.00 root Column#35:desc, tpch.orders.o_orderdate, offset:0, count:10 - └─HashAgg 40252367.98 root group by:Column#48, Column#49, Column#50, funcs:sum(Column#44)->Column#35, funcs:firstrow(Column#45)->tpch.orders.o_orderdate, funcs:firstrow(Column#46)->tpch.orders.o_shippriority, funcs:firstrow(Column#47)->tpch.lineitem.l_orderkey - └─Projection 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#44, tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority +Projection 10.00 root tpch.lineitem.l_orderkey, Column#37, tpch.orders.o_orderdate, tpch.orders.o_shippriority +└─TopN 10.00 root Column#37:desc, tpch.orders.o_orderdate, offset:0, count:10 + └─HashAgg 40252367.98 root group by:Column#58, Column#59, Column#60, funcs:sum(Column#54)->Column#37, funcs:firstrow(Column#55)->tpch.orders.o_orderdate, funcs:firstrow(Column#56)->tpch.orders.o_shippriority, funcs:firstrow(Column#57)->tpch.lineitem.l_orderkey + └─Projection 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#54, tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority └─HashJoin 91515927.49 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] ├─HashJoin(Build) 22592975.51 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] │ ├─TableReader(Build) 1498236.00 root data:Selection @@ -296,8 +296,8 @@ order by o_orderpriority; id estRows task access object operator info Sort 1.00 root tpch.orders.o_orderpriority -└─Projection 1.00 root tpch.orders.o_orderpriority, Column#27 - └─HashAgg 1.00 root group by:tpch.orders.o_orderpriority, funcs:count(1)->Column#27, funcs:firstrow(tpch.orders.o_orderpriority)->tpch.orders.o_orderpriority +└─Projection 1.00 root tpch.orders.o_orderpriority, Column#28 + └─HashAgg 1.00 root group by:tpch.orders.o_orderpriority, funcs:count(1)->Column#28, funcs:firstrow(tpch.orders.o_orderpriority)->tpch.orders.o_orderpriority └─IndexHashJoin 2340750.00 root semi join, inner:IndexLookUp, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey) ├─TableReader(Build) 2925937.50 root data:Selection │ └─Selection 2925937.50 cop[tikv] ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1995-04-01) @@ -343,10 +343,10 @@ n_name order by revenue desc; id estRows task access object operator info -Sort 5.00 root Column#49:desc -└─Projection 5.00 root tpch.nation.n_name, Column#49 - └─HashAgg 5.00 root group by:Column#52, funcs:sum(Column#50)->Column#49, funcs:firstrow(Column#51)->tpch.nation.n_name - └─Projection 11822812.50 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#50, tpch.nation.n_name, tpch.nation.n_name +Sort 5.00 root Column#54:desc +└─Projection 5.00 root tpch.nation.n_name, Column#54 + └─HashAgg 5.00 root group by:Column#66, funcs:sum(Column#64)->Column#54, funcs:firstrow(Column#65)->tpch.nation.n_name + └─Projection 11822812.50 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#64, tpch.nation.n_name, tpch.nation.n_name └─Projection 11822812.50 root tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.nation.n_name └─HashJoin 11822812.50 root inner join, equal:[eq(tpch.supplier.s_nationkey, tpch.customer.c_nationkey) eq(tpch.orders.o_custkey, tpch.customer.c_custkey)] ├─TableReader(Build) 7500000.00 root data:TableFullScan @@ -445,10 +445,10 @@ supp_nation, cust_nation, l_year; id estRows task access object operator info -Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#50 -└─Projection 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#50, Column#52 - └─HashAgg 769.96 root group by:Column#50, tpch.nation.n_name, tpch.nation.n_name, funcs:sum(Column#51)->Column#52, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#50)->Column#50 - └─Projection 1957240.42 root tpch.nation.n_name, tpch.nation.n_name, extract(YEAR, tpch.lineitem.l_shipdate)->Column#50, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#51 +Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#55 +└─Projection 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#55, Column#57 + └─HashAgg 769.96 root group by:Column#55, tpch.nation.n_name, tpch.nation.n_name, funcs:sum(Column#56)->Column#57, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#55)->Column#55 + └─Projection 1957240.42 root tpch.nation.n_name, tpch.nation.n_name, extract(YEAR, tpch.lineitem.l_shipdate)->Column#55, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#56 └─Projection 1957240.42 root tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.lineitem.l_shipdate, tpch.nation.n_name, tpch.nation.n_name └─HashJoin 1957240.42 root inner join, equal:[eq(tpch.customer.c_nationkey, tpch.nation.n_nationkey)], other cond:or(and(eq(tpch.nation.n_name, "JAPAN"), eq(tpch.nation.n_name, "INDIA")), and(eq(tpch.nation.n_name, "INDIA"), eq(tpch.nation.n_name, "JAPAN"))) ├─TableReader(Build) 2.00 root data:Selection @@ -457,7 +457,7 @@ Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#50 └─HashJoin(Probe) 24465505.20 root inner join, equal:[eq(tpch.orders.o_custkey, tpch.customer.c_custkey)] ├─TableReader(Build) 7500000.00 root data:TableFullScan │ └─TableFullScan 7500000.00 cop[tikv] table:customer keep order:false - └─IndexJoin(Probe) 24465505.20 root inner join, inner:TableReader, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) + └─HashJoin(Probe) 24465505.20 root inner join, equal:[eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)] ├─HashJoin(Build) 24465505.20 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] │ ├─HashJoin(Build) 40000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ │ ├─TableReader(Build) 2.00 root data:Selection @@ -468,8 +468,8 @@ Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#50 │ └─TableReader(Probe) 91446230.29 root data:Selection │ └─Selection 91446230.29 cop[tikv] ge(tpch.lineitem.l_shipdate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shipdate, 1996-12-31 00:00:00.000000) │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─TableReader(Probe) 1.00 root data:TableRangeScan - └─TableRangeScan 1.00 cop[tikv] table:orders range: decided by [tpch.lineitem.l_orderkey], keep order:false + └─TableReader(Probe) 75000000.00 root data:TableFullScan + └─TableFullScan 75000000.00 cop[tikv] table:orders keep order:false /* Q8 National Market Share Query This query determines how the market share of a given nation within a given region has changed over two years for @@ -518,11 +518,11 @@ o_year order by o_year; id estRows task access object operator info -Sort 719.02 root Column#62 -└─Projection 719.02 root Column#62, div(Column#64, Column#65)->Column#66 - └─HashAgg 719.02 root group by:Column#78, funcs:sum(Column#75)->Column#64, funcs:sum(Column#76)->Column#65, funcs:firstrow(Column#77)->Column#62 - └─Projection 563136.02 root case(eq(tpch.nation.n_name, INDIA), Column#63, 0)->Column#75, Column#63, Column#62, Column#62 - └─Projection 563136.02 root extract(YEAR, tpch.orders.o_orderdate)->Column#62, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#63, tpch.nation.n_name +Sort 719.02 root Column#69 +└─Projection 719.02 root Column#69, div(Column#71, Column#72)->Column#73 + └─HashAgg 719.02 root group by:Column#97, funcs:sum(Column#94)->Column#71, funcs:sum(Column#95)->Column#72, funcs:firstrow(Column#96)->Column#69 + └─Projection 563136.02 root case(eq(tpch.nation.n_name, INDIA), Column#70, 0)->Column#94, Column#70, Column#69, Column#69 + └─Projection 563136.02 root extract(YEAR, tpch.orders.o_orderdate)->Column#69, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#70, tpch.nation.n_name └─Projection 563136.02 root tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.orders.o_orderdate, tpch.nation.n_name └─HashJoin 563136.02 root inner join, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] ├─TableReader(Build) 25.00 root data:TableFullScan @@ -595,10 +595,10 @@ order by nation, o_year desc; id estRows task access object operator info -Sort 2406.00 root tpch.nation.n_name, Column#53:desc -└─Projection 2406.00 root tpch.nation.n_name, Column#53, Column#55 - └─HashAgg 2406.00 root group by:Column#53, tpch.nation.n_name, funcs:sum(Column#54)->Column#55, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#53)->Column#53 - └─Projection 241379546.70 root tpch.nation.n_name, extract(YEAR, tpch.orders.o_orderdate)->Column#53, minus(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), mul(tpch.partsupp.ps_supplycost, tpch.lineitem.l_quantity))->Column#54 +Sort 2406.00 root tpch.nation.n_name, Column#57:desc +└─Projection 2406.00 root tpch.nation.n_name, Column#57, Column#59 + └─HashAgg 2406.00 root group by:Column#57, tpch.nation.n_name, funcs:sum(Column#58)->Column#59, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#57)->Column#57 + └─Projection 241379546.70 root tpch.nation.n_name, extract(YEAR, tpch.orders.o_orderdate)->Column#57, minus(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), mul(tpch.partsupp.ps_supplycost, tpch.lineitem.l_quantity))->Column#58 └─Projection 241379546.70 root tpch.lineitem.l_quantity, tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.partsupp.ps_supplycost, tpch.orders.o_orderdate, tpch.nation.n_name └─HashJoin 241379546.70 root inner join, equal:[eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)] ├─TableReader(Build) 75000000.00 root data:TableFullScan @@ -662,10 +662,10 @@ order by revenue desc limit 20; id estRows task access object operator info -Projection 20.00 root tpch.customer.c_custkey, tpch.customer.c_name, Column#39, tpch.customer.c_acctbal, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_comment -└─TopN 20.00 root Column#39:desc, offset:0, count:20 - └─HashAgg 3017307.69 root group by:Column#53, Column#54, Column#55, Column#56, Column#57, Column#58, Column#59, funcs:sum(Column#45)->Column#39, funcs:firstrow(Column#46)->tpch.customer.c_custkey, funcs:firstrow(Column#47)->tpch.customer.c_name, funcs:firstrow(Column#48)->tpch.customer.c_address, funcs:firstrow(Column#49)->tpch.customer.c_phone, funcs:firstrow(Column#50)->tpch.customer.c_acctbal, funcs:firstrow(Column#51)->tpch.customer.c_comment, funcs:firstrow(Column#52)->tpch.nation.n_name - └─Projection 12222016.17 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#45, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.nation.n_name, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_acctbal, tpch.customer.c_phone, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_comment +Projection 20.00 root tpch.customer.c_custkey, tpch.customer.c_name, Column#42, tpch.customer.c_acctbal, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_comment +└─TopN 20.00 root Column#42:desc, offset:0, count:20 + └─HashAgg 3017307.69 root group by:Column#59, Column#60, Column#61, Column#62, Column#63, Column#64, Column#65, funcs:sum(Column#51)->Column#42, funcs:firstrow(Column#52)->tpch.customer.c_custkey, funcs:firstrow(Column#53)->tpch.customer.c_name, funcs:firstrow(Column#54)->tpch.customer.c_address, funcs:firstrow(Column#55)->tpch.customer.c_phone, funcs:firstrow(Column#56)->tpch.customer.c_acctbal, funcs:firstrow(Column#57)->tpch.customer.c_comment, funcs:firstrow(Column#58)->tpch.nation.n_name + └─Projection 12222016.17 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#51, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.nation.n_name, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_acctbal, tpch.customer.c_phone, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_comment └─Projection 12222016.17 root tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.nation.n_name └─IndexHashJoin 12222016.17 root inner join, inner:IndexLookUp, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey) ├─HashJoin(Build) 3017307.69 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] @@ -717,11 +717,11 @@ and n_name = 'MOZAMBIQUE' order by value desc; id estRows task access object operator info -Projection 1304801.67 root tpch.partsupp.ps_partkey, Column#35 -└─Sort 1304801.67 root Column#35:desc - └─Selection 1304801.67 root gt(Column#35, NULL) - └─HashAgg 1631002.09 root group by:Column#44, funcs:sum(Column#42)->Column#35, funcs:firstrow(Column#43)->tpch.partsupp.ps_partkey - └─Projection 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->Column#42, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey +Projection 1304801.67 root tpch.partsupp.ps_partkey, Column#39 +└─Sort 1304801.67 root Column#39:desc + └─Selection 1304801.67 root gt(Column#39, NULL) + └─HashAgg 1631002.09 root group by:Column#54, funcs:sum(Column#52)->Column#39, funcs:firstrow(Column#53)->tpch.partsupp.ps_partkey + └─Projection 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->Column#52, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey └─HashJoin 1631002.09 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] ├─HashJoin(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ ├─TableReader(Build) 1.00 root data:Selection @@ -772,16 +772,17 @@ order by l_shipmode; id estRows task access object operator info Sort 1.00 root tpch.lineitem.l_shipmode -└─Projection 1.00 root tpch.lineitem.l_shipmode, Column#27, Column#28 - └─HashAgg 1.00 root group by:Column#40, funcs:sum(Column#37)->Column#27, funcs:sum(Column#38)->Column#28, funcs:firstrow(Column#39)->tpch.lineitem.l_shipmode - └─Projection 10023369.01 root cast(case(or(eq(tpch.orders.o_orderpriority, 1-URGENT), eq(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#37, cast(case(and(ne(tpch.orders.o_orderpriority, 1-URGENT), ne(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#38, tpch.lineitem.l_shipmode, tpch.lineitem.l_shipmode +└─Projection 1.00 root tpch.lineitem.l_shipmode, Column#28, Column#29 + └─HashAgg 1.00 root group by:Column#46, funcs:sum(Column#43)->Column#28, funcs:sum(Column#44)->Column#29, funcs:firstrow(Column#45)->tpch.lineitem.l_shipmode + └─Projection 10023369.01 root cast(case(or(eq(tpch.orders.o_orderpriority, 1-URGENT), eq(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#43, cast(case(and(ne(tpch.orders.o_orderpriority, 1-URGENT), ne(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#44, tpch.lineitem.l_shipmode, tpch.lineitem.l_shipmode └─Projection 10023369.01 root tpch.orders.o_orderpriority, tpch.lineitem.l_shipmode - └─IndexJoin 10023369.01 root inner join, inner:TableReader, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) + └─IndexJoin 10023369.01 root inner join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) ├─TableReader(Build) 10023369.01 root data:Selection │ └─Selection 10023369.01 cop[tikv] ge(tpch.lineitem.l_receiptdate, 1997-01-01 00:00:00.000000), in(tpch.lineitem.l_shipmode, "RAIL", "FOB"), lt(tpch.lineitem.l_commitdate, tpch.lineitem.l_receiptdate), lt(tpch.lineitem.l_receiptdate, 1998-01-01), lt(tpch.lineitem.l_shipdate, tpch.lineitem.l_commitdate) │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─TableReader(Probe) 1.00 root data:TableRangeScan - └─TableRangeScan 1.00 cop[tikv] table:orders range: decided by [tpch.lineitem.l_orderkey], keep order:false + └─IndexLookUp(Probe) 1.00 root + ├─IndexRangeScan(Build) 1.00 cop[tikv] table:orders, index:PRIMARY(O_ORDERKEY) range: decided by [eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)], keep order:false + └─TableRowIDScan(Probe) 1.00 cop[tikv] table:orders keep order:false /* Q13 Customer Distribution Query This query seeks relationships between customers and the size of their orders. @@ -812,13 +813,13 @@ order by custdist desc, c_count desc; id estRows task access object operator info -Sort 7500000.00 root Column#19:desc, Column#18:desc -└─Projection 7500000.00 root Column#18, Column#19 - └─HashAgg 7500000.00 root group by:Column#18, funcs:count(1)->Column#19, funcs:firstrow(Column#18)->Column#18 - └─HashAgg 7500000.00 root group by:tpch.customer.c_custkey, funcs:count(tpch.orders.o_orderkey)->Column#18 +Sort 7500000.00 root Column#21:desc, Column#20:desc +└─Projection 7500000.00 root Column#20, Column#21 + └─HashAgg 7500000.00 root group by:Column#20, funcs:count(1)->Column#21, funcs:firstrow(Column#20)->Column#20 + └─HashAgg 7500000.00 root group by:tpch.customer.c_custkey, funcs:count(tpch.orders.o_orderkey)->Column#20 └─HashJoin 60000000.00 root left outer join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] - ├─TableReader(Build) 7500000.00 root data:TableFullScan - │ └─TableFullScan 7500000.00 cop[tikv] table:customer keep order:false + ├─IndexReader(Build) 7500000.00 root index:IndexFullScan + │ └─IndexFullScan 7500000.00 cop[tikv] table:customer, index:PRIMARY(C_CUSTKEY) keep order:false └─TableReader(Probe) 60000000.00 root data:Selection └─Selection 60000000.00 cop[tikv] not(like(tpch.orders.o_comment, "%pending%deposits%", 92)) └─TableFullScan 75000000.00 cop[tikv] table:orders keep order:false @@ -844,15 +845,15 @@ l_partkey = p_partkey and l_shipdate >= '1996-12-01' and l_shipdate < date_add('1996-12-01', interval '1' month); id estRows task access object operator info -Projection 1.00 root div(mul(100.00, Column#27), Column#28)->Column#29 -└─StreamAgg 1.00 root funcs:sum(Column#31)->Column#27, funcs:sum(Column#32)->Column#28 - └─Projection 4121984.49 root case(like(tpch.part.p_type, PROMO%, 92), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), 0)->Column#31, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#32 - └─IndexJoin 4121984.49 root inner join, inner:TableReader, outer key:tpch.lineitem.l_partkey, inner key:tpch.part.p_partkey, equal cond:eq(tpch.lineitem.l_partkey, tpch.part.p_partkey) +Projection 1.00 root div(mul(100.00, Column#28), Column#29)->Column#30 +└─StreamAgg 1.00 root funcs:sum(Column#38)->Column#28, funcs:sum(Column#39)->Column#29 + └─Projection 4121984.49 root case(like(tpch.part.p_type, PROMO%, 92), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), 0)->Column#38, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#39 + └─HashJoin 4121984.49 root inner join, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] ├─TableReader(Build) 4121984.49 root data:Selection │ └─Selection 4121984.49 cop[tikv] ge(tpch.lineitem.l_shipdate, 1996-12-01 00:00:00.000000), lt(tpch.lineitem.l_shipdate, 1997-01-01) │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─TableReader(Probe) 1.00 root data:TableRangeScan - └─TableRangeScan 1.00 cop[tikv] table:part range: decided by [tpch.lineitem.l_partkey], keep order:false + └─TableReader(Probe) 10000000.00 root data:TableFullScan + └─TableFullScan 10000000.00 cop[tikv] table:part keep order:false /* Q15 Top Supplier Query This query determines the top supplier so it can be rewarded, given more business, or identified for special recognition. @@ -933,9 +934,9 @@ p_brand, p_type, p_size; id estRows task access object operator info -Sort 14.41 root Column#23:desc, tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size -└─Projection 14.41 root tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size, Column#23 - └─HashAgg 14.41 root group by:tpch.part.p_brand, tpch.part.p_size, tpch.part.p_type, funcs:count(distinct tpch.partsupp.ps_suppkey)->Column#23, funcs:firstrow(tpch.part.p_brand)->tpch.part.p_brand, funcs:firstrow(tpch.part.p_type)->tpch.part.p_type, funcs:firstrow(tpch.part.p_size)->tpch.part.p_size +Sort 14.41 root Column#25:desc, tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size +└─Projection 14.41 root tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size, Column#25 + └─HashAgg 14.41 root group by:tpch.part.p_brand, tpch.part.p_size, tpch.part.p_type, funcs:count(distinct tpch.partsupp.ps_suppkey)->Column#25, funcs:firstrow(tpch.part.p_brand)->tpch.part.p_brand, funcs:firstrow(tpch.part.p_type)->tpch.part.p_type, funcs:firstrow(tpch.part.p_size)->tpch.part.p_size └─HashJoin 3863988.24 root anti semi join, equal:[eq(tpch.partsupp.ps_suppkey, tpch.supplier.s_suppkey)] ├─TableReader(Build) 400000.00 root data:Selection │ └─Selection 400000.00 cop[tikv] like(tpch.supplier.s_comment, "%Customer%Complaints%", 92) @@ -976,18 +977,18 @@ where l_partkey = p_partkey ); id estRows task access object operator info -Projection 1.00 root div(Column#46, 7.0)->Column#47 -└─StreamAgg 1.00 root funcs:sum(tpch.lineitem.l_extendedprice)->Column#46 - └─HashJoin 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:lt(tpch.lineitem.l_quantity, mul(0.2, Column#44)) +Projection 1.00 root div(Column#47, 7.0)->Column#48 +└─StreamAgg 1.00 root funcs:sum(tpch.lineitem.l_extendedprice)->Column#47 + └─HashJoin 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:lt(tpch.lineitem.l_quantity, mul(0.2, Column#45)) ├─HashJoin(Build) 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)] │ ├─TableReader(Build) 9736.49 root data:Selection │ │ └─Selection 9736.49 cop[tikv] eq(tpch.part.p_brand, "Brand#44"), eq(tpch.part.p_container, "WRAP PKG") │ │ └─TableFullScan 10000000.00 cop[tikv] table:part keep order:false │ └─TableReader(Probe) 300005811.00 root data:TableFullScan │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─HashAgg(Probe) 9943040.00 root group by:tpch.lineitem.l_partkey, funcs:avg(Column#50, Column#51)->Column#44, funcs:firstrow(tpch.lineitem.l_partkey)->tpch.lineitem.l_partkey + └─HashAgg(Probe) 9943040.00 root group by:tpch.lineitem.l_partkey, funcs:avg(Column#54, Column#55)->Column#45, funcs:firstrow(tpch.lineitem.l_partkey)->tpch.lineitem.l_partkey └─TableReader 9943040.00 root data:HashAgg - └─HashAgg 9943040.00 cop[tikv] group by:tpch.lineitem.l_partkey, funcs:count(tpch.lineitem.l_quantity)->Column#50, funcs:sum(tpch.lineitem.l_quantity)->Column#51 + └─HashAgg 9943040.00 cop[tikv] group by:tpch.lineitem.l_partkey, funcs:count(tpch.lineitem.l_quantity)->Column#54, funcs:sum(tpch.lineitem.l_quantity)->Column#55 └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false /* Q18 Large Volume Customer Query @@ -1032,15 +1033,15 @@ o_totalprice desc, o_orderdate limit 100; id estRows task access object operator info -Projection 100.00 root tpch.customer.c_name, tpch.customer.c_custkey, tpch.orders.o_orderkey, tpch.orders.o_orderdate, tpch.orders.o_totalprice, Column#54 +Projection 100.00 root tpch.customer.c_name, tpch.customer.c_custkey, tpch.orders.o_orderkey, tpch.orders.o_orderdate, tpch.orders.o_totalprice, Column#56 └─TopN 100.00 root tpch.orders.o_totalprice:desc, tpch.orders.o_orderdate, offset:0, count:100 - └─HashAgg 59251097.60 root group by:tpch.customer.c_custkey, tpch.customer.c_name, tpch.orders.o_orderdate, tpch.orders.o_orderkey, tpch.orders.o_totalprice, funcs:sum(tpch.lineitem.l_quantity)->Column#54, funcs:firstrow(tpch.customer.c_custkey)->tpch.customer.c_custkey, funcs:firstrow(tpch.customer.c_name)->tpch.customer.c_name, funcs:firstrow(tpch.orders.o_orderkey)->tpch.orders.o_orderkey, funcs:firstrow(tpch.orders.o_totalprice)->tpch.orders.o_totalprice, funcs:firstrow(tpch.orders.o_orderdate)->tpch.orders.o_orderdate + └─HashAgg 59251097.60 root group by:tpch.customer.c_custkey, tpch.customer.c_name, tpch.orders.o_orderdate, tpch.orders.o_orderkey, tpch.orders.o_totalprice, funcs:sum(tpch.lineitem.l_quantity)->Column#56, funcs:firstrow(tpch.customer.c_custkey)->tpch.customer.c_custkey, funcs:firstrow(tpch.customer.c_name)->tpch.customer.c_name, funcs:firstrow(tpch.orders.o_orderkey)->tpch.orders.o_orderkey, funcs:firstrow(tpch.orders.o_totalprice)->tpch.orders.o_totalprice, funcs:firstrow(tpch.orders.o_orderdate)->tpch.orders.o_orderdate └─HashJoin 240004648.80 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] ├─HashJoin(Build) 59251097.60 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] - │ ├─Selection(Build) 59251097.60 root gt(Column#52, 314) - │ │ └─HashAgg 74063872.00 root group by:tpch.lineitem.l_orderkey, funcs:sum(Column#66)->Column#52, funcs:firstrow(tpch.lineitem.l_orderkey)->tpch.lineitem.l_orderkey + │ ├─Selection(Build) 59251097.60 root gt(Column#54, 314) + │ │ └─HashAgg 74063872.00 root group by:tpch.lineitem.l_orderkey, funcs:sum(Column#76)->Column#54, funcs:firstrow(tpch.lineitem.l_orderkey)->tpch.lineitem.l_orderkey │ │ └─TableReader 74063872.00 root data:HashAgg - │ │ └─HashAgg 74063872.00 cop[tikv] group by:tpch.lineitem.l_orderkey, funcs:sum(tpch.lineitem.l_quantity)->Column#66 + │ │ └─HashAgg 74063872.00 cop[tikv] group by:tpch.lineitem.l_orderkey, funcs:sum(tpch.lineitem.l_quantity)->Column#76 │ │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false │ └─HashJoin(Probe) 75000000.00 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] │ ├─TableReader(Build) 7500000.00 root data:TableFullScan @@ -1095,8 +1096,8 @@ and l_shipmode in ('AIR', 'AIR REG') and l_shipinstruct = 'DELIVER IN PERSON' ); id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#28)->Column#27 -└─Projection 733887.82 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#28 +StreamAgg 1.00 root funcs:sum(Column#35)->Column#28 +└─Projection 733887.82 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#35 └─HashJoin 733887.82 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:or(and(and(eq(tpch.part.p_brand, "Brand#52"), in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(tpch.lineitem.l_quantity, 4), and(le(tpch.lineitem.l_quantity, 14), le(tpch.part.p_size, 5)))), or(and(and(eq(tpch.part.p_brand, "Brand#11"), in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(tpch.lineitem.l_quantity, 18), and(le(tpch.lineitem.l_quantity, 28), le(tpch.part.p_size, 10)))), and(and(eq(tpch.part.p_brand, "Brand#51"), in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(tpch.lineitem.l_quantity, 29), and(le(tpch.lineitem.l_quantity, 39), le(tpch.part.p_size, 15)))))) ├─TableReader(Build) 24323.12 root data:Selection │ └─Selection 24323.12 cop[tikv] ge(tpch.part.p_size, 1), or(and(eq(tpch.part.p_brand, "Brand#52"), and(in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(tpch.part.p_size, 5))), or(and(eq(tpch.part.p_brand, "Brand#11"), and(in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(tpch.part.p_size, 10))), and(eq(tpch.part.p_brand, "Brand#51"), and(in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(tpch.part.p_size, 15))))) @@ -1161,8 +1162,8 @@ Sort 20000.00 root tpch.supplier.s_name │ └─TableFullScan 500000.00 cop[tikv] table:supplier keep order:false └─HashAgg(Probe) 257492.04 root group by:tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey └─Projection 257492.04 root tpch.partsupp.ps_suppkey - └─Selection 257492.04 root gt(cast(tpch.partsupp.ps_availqty), mul(0.5, Column#44)) - └─HashAgg 321865.05 root group by:tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_availqty)->tpch.partsupp.ps_availqty, funcs:sum(tpch.lineitem.l_quantity)->Column#44 + └─Selection 257492.04 root gt(cast(tpch.partsupp.ps_availqty), mul(0.5, Column#47)) + └─HashAgg 321865.05 root group by:tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_availqty)->tpch.partsupp.ps_availqty, funcs:sum(tpch.lineitem.l_quantity)->Column#47 └─HashJoin 9711455.06 root left outer join, equal:[eq(tpch.partsupp.ps_partkey, tpch.lineitem.l_partkey) eq(tpch.partsupp.ps_suppkey, tpch.lineitem.l_suppkey)] ├─IndexHashJoin(Build) 321865.05 root inner join, inner:IndexLookUp, outer key:tpch.part.p_partkey, inner key:tpch.partsupp.ps_partkey, equal cond:eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) │ ├─TableReader(Build) 80007.93 root data:Selection @@ -1223,12 +1224,12 @@ numwait desc, s_name limit 100; id estRows task access object operator info -Projection 100.00 root tpch.supplier.s_name, Column#72 -└─TopN 100.00 root Column#72:desc, tpch.supplier.s_name, offset:0, count:100 - └─HashAgg 12800.00 root group by:tpch.supplier.s_name, funcs:count(1)->Column#72, funcs:firstrow(tpch.supplier.s_name)->tpch.supplier.s_name +Projection 100.00 root tpch.supplier.s_name, Column#75 +└─TopN 100.00 root Column#75:desc, tpch.supplier.s_name, offset:0, count:100 + └─HashAgg 12800.00 root group by:tpch.supplier.s_name, funcs:count(1)->Column#75, funcs:firstrow(tpch.supplier.s_name)->tpch.supplier.s_name └─IndexHashJoin 7828961.66 root anti semi join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey), other cond:ne(tpch.lineitem.l_suppkey, tpch.lineitem.l_suppkey) ├─IndexHashJoin(Build) 9786202.08 root semi join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey), other cond:ne(tpch.lineitem.l_suppkey, tpch.lineitem.l_suppkey), ne(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey) - │ ├─IndexJoin(Build) 12232752.60 root inner join, inner:TableReader, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) + │ ├─IndexJoin(Build) 12232752.60 root inner join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) │ │ ├─HashJoin(Build) 12232752.60 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] │ │ │ ├─HashJoin(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ │ │ │ ├─TableReader(Build) 1.00 root data:Selection @@ -1239,9 +1240,10 @@ Projection 100.00 root tpch.supplier.s_name, Column#72 │ │ │ └─TableReader(Probe) 240004648.80 root data:Selection │ │ │ └─Selection 240004648.80 cop[tikv] gt(tpch.lineitem.l_receiptdate, tpch.lineitem.l_commitdate) │ │ │ └─TableFullScan 300005811.00 cop[tikv] table:l1 keep order:false - │ │ └─TableReader(Probe) 0.49 root data:Selection - │ │ └─Selection 0.49 cop[tikv] eq(tpch.orders.o_orderstatus, "F") - │ │ └─TableRangeScan 1.00 cop[tikv] table:orders range: decided by [tpch.lineitem.l_orderkey], keep order:false + │ │ └─IndexLookUp(Probe) 1.00 root + │ │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:orders, index:PRIMARY(O_ORDERKEY) range: decided by [eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)], keep order:false + │ │ └─Selection(Probe) 1.00 cop[tikv] eq(tpch.orders.o_orderstatus, "F") + │ │ └─TableRowIDScan 1.00 cop[tikv] table:orders keep order:false │ └─IndexLookUp(Probe) 4.05 root │ ├─IndexRangeScan(Build) 4.05 cop[tikv] table:l2, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey)], keep order:false │ └─TableRowIDScan(Probe) 4.05 cop[tikv] table:l2 keep order:false @@ -1296,10 +1298,10 @@ cntrycode order by cntrycode; id estRows task access object operator info -Sort 1.00 root Column#27 -└─Projection 1.00 root Column#27, Column#28, Column#29 - └─HashAgg 1.00 root group by:Column#27, funcs:count(1)->Column#28, funcs:sum(tpch.customer.c_acctbal)->Column#29, funcs:firstrow(Column#27)->Column#27 - └─Projection 0.00 root substring(tpch.customer.c_phone, 1, 2)->Column#27, tpch.customer.c_acctbal +Sort 1.00 root Column#30 +└─Projection 1.00 root Column#30, Column#31, Column#32 + └─HashAgg 1.00 root group by:Column#30, funcs:count(1)->Column#31, funcs:sum(tpch.customer.c_acctbal)->Column#32, funcs:firstrow(Column#30)->Column#30 + └─Projection 0.00 root substring(tpch.customer.c_phone, 1, 2)->Column#30, tpch.customer.c_acctbal └─HashJoin 0.00 root anti semi join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] ├─TableReader(Build) 75000000.00 root data:TableFullScan │ └─TableFullScan 75000000.00 cop[tikv] table:orders keep order:false diff --git a/cmd/explaintest/r/window_function.result b/cmd/explaintest/r/window_function.result index 6c92b63dcd0d3..b677b48ca8795 100644 --- a/cmd/explaintest/r/window_function.result +++ b/cmd/explaintest/r/window_function.result @@ -109,8 +109,8 @@ insert into t1 values(1, 1), (2, 1); analyze table t1; explain format = 'brief' select sum(a) over(partition by b) from t1; id estRows task access object operator info -Projection 2.00 root Column#4 -└─Window 2.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#4 over(partition by test.t1.b) +Projection 2.00 root Column#5 +└─Window 2.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#5 over(partition by test.t1.b) └─Sort 2.00 root test.t1.b └─TableReader 2.00 root data:TableFullScan └─TableFullScan 2.00 cop[tikv] table:t1 keep order:false @@ -118,9 +118,9 @@ insert into t1 values(3, 3); analyze table t1; explain format = 'brief' select sum(a) over(partition by b) from t1; id estRows task access object operator info -Projection 3.00 root Column#4 +Projection 3.00 root Column#5 └─Shuffle 3.00 root execution info: concurrency:2, data sources:[TableReader] - └─Window 3.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#4 over(partition by test.t1.b) + └─Window 3.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#5 over(partition by test.t1.b) └─Sort 3.00 root test.t1.b └─TableReader 3.00 root data:TableFullScan └─TableFullScan 3.00 cop[tikv] table:t1 keep order:false diff --git a/cmd/explaintest/t/clustered_index.test b/cmd/explaintest/t/clustered_index.test index 7c40b6ae6523d..0f2d234c16b2c 100644 --- a/cmd/explaintest/t/clustered_index.test +++ b/cmd/explaintest/t/clustered_index.test @@ -4,12 +4,11 @@ drop database if exists wout_cluster_index; create database wout_cluster_index; use with_cluster_index; -set @@tidb_enable_clustered_index = 1; -create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) , unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; -create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) , unique key idx_7 ( col_5 ) ) ; -create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) , key idx_9 ( col_11 ) ) ; -create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) , key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; -create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) , key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; +create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) clustered, unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; +create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) clustered, unique key idx_7 ( col_5 ) ) ; +create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) clustered, key idx_9 ( col_11 ) ) ; +create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) clustered, key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; +create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) clustered, key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; load stats 's/with_cluster_index_tbl_0.json'; load stats 's/with_cluster_index_tbl_1.json'; load stats 's/with_cluster_index_tbl_2.json'; @@ -17,12 +16,11 @@ load stats 's/with_cluster_index_tbl_3.json'; load stats 's/with_cluster_index_tbl_4.json'; use wout_cluster_index; -set @@tidb_enable_clustered_index = 0; -create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) , unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; -create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) , unique key idx_7 ( col_5 ) ) ; -create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) , key idx_9 ( col_11 ) ) ; -create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) , key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; -create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) , key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; +create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) nonclustered, key idx_1 ( col_3 ) , unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; +create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) nonclustered, unique key idx_7 ( col_5 ) ) ; +create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) nonclustered, key idx_9 ( col_11 ) ) ; +create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) nonclustered, key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; +create table tbl_4 ( col_20 double(230,16) default 8.49 not null , col_21 int unsigned not null , col_22 enum('Alice','Bob','Charlie','David') not null , col_23 float default 3066.13040283622 , col_24 datetime default '1980-10-27' not null , primary key idx_13 ( col_22,col_24 ) nonclustered, key idx_14 ( col_23,col_20 ) , key idx_15 ( col_24 ) , key idx_16 ( col_20 ) , unique key idx_17 ( col_24 ) , key idx_18 ( col_21 ) ) ; load stats 's/wout_cluster_index_tbl_0.json'; load stats 's/wout_cluster_index_tbl_1.json'; load stats 's/wout_cluster_index_tbl_2.json'; From ddc0b916143a77918e9be66e798007590c9527ca Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 16 Mar 2021 20:45:49 +0800 Subject: [PATCH 07/16] allow binlog and PKIsHandle to be used together --- ddl/ddl_api.go | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 8aea6df281e56..7517e8e739ff5 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -1427,14 +1427,15 @@ func buildTableInfo( if err != nil { return nil, err } - clustered, err := ShouldBuildClusteredIndex(ctx, constr.Option) - if err != nil { - return nil, err - } - if clustered { + if ShouldBuildClusteredIndex(ctx, constr.Option) { if isSingleIntPK(constr, lastCol) { tbInfo.PKIsHandle = true } else { + hasBinlog := ctx.GetSessionVars().BinlogClient != nil + if hasBinlog { + msg := mysql.Message("Cannot create clustered index table when the binlog is ON", nil) + return nil, dbterror.ClassDDL.NewStdErr(errno.ErrUnsupportedDDLOperation, msg) + } tbInfo.IsCommonHandle = true tbInfo.CommonHandleVersion = 1 } @@ -1513,24 +1514,11 @@ func isSingleIntPK(constr *ast.Constraint, lastCol *model.ColumnInfo) bool { } // ShouldBuildClusteredIndex is used to determine whether the CREATE TABLE statement should build a clustered index table. -func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption) (bool, error) { +func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption) bool { if opt == nil || opt.PrimaryKeyTp == model.PrimaryKeyTypeDefault { - return ctx.GetSessionVars().EnableClusteredIndex, nil - } - switch opt.PrimaryKeyTp { - case model.PrimaryKeyTypeClustered: - hasBinlog := ctx.GetSessionVars().BinlogClient != nil - if hasBinlog { - msg := mysql.Message("Cannot create clustered index table when the binlog is ON", nil) - return false, dbterror.ClassDDL.NewStdErr(errno.ErrUnsupportedDDLOperation, msg) - } - return true, nil - case model.PrimaryKeyTypeNonClustered: - return false, nil - default: // should never reach here - logutil.BgLogger().Error("Unknown primary key type") - return false, nil + return ctx.GetSessionVars().EnableClusteredIndex } + return opt.PrimaryKeyTp == model.PrimaryKeyTypeClustered } // checkTableInfoValidExtra is like checkTableInfoValid, but also assumes the From 52e77afc0d04d64e74d93feaf541252db6809d78 Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 16 Mar 2021 21:04:31 +0800 Subject: [PATCH 08/16] change the pk type value 'non-clustered' to 'nonclustered' --- executor/infoschema_reader.go | 2 +- executor/infoschema_reader_test.go | 4 ++-- session/clustered_index_test.go | 2 +- sessionctx/binloginfo/binloginfo_test.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 7abf159313a9e..fe394f8e473ef 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -457,7 +457,7 @@ func (e *memtableRetriever) setDataFromTables(ctx sessionctx.Context, schemas [] if checker != nil && !checker.RequestVerification(ctx.GetSessionVars().ActiveRoles, schema.Name.L, table.Name.L, "", mysql.AllPrivMask) { continue } - pkType := "NON-CLUSTERED" + pkType := "NONCLUSTERED" if !table.IsView() { if table.GetPartitionInfo() != nil { createOptions = "partitioned" diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index 903d42a02df29..bb3497ac564a8 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -875,9 +875,9 @@ func (s *testInfoschemaTableSuite) TestTablesPKType(c *C) { tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'test' and table_name = 't_int'").Check(testkit.Rows("CLUSTERED")) tk.Se.GetSessionVars().EnableClusteredIndex = false tk.MustExec("create table t_implicit (a varchar(64) primary key, b int)") - tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'test' and table_name = 't_implicit'").Check(testkit.Rows("NON-CLUSTERED")) + tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'test' and table_name = 't_implicit'").Check(testkit.Rows("NONCLUSTERED")) tk.Se.GetSessionVars().EnableClusteredIndex = true tk.MustExec("create table t_common (a varchar(64) primary key, b int)") tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'test' and table_name = 't_common'").Check(testkit.Rows("CLUSTERED")) - tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'INFORMATION_SCHEMA' and table_name = 'TABLES'").Check(testkit.Rows("NON-CLUSTERED")) + tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'INFORMATION_SCHEMA' and table_name = 'TABLES'").Check(testkit.Rows("NONCLUSTERED")) } diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index aeb17db406885..3449248dd5f73 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -402,7 +402,7 @@ func (s *testClusteredSuite) TestClusteredIndexSelectWhereInNull(c *C) { func (s *testClusteredSuite) TestClusteredIndexSyntax(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) const showPKType = `select tidb_pk_type from information_schema.tables where table_schema = 'test' and table_name = 't';` - const nonClustered, clustered = `NON-CLUSTERED`, `CLUSTERED` + const nonClustered, clustered = `NONCLUSTERED`, `CLUSTERED` assertPkType := func(sql string, pkType string) { tk.MustExec("drop table if exists t;") tk.MustExec(sql) diff --git a/sessionctx/binloginfo/binloginfo_test.go b/sessionctx/binloginfo/binloginfo_test.go index a64d2684aec26..0083c1cf9ac3d 100644 --- a/sessionctx/binloginfo/binloginfo_test.go +++ b/sessionctx/binloginfo/binloginfo_test.go @@ -261,7 +261,7 @@ func (s *testBinlogSuite) TestBinlog(c *C) { warnMsg := "Warning 1105 cannot build clustered index table because the binlog is ON" tk.MustQuery("show warnings;").Check(testkit.Rows(warnMsg)) tk.MustQuery("select tidb_pk_type from information_schema.tables where table_name = 'local_clustered_index' and table_schema = 'test';"). - Check(testkit.Rows("NON-CLUSTERED")) + Check(testkit.Rows("NONCLUSTERED")) tk.MustExec("drop table if exists local_clustered_index;") // Test clustered index tables will not write binlog. tk.Se.GetSessionVars().BinlogClient = nil From 08b38ba3582bdaba65c507aba48b3a74f9b0a76c Mon Sep 17 00:00:00 2001 From: tangenta Date: Tue, 16 Mar 2021 22:46:22 +0800 Subject: [PATCH 09/16] update explain test --- cmd/explaintest/r/explain.result | 12 +- cmd/explaintest/r/explain_complex.result | 10 +- .../r/explain_complex_stats.result | 18 +- cmd/explaintest/r/explain_easy.result | 291 +++++++++--------- cmd/explaintest/r/explain_easy_stats.result | 73 ++--- cmd/explaintest/r/explain_indexmerge.result | 110 +++---- cmd/explaintest/r/explain_join_stats.result | 12 +- cmd/explaintest/r/partition_pruning.result | 272 ++++++++-------- cmd/explaintest/r/select.result | 19 +- cmd/explaintest/r/subquery.result | 17 +- cmd/explaintest/r/tpch.result | 170 +++++----- cmd/explaintest/r/window_function.result | 8 +- 12 files changed, 494 insertions(+), 518 deletions(-) diff --git a/cmd/explaintest/r/explain.result b/cmd/explaintest/r/explain.result index 43a79435b1d84..259a7c49be9ea 100644 --- a/cmd/explaintest/r/explain.result +++ b/cmd/explaintest/r/explain.result @@ -28,16 +28,16 @@ set session tidb_hashagg_partial_concurrency = 1; set session tidb_hashagg_final_concurrency = 1; explain format = 'brief' select group_concat(a) from t group by id; id estRows task access object operator info -HashAgg 8000.00 root group by:Column#9, funcs:group_concat(Column#8 separator ",")->Column#5 -└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#8, test.t.id +StreamAgg 8000.00 root group by:Column#6, funcs:group_concat(Column#5 separator ",")->Column#4 +└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, test.t.id └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─TableFullScan 10000.00 cop[tikv] table:t keep order:true, stats:pseudo explain format = 'brief' select group_concat(a, b) from t group by id; id estRows task access object operator info -HashAgg 8000.00 root group by:Column#10, funcs:group_concat(Column#8, Column#9 separator ",")->Column#5 -└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#8, cast(test.t.b, var_string(20))->Column#9, test.t.id +StreamAgg 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6 separator ",")->Column#4 +└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─TableFullScan 10000.00 cop[tikv] table:t keep order:true, stats:pseudo drop table t; drop view if exists v; create view v as select cast(replace(substring_index(substring_index("",',',1),':',-1),'"','') as CHAR(32)) as event_id; diff --git a/cmd/explaintest/r/explain_complex.result b/cmd/explaintest/r/explain_complex.result index 4e7e0d430d1a2..b3c79948a142e 100644 --- a/cmd/explaintest/r/explain_complex.result +++ b/cmd/explaintest/r/explain_complex.result @@ -105,12 +105,12 @@ PRIMARY KEY (`aid`,`dic`) ); explain format = 'brief' SELECT `ds`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6_md5`, `p7_md5`, count(dic) as install_device FROM `dt` use index (cmi) WHERE (`ds` >= '2016-09-01') AND (`ds` <= '2016-11-03') AND (`cm` IN ('1062', '1086', '1423', '1424', '1425', '1426', '1427', '1428', '1429', '1430', '1431', '1432', '1433', '1434', '1435', '1436', '1437', '1438', '1439', '1440', '1441', '1442', '1443', '1444', '1445', '1446', '1447', '1448', '1449', '1450', '1451', '1452', '1488', '1489', '1490', '1491', '1492', '1493', '1494', '1495', '1496', '1497', '1550', '1551', '1552', '1553', '1554', '1555', '1556', '1557', '1558', '1559', '1597', '1598', '1599', '1600', '1601', '1602', '1603', '1604', '1605', '1606', '1607', '1608', '1609', '1610', '1611', '1612', '1613', '1614', '1615', '1616', '1623', '1624', '1625', '1626', '1627', '1628', '1629', '1630', '1631', '1632', '1709', '1719', '1720', '1843', '2813', '2814', '2815', '2816', '2817', '2818', '2819', '2820', '2821', '2822', '2823', '2824', '2825', '2826', '2827', '2828', '2829', '2830', '2831', '2832', '2833', '2834', '2835', '2836', '2837', '2838', '2839', '2840', '2841', '2842', '2843', '2844', '2845', '2846', '2847', '2848', '2849', '2850', '2851', '2852', '2853', '2854', '2855', '2856', '2857', '2858', '2859', '2860', '2861', '2862', '2863', '2864', '2865', '2866', '2867', '2868', '2869', '2870', '2871', '2872', '3139', '3140', '3141', '3142', '3143', '3144', '3145', '3146', '3147', '3148', '3149', '3150', '3151', '3152', '3153', '3154', '3155', '3156', '3157', '3158', '3386', '3387', '3388', '3389', '3390', '3391', '3392', '3393', '3394', '3395', '3664', '3665', '3666', '3667', '3668', '3670', '3671', '3672', '3673', '3674', '3676', '3677', '3678', '3679', '3680', '3681', '3682', '3683', '3684', '3685', '3686', '3687', '3688', '3689', '3690', '3691', '3692', '3693', '3694', '3695', '3696', '3697', '3698', '3699', '3700', '3701', '3702', '3703', '3704', '3705', '3706', '3707', '3708', '3709', '3710', '3711', '3712', '3713', '3714', '3715', '3960', '3961', '3962', '3963', '3964', '3965', '3966', '3967', '3968', '3978', '3979', '3980', '3981', '3982', '3983', '3984', '3985', '3986', '3987', '4208', '4209', '4210', '4211', '4212', '4304', '4305', '4306', '4307', '4308', '4866', '4867', '4868', '4869', '4870', '4871', '4872', '4873', '4874', '4875')) GROUP BY `ds`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6_md5`, `p7_md5` ORDER BY `ds2` DESC; id estRows task access object operator info -Projection 53.00 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#22 +Projection 53.00 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#21 └─Sort 53.00 root test.dt.ds2:desc - └─HashAgg 53.00 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#33)->Column#22, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#35)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 + └─HashAgg 53.00 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#32)->Column#21, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#34)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 └─IndexLookUp 53.00 root ├─IndexRangeScan(Build) 2650.00 cop[tikv] table:dt, index:cmi(cm) range:[1062,1062], [1086,1086], [1423,1423], [1424,1424], [1425,1425], [1426,1426], [1427,1427], [1428,1428], [1429,1429], [1430,1430], [1431,1431], [1432,1432], [1433,1433], [1434,1434], [1435,1435], [1436,1436], [1437,1437], [1438,1438], [1439,1439], [1440,1440], [1441,1441], [1442,1442], [1443,1443], [1444,1444], [1445,1445], [1446,1446], [1447,1447], [1448,1448], [1449,1449], [1450,1450], [1451,1451], [1452,1452], [1488,1488], [1489,1489], [1490,1490], [1491,1491], [1492,1492], [1493,1493], [1494,1494], [1495,1495], [1496,1496], [1497,1497], [1550,1550], [1551,1551], [1552,1552], [1553,1553], [1554,1554], [1555,1555], [1556,1556], [1557,1557], [1558,1558], [1559,1559], [1597,1597], [1598,1598], [1599,1599], [1600,1600], [1601,1601], [1602,1602], [1603,1603], [1604,1604], [1605,1605], [1606,1606], [1607,1607], [1608,1608], [1609,1609], [1610,1610], [1611,1611], [1612,1612], [1613,1613], [1614,1614], [1615,1615], [1616,1616], [1623,1623], [1624,1624], [1625,1625], [1626,1626], [1627,1627], [1628,1628], [1629,1629], [1630,1630], [1631,1631], [1632,1632], [1709,1709], [1719,1719], [1720,1720], [1843,1843], [2813,2813], [2814,2814], [2815,2815], [2816,2816], [2817,2817], [2818,2818], [2819,2819], [2820,2820], [2821,2821], [2822,2822], [2823,2823], [2824,2824], [2825,2825], [2826,2826], [2827,2827], [2828,2828], [2829,2829], [2830,2830], [2831,2831], [2832,2832], [2833,2833], [2834,2834], [2835,2835], [2836,2836], [2837,2837], [2838,2838], [2839,2839], [2840,2840], [2841,2841], [2842,2842], [2843,2843], [2844,2844], [2845,2845], [2846,2846], [2847,2847], [2848,2848], [2849,2849], [2850,2850], [2851,2851], [2852,2852], [2853,2853], [2854,2854], [2855,2855], [2856,2856], [2857,2857], [2858,2858], [2859,2859], [2860,2860], [2861,2861], [2862,2862], [2863,2863], [2864,2864], [2865,2865], [2866,2866], [2867,2867], [2868,2868], [2869,2869], [2870,2870], [2871,2871], [2872,2872], [3139,3139], [3140,3140], [3141,3141], [3142,3142], [3143,3143], [3144,3144], [3145,3145], [3146,3146], [3147,3147], [3148,3148], [3149,3149], [3150,3150], [3151,3151], [3152,3152], [3153,3153], [3154,3154], [3155,3155], [3156,3156], [3157,3157], [3158,3158], [3386,3386], [3387,3387], [3388,3388], [3389,3389], [3390,3390], [3391,3391], [3392,3392], [3393,3393], [3394,3394], [3395,3395], [3664,3664], [3665,3665], [3666,3666], [3667,3667], [3668,3668], [3670,3670], [3671,3671], [3672,3672], [3673,3673], [3674,3674], [3676,3676], [3677,3677], [3678,3678], [3679,3679], [3680,3680], [3681,3681], [3682,3682], [3683,3683], [3684,3684], [3685,3685], [3686,3686], [3687,3687], [3688,3688], [3689,3689], [3690,3690], [3691,3691], [3692,3692], [3693,3693], [3694,3694], [3695,3695], [3696,3696], [3697,3697], [3698,3698], [3699,3699], [3700,3700], [3701,3701], [3702,3702], [3703,3703], [3704,3704], [3705,3705], [3706,3706], [3707,3707], [3708,3708], [3709,3709], [3710,3710], [3711,3711], [3712,3712], [3713,3713], [3714,3714], [3715,3715], [3960,3960], [3961,3961], [3962,3962], [3963,3963], [3964,3964], [3965,3965], [3966,3966], [3967,3967], [3968,3968], [3978,3978], [3979,3979], [3980,3980], [3981,3981], [3982,3982], [3983,3983], [3984,3984], [3985,3985], [3986,3986], [3987,3987], [4208,4208], [4209,4209], [4210,4210], [4211,4211], [4212,4212], [4304,4304], [4305,4305], [4306,4306], [4307,4307], [4308,4308], [4866,4866], [4867,4867], [4868,4868], [4869,4869], [4870,4870], [4871,4871], [4872,4872], [4873,4873], [4874,4874], [4875,4875], keep order:false, stats:pseudo - └─HashAgg(Probe) 53.00 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#33, funcs:firstrow(test.dt.ds2)->Column#35 + └─HashAgg(Probe) 53.00 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#32, funcs:firstrow(test.dt.ds2)->Column#34 └─Selection 66.25 cop[tikv] ge(test.dt.ds, 2016-09-01 00:00:00.000000), le(test.dt.ds, 2016-11-03 00:00:00.000000) └─TableRowIDScan 2650.00 cop[tikv] table:dt keep order:false, stats:pseudo explain format = 'brief' select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext, gad.t as gtime from st gad join (select id, aid, pt, dic, ip, t from dd where pt = 'android' and bm = 0 and t > 1478143908) sdk on gad.aid = sdk.aid and gad.ip = sdk.ip and sdk.t > gad.t where gad.t > 1478143908 and gad.pt = 'android' group by gad.aid, sdk.dic limit 2500; @@ -143,8 +143,8 @@ Projection 0.00 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd.d └─TableRowIDScan 10000.00 cop[tikv] table:sdk keep order:false, stats:pseudo explain format = 'brief' SELECT cm, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(1) as click_pv, count(DISTINCT ip) as click_ip FROM st WHERE (t between 1478188800 and 1478275200) and aid='cn.sbkcq' and pt='android' GROUP BY cm, p1, p2, p3, p4, p5, p6_md5, p7_md5; id estRows task access object operator info -Projection 1.00 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#21, Column#22 -└─HashAgg 1.00 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#21, funcs:count(distinct test.st.ip)->Column#22, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 +Projection 1.00 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#20, Column#21 +└─HashAgg 1.00 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#20, funcs:count(distinct test.st.ip)->Column#21, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 └─IndexLookUp 0.00 root ├─IndexRangeScan(Build) 250.00 cop[tikv] table:st, index:t(t) range:[1478188800,1478275200], keep order:false, stats:pseudo └─Selection(Probe) 0.00 cop[tikv] eq(test.st.aid, "cn.sbkcq"), eq(test.st.pt, "android") diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index 8b527a62be75c..46fed25d76094 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -115,12 +115,12 @@ PRIMARY KEY (aid,dic) load stats 's/explain_complex_stats_rr.json'; explain format = 'brief' SELECT ds, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(dic) as install_device FROM dt use index (cm) WHERE (ds >= '2016-09-01') AND (ds <= '2016-11-03') AND (cm IN ('1062', '1086', '1423', '1424', '1425', '1426', '1427', '1428', '1429', '1430', '1431', '1432', '1433', '1434', '1435', '1436', '1437', '1438', '1439', '1440', '1441', '1442', '1443', '1444', '1445', '1446', '1447', '1448', '1449', '1450', '1451', '1452', '1488', '1489', '1490', '1491', '1492', '1493', '1494', '1495', '1496', '1497', '1550', '1551', '1552', '1553', '1554', '1555', '1556', '1557', '1558', '1559', '1597', '1598', '1599', '1600', '1601', '1602', '1603', '1604', '1605', '1606', '1607', '1608', '1609', '1610', '1611', '1612', '1613', '1614', '1615', '1616', '1623', '1624', '1625', '1626', '1627', '1628', '1629', '1630', '1631', '1632', '1709', '1719', '1720', '1843', '2813', '2814', '2815', '2816', '2817', '2818', '2819', '2820', '2821', '2822', '2823', '2824', '2825', '2826', '2827', '2828', '2829', '2830', '2831', '2832', '2833', '2834', '2835', '2836', '2837', '2838', '2839', '2840', '2841', '2842', '2843', '2844', '2845', '2846', '2847', '2848', '2849', '2850', '2851', '2852', '2853', '2854', '2855', '2856', '2857', '2858', '2859', '2860', '2861', '2862', '2863', '2864', '2865', '2866', '2867', '2868', '2869', '2870', '2871', '2872', '3139', '3140', '3141', '3142', '3143', '3144', '3145', '3146', '3147', '3148', '3149', '3150', '3151', '3152', '3153', '3154', '3155', '3156', '3157', '3158', '3386', '3387', '3388', '3389', '3390', '3391', '3392', '3393', '3394', '3395', '3664', '3665', '3666', '3667', '3668', '3670', '3671', '3672', '3673', '3674', '3676', '3677', '3678', '3679', '3680', '3681', '3682', '3683', '3684', '3685', '3686', '3687', '3688', '3689', '3690', '3691', '3692', '3693', '3694', '3695', '3696', '3697', '3698', '3699', '3700', '3701', '3702', '3703', '3704', '3705', '3706', '3707', '3708', '3709', '3710', '3711', '3712', '3713', '3714', '3715', '3960', '3961', '3962', '3963', '3964', '3965', '3966', '3967', '3968', '3978', '3979', '3980', '3981', '3982', '3983', '3984', '3985', '3986', '3987', '4208', '4209', '4210', '4211', '4212', '4304', '4305', '4306', '4307', '4308', '4866', '4867', '4868', '4869', '4870', '4871', '4872', '4873', '4874', '4875')) GROUP BY ds, p1, p2, p3, p4, p5, p6_md5, p7_md5 ORDER BY ds2 DESC; id estRows task access object operator info -Projection 21.53 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#22 +Projection 21.53 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#21 └─Sort 21.53 root test.dt.ds2:desc - └─HashAgg 21.53 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#33)->Column#22, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#35)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 + └─HashAgg 21.53 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#32)->Column#21, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#34)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5 └─IndexLookUp 21.53 root ├─IndexRangeScan(Build) 128.32 cop[tikv] table:dt, index:cm(cm) range:[1062,1062], [1086,1086], [1423,1423], [1424,1424], [1425,1425], [1426,1426], [1427,1427], [1428,1428], [1429,1429], [1430,1430], [1431,1431], [1432,1432], [1433,1433], [1434,1434], [1435,1435], [1436,1436], [1437,1437], [1438,1438], [1439,1439], [1440,1440], [1441,1441], [1442,1442], [1443,1443], [1444,1444], [1445,1445], [1446,1446], [1447,1447], [1448,1448], [1449,1449], [1450,1450], [1451,1451], [1452,1452], [1488,1488], [1489,1489], [1490,1490], [1491,1491], [1492,1492], [1493,1493], [1494,1494], [1495,1495], [1496,1496], [1497,1497], [1550,1550], [1551,1551], [1552,1552], [1553,1553], [1554,1554], [1555,1555], [1556,1556], [1557,1557], [1558,1558], [1559,1559], [1597,1597], [1598,1598], [1599,1599], [1600,1600], [1601,1601], [1602,1602], [1603,1603], [1604,1604], [1605,1605], [1606,1606], [1607,1607], [1608,1608], [1609,1609], [1610,1610], [1611,1611], [1612,1612], [1613,1613], [1614,1614], [1615,1615], [1616,1616], [1623,1623], [1624,1624], [1625,1625], [1626,1626], [1627,1627], [1628,1628], [1629,1629], [1630,1630], [1631,1631], [1632,1632], [1709,1709], [1719,1719], [1720,1720], [1843,1843], [2813,2813], [2814,2814], [2815,2815], [2816,2816], [2817,2817], [2818,2818], [2819,2819], [2820,2820], [2821,2821], [2822,2822], [2823,2823], [2824,2824], [2825,2825], [2826,2826], [2827,2827], [2828,2828], [2829,2829], [2830,2830], [2831,2831], [2832,2832], [2833,2833], [2834,2834], [2835,2835], [2836,2836], [2837,2837], [2838,2838], [2839,2839], [2840,2840], [2841,2841], [2842,2842], [2843,2843], [2844,2844], [2845,2845], [2846,2846], [2847,2847], [2848,2848], [2849,2849], [2850,2850], [2851,2851], [2852,2852], [2853,2853], [2854,2854], [2855,2855], [2856,2856], [2857,2857], [2858,2858], [2859,2859], [2860,2860], [2861,2861], [2862,2862], [2863,2863], [2864,2864], [2865,2865], [2866,2866], [2867,2867], [2868,2868], [2869,2869], [2870,2870], [2871,2871], [2872,2872], [3139,3139], [3140,3140], [3141,3141], [3142,3142], [3143,3143], [3144,3144], [3145,3145], [3146,3146], [3147,3147], [3148,3148], [3149,3149], [3150,3150], [3151,3151], [3152,3152], [3153,3153], [3154,3154], [3155,3155], [3156,3156], [3157,3157], [3158,3158], [3386,3386], [3387,3387], [3388,3388], [3389,3389], [3390,3390], [3391,3391], [3392,3392], [3393,3393], [3394,3394], [3395,3395], [3664,3664], [3665,3665], [3666,3666], [3667,3667], [3668,3668], [3670,3670], [3671,3671], [3672,3672], [3673,3673], [3674,3674], [3676,3676], [3677,3677], [3678,3678], [3679,3679], [3680,3680], [3681,3681], [3682,3682], [3683,3683], [3684,3684], [3685,3685], [3686,3686], [3687,3687], [3688,3688], [3689,3689], [3690,3690], [3691,3691], [3692,3692], [3693,3693], [3694,3694], [3695,3695], [3696,3696], [3697,3697], [3698,3698], [3699,3699], [3700,3700], [3701,3701], [3702,3702], [3703,3703], [3704,3704], [3705,3705], [3706,3706], [3707,3707], [3708,3708], [3709,3709], [3710,3710], [3711,3711], [3712,3712], [3713,3713], [3714,3714], [3715,3715], [3960,3960], [3961,3961], [3962,3962], [3963,3963], [3964,3964], [3965,3965], [3966,3966], [3967,3967], [3968,3968], [3978,3978], [3979,3979], [3980,3980], [3981,3981], [3982,3982], [3983,3983], [3984,3984], [3985,3985], [3986,3986], [3987,3987], [4208,4208], [4209,4209], [4210,4210], [4211,4211], [4212,4212], [4304,4304], [4305,4305], [4306,4306], [4307,4307], [4308,4308], [4866,4866], [4867,4867], [4868,4868], [4869,4869], [4870,4870], [4871,4871], [4872,4872], [4873,4873], [4874,4874], [4875,4875], keep order:false - └─HashAgg(Probe) 21.53 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#33, funcs:firstrow(test.dt.ds2)->Column#35 + └─HashAgg(Probe) 21.53 cop[tikv] group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(test.dt.dic)->Column#32, funcs:firstrow(test.dt.ds2)->Column#34 └─Selection 21.56 cop[tikv] ge(test.dt.ds, 2016-09-01 00:00:00.000000), le(test.dt.ds, 2016-11-03 00:00:00.000000) └─TableRowIDScan 128.32 cop[tikv] table:dt keep order:false explain format = 'brief' select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext, gad.t as gtime from st gad join (select id, aid, pt, dic, ip, t from dd where pt = 'android' and bm = 0 and t > 1478143908) sdk on gad.aid = sdk.aid and gad.ip = sdk.ip and sdk.t > gad.t where gad.t > 1478143908 and gad.bm = 0 and gad.pt = 'android' group by gad.aid, sdk.dic limit 2500; @@ -131,10 +131,10 @@ Projection 424.00 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd └─HashJoin 424.00 root inner join, equal:[eq(test.st.aid, test.dd.aid) eq(test.st.ip, test.dd.ip)], other cond:gt(test.dd.t, test.st.t) ├─TableReader(Build) 424.00 root data:Selection │ └─Selection 424.00 cop[tikv] eq(test.st.bm, 0), eq(test.st.pt, "android"), gt(test.st.t, 1478143908), not(isnull(test.st.ip)) - │ └─TableFullScan 1999.00 cop[tikv] table:gad keep order:false + │ └─TableRangeScan 1999.00 cop[tikv] table:gad range:[0,+inf], keep order:false └─TableReader(Probe) 455.80 root data:Selection └─Selection 455.80 cop[tikv] eq(test.dd.bm, 0), eq(test.dd.pt, "android"), gt(test.dd.t, 1478143908), not(isnull(test.dd.ip)), not(isnull(test.dd.t)) - └─TableFullScan 2000.00 cop[tikv] table:dd keep order:false + └─TableRangeScan 2000.00 cop[tikv] table:dd range:[0,+inf], keep order:false explain format = 'brief' select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext from st gad join dd sdk on gad.aid = sdk.aid and gad.dic = sdk.mac and gad.t < sdk.t where gad.t > 1477971479 and gad.bm = 0 and gad.pt = 'ios' and gad.dit = 'mac' and sdk.t > 1477971479 and sdk.bm = 0 and sdk.pt = 'ios' limit 3000; id estRows task access object operator info Projection 170.34 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd.dic, test.dd.ip, test.dd.t, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, test.st.ext @@ -142,15 +142,15 @@ Projection 170.34 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd └─IndexJoin 170.34 root inner join, inner:IndexLookUp, outer key:test.st.aid, inner key:test.dd.aid, equal cond:eq(test.st.aid, test.dd.aid), eq(test.st.dic, test.dd.mac), other cond:lt(test.st.t, test.dd.t) ├─TableReader(Build) 170.34 root data:Selection │ └─Selection 170.34 cop[tikv] eq(test.st.bm, 0), eq(test.st.dit, "mac"), eq(test.st.pt, "ios"), gt(test.st.t, 1477971479), not(isnull(test.st.dic)) - │ └─TableFullScan 1999.00 cop[tikv] table:gad keep order:false + │ └─TableRangeScan 1999.00 cop[tikv] table:gad range:[0,+inf], keep order:false └─IndexLookUp(Probe) 1.00 root ├─IndexRangeScan(Build) 3.93 cop[tikv] table:sdk, index:aid(aid, dic) range: decided by [eq(test.dd.aid, test.st.aid)], keep order:false └─Selection(Probe) 1.00 cop[tikv] eq(test.dd.bm, 0), eq(test.dd.pt, "ios"), gt(test.dd.t, 1477971479), not(isnull(test.dd.mac)), not(isnull(test.dd.t)) └─TableRowIDScan 3.93 cop[tikv] table:sdk keep order:false explain format = 'brief' SELECT cm, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(1) as click_pv, count(DISTINCT ip) as click_ip FROM st WHERE (t between 1478188800 and 1478275200) and aid='cn.sbkcq' and pt='android' GROUP BY cm, p1, p2, p3, p4, p5, p6_md5, p7_md5; id estRows task access object operator info -Projection 39.28 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#21, Column#22 -└─HashAgg 39.28 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#21, funcs:count(distinct test.st.ip)->Column#22, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 +Projection 39.28 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, Column#20, Column#21 +└─HashAgg 39.28 root group by:test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, funcs:count(1)->Column#20, funcs:count(distinct test.st.ip)->Column#21, funcs:firstrow(test.st.cm)->test.st.cm, funcs:firstrow(test.st.p1)->test.st.p1, funcs:firstrow(test.st.p2)->test.st.p2, funcs:firstrow(test.st.p3)->test.st.p3, funcs:firstrow(test.st.p4)->test.st.p4, funcs:firstrow(test.st.p5)->test.st.p5, funcs:firstrow(test.st.p6_md5)->test.st.p6_md5, funcs:firstrow(test.st.p7_md5)->test.st.p7_md5 └─IndexLookUp 39.38 root ├─IndexRangeScan(Build) 160.23 cop[tikv] table:st, index:t(t) range:[1478188800,1478275200], keep order:false └─Selection(Probe) 39.38 cop[tikv] eq(test.st.aid, "cn.sbkcq"), eq(test.st.pt, "android") @@ -162,7 +162,7 @@ Projection 428.32 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.d └─IndexJoin 428.32 root inner join, inner:IndexLookUp, outer key:test.dt.aid, test.dt.dic, inner key:test.rr.aid, test.rr.dic, equal cond:eq(test.dt.aid, test.rr.aid), eq(test.dt.dic, test.rr.dic) ├─TableReader(Build) 428.32 root data:Selection │ └─Selection 428.32 cop[tikv] eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592), not(isnull(test.dt.dic)) - │ └─TableFullScan 2000.00 cop[tikv] table:dt keep order:false + │ └─TableRangeScan 2000.00 cop[tikv] table:dt range:[0,+inf], keep order:false └─IndexLookUp(Probe) 1.00 root ├─IndexRangeScan(Build) 1.00 cop[tikv] table:rr, index:PRIMARY(aid, dic) range: decided by [eq(test.rr.aid, test.dt.aid) eq(test.rr.dic, test.dt.dic)], keep order:false └─Selection(Probe) 1.00 cop[tikv] eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592) diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index cf350bb697a28..96f66065effb7 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -27,10 +27,9 @@ TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c2; id estRows task access object operator info -Projection 10000.00 root test.t1.c1, test.t1.c2, test.t1.c3 -└─IndexLookUp 10000.00 root - ├─IndexFullScan(Build) 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:true, stats:pseudo - └─TableRowIDScan(Probe) 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexLookUp 10000.00 root +├─IndexFullScan(Build) 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:true, stats:pseudo +└─TableRowIDScan(Probe) 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t2 order by c2; id estRows task access object operator info Sort 10000.00 root test.t2.c2 @@ -38,27 +37,24 @@ Sort 10000.00 root test.t2.c2 └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where t1.c1 > 0; id estRows task access object operator info -TableReader 3333.33 root data:Selection -└─Selection 3333.33 cop[tikv] gt(test.t1.c1, 0) - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +TableReader 3333.33 root data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(0,+inf], keep order:false, stats:pseudo explain format = 'brief' select t1.c1, t1.c2 from t1 where t1.c2 = 1; id estRows task access object operator info -IndexLookUp 10.00 root -├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo -└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo explain format = 'brief' select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id estRows task access object operator info HashJoin 4166.67 root left outer join, equal:[eq(test.t1.c2, test.t2.c1)] -├─TableReader(Build) 3333.33 root data:Selection -│ └─Selection 3333.33 cop[tikv] gt(test.t1.c1, 1) -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +├─TableReader(Build) 3333.33 root data:TableRangeScan +│ └─TableRangeScan 3333.33 cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo └─TableReader(Probe) 9990.00 root data:Selection └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c1)) └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' update t1 set t1.c2 = 2 where t1.c1 = 1; id estRows task access object operator info Update N/A root N/A -└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) +└─Point_Get 1.00 root table:t1 handle:1 explain format = 'brief' delete from t1 where t1.c2 = 1; id estRows task access object operator info Delete N/A root N/A @@ -67,15 +63,15 @@ Delete N/A root N/A └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id estRows task access object operator info -Projection 9990.00 root cast(Column#9, bigint(21) BINARY)->Column#8 +Projection 9990.00 root cast(Column#8, bigint(21) BINARY)->Column#7 └─HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] - ├─HashAgg(Build) 7992.00 root group by:test.t2.c2, funcs:count(Column#10)->Column#9, funcs:firstrow(test.t2.c2)->test.t2.c2 + ├─HashAgg(Build) 7992.00 root group by:test.t2.c2, funcs:count(Column#9)->Column#8, funcs:firstrow(test.t2.c2)->test.t2.c2 │ └─TableReader 7992.00 root data:HashAgg - │ └─HashAgg 7992.00 cop[tikv] group by:test.t2.c2, funcs:count(test.t2.c2)->Column#10 + │ └─HashAgg 7992.00 cop[tikv] group by:test.t2.c2, funcs:count(test.t2.c2)->Column#9 │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 10000.00 cop[tikv] table:b keep order:false, stats:pseudo - └─IndexReader(Probe) 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:a, index:PRIMARY(c1) keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:a keep order:false, stats:pseudo explain format = 'brief' select * from t2 order by t2.c2 limit 0, 1; id estRows task access object operator info TopN 1.00 root test.t2.c2, offset:0, count:1 @@ -84,23 +80,23 @@ TopN 1.00 root test.t2.c2, offset:0, count:1 └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where c1 > 1 and c2 = 1 and c3 < 1; id estRows task access object operator info -IndexLookUp 1.11 root -├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false, stats:pseudo -└─Selection(Probe) 1.11 cop[tikv] gt(test.t1.c1, 1), lt(test.t1.c3, 1) - └─TableRowIDScan 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo +IndexLookUp 11.08 root +├─IndexRangeScan(Build) 33.33 cop[tikv] table:t1, index:c2(c2) range:(1 1,1 +inf], keep order:false, stats:pseudo +└─Selection(Probe) 11.08 cop[tikv] lt(test.t1.c3, 1) + └─TableRowIDScan 33.33 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select * from t1 where c1 = 1 and c2 > 1; id estRows task access object operator info Selection 0.33 root gt(test.t1.c2, 1) -└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) +└─Point_Get 1.00 root table:t1 handle:1 explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#9 -└─Projection 10000.00 root cast(Column#8, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo - └─IndexReader(Probe) 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select c1 from t1 where c1 in (select c2 from t2); id estRows task access object operator info HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] @@ -108,23 +104,23 @@ HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] │ └─TableReader 9990.00 root data:Selection │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─IndexReader(Probe) 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select (select count(1) k from t1 s where s.c1 = t1.c1 having k != 0) from t1; id estRows task access object operator info -Projection 10000.00 root ifnull(Column#9, 0)->Column#9 +Projection 10000.00 root ifnull(Column#7, 0)->Column#7 └─MergeJoin 10000.00 root left outer join, left key:test.t1.c1, right key:test.t1.c1 - ├─Projection(Build) 8000.00 root 1->Column#9, test.t1.c1 - │ └─IndexReader 10000.00 root index:IndexFullScan - │ └─IndexFullScan 10000.00 cop[tikv] table:s, index:PRIMARY(c1) keep order:true, stats:pseudo - └─IndexReader(Probe) 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:true, stats:pseudo + ├─Projection(Build) 8000.00 root 1->Column#7, test.t1.c1 + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:s keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo explain format = 'brief' select * from information_schema.columns; id estRows task access object operator info MemTableScan 10000.00 root table:COLUMNS explain format = 'brief' select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1; id estRows task access object operator info -Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#9 +Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#8 └─Apply 10000.00 root CARTESIAN left outer join ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo @@ -135,11 +131,10 @@ Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#9 └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c1 desc limit 1; id estRows task access object operator info -Projection 1.00 root test.t1.c1, test.t1.c2, test.t1.c3 -└─IndexLookUp 1.00 root limit embedded(offset:0, count:1) - ├─Limit(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexFullScan 1.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:true, desc, stats:pseudo - └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Limit 1.00 root offset:0, count:1 +└─TableReader 1.00 root data:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan 1.00 cop[tikv] table:t1 keep order:true, desc, stats:pseudo explain format = 'brief' select * from t4 use index(idx) where a > 1 and b > 1 and c > 1 limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 @@ -154,16 +149,16 @@ id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─TableReader 1.00 root data:Limit └─Limit 1.00 cop[tikv] offset:0, count:1 - └─Selection 1.00 cop[tikv] gt(test.t4.a, 1), gt(test.t4.c, 1) - └─TableFullScan 9.00 cop[tikv] table:t4 keep order:false, stats:pseudo + └─Selection 1.00 cop[tikv] gt(test.t4.c, 1) + └─TableRangeScan 3.00 cop[tikv] table:t4 range:(1,+inf], keep order:false, stats:pseudo explain format = 'brief' select ifnull(null, t1.c1) from t1; id estRows task access object operator info -IndexReader 10000.00 root index:IndexFullScan -└─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select if(10, t1.c1, t1.c2) from t1; id estRows task access object operator info -IndexReader 10000.00 root index:IndexFullScan -└─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select c1 from t2 union select c1 from t2 union all select c1 from t2; id estRows task access object operator info Union 26000.00 root @@ -192,64 +187,64 @@ HashAgg 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#10 └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo select * from information_schema.tidb_indexes where table_name='t4'; TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID IS_VISIBLE CLUSTERED +test t4 0 PRIMARY 1 a NULL NULL 0 YES YES test t4 1 idx 1 a NULL NULL 1 YES NO test t4 1 idx 2 b NULL NULL 1 YES NO -test t4 0 PRIMARY 1 a NULL NULL 2 YES NO -test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 3 YES NO +test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 2 YES NO explain format = 'brief' select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#6 -└─StreamAgg 1.00 root funcs:firstrow(Column#10)->Column#8 +StreamAgg 1.00 root funcs:count(1)->Column#5 +└─StreamAgg 1.00 root funcs:firstrow(Column#9)->Column#7 └─TableReader 1.00 root data:StreamAgg - └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#10 + └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#9 └─Selection 10.00 cop[tikv] eq(test.t1.c3, 100) └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select 1 from (select count(c2), count(c3) from t1) k; id estRows task access object operator info -Projection 1.00 root 1->Column#7 -└─StreamAgg 1.00 root funcs:firstrow(Column#18)->Column#10 - └─IndexReader 1.00 root index:StreamAgg - └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#18 - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo +Projection 1.00 root 1->Column#6 +└─StreamAgg 1.00 root funcs:firstrow(Column#14)->Column#9 + └─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#14 + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select count(1) from (select max(c2), count(c3) as m from t1) k; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#7 -└─StreamAgg 1.00 root funcs:firstrow(Column#17)->Column#9 - └─IndexReader 1.00 root index:StreamAgg - └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#17 - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo +StreamAgg 1.00 root funcs:count(1)->Column#6 +└─StreamAgg 1.00 root funcs:firstrow(Column#13)->Column#8 + └─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:firstrow(1)->Column#13 + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select count(1) from (select count(c2) from t1 group by c3) k; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#6 -└─HashAgg 8000.00 root group by:test.t1.c3, funcs:firstrow(1)->Column#8 +StreamAgg 1.00 root funcs:count(1)->Column#5 +└─HashAgg 8000.00 root group by:test.t1.c3, funcs:firstrow(1)->Column#7 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo set @@session.tidb_opt_insubq_to_join_and_agg=0; explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#9 -└─Projection 10000.00 root cast(Column#8, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo - └─IndexReader(Probe) 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select 1 in (select c2 from t2) from t1; id estRows task access object operator info HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─IndexReader(Probe) 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select sum(6 in (select c2 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#12)->Column#9 -└─Projection 10000.00 root cast(Column#8, decimal(65,0) BINARY)->Column#12 +StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(6, test.t2.c2) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─IndexReader(Probe) 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format="dot" select sum(t1.c1 in (select c1 from t2)) from t1; dot contents @@ -260,14 +255,14 @@ color=black label = "root" "StreamAgg_9" -> "Projection_20" "Projection_20" -> "HashJoin_19" -"HashJoin_19" -> "IndexReader_14" +"HashJoin_19" -> "TableReader_12" "HashJoin_19" -> "IndexReader_18" } -subgraph cluster13{ +subgraph cluster11{ node [style=filled, color=lightgrey] color=black label = "cop" -"IndexFullScan_13" +"TableFullScan_11" } subgraph cluster17{ node [style=filled, color=lightgrey] @@ -275,7 +270,7 @@ color=black label = "cop" "IndexFullScan_17" } -"IndexReader_14" -> "IndexFullScan_13" +"TableReader_12" -> "TableFullScan_11" "IndexReader_18" -> "IndexFullScan_17" } @@ -287,23 +282,23 @@ subgraph cluster7{ node [style=filled, color=lightgrey] color=black label = "root" -"HashJoin_7" -> "IndexReader_13" -"HashJoin_7" -> "TableReader_15" +"HashJoin_7" -> "TableReader_9" +"HashJoin_7" -> "TableReader_13" } -subgraph cluster12{ +subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "cop" -"IndexFullScan_12" +"TableFullScan_8" } -subgraph cluster14{ +subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_14" +"TableFullScan_12" } -"IndexReader_13" -> "IndexFullScan_12" -"TableReader_15" -> "TableFullScan_14" +"TableReader_9" -> "TableFullScan_8" +"TableReader_13" -> "TableFullScan_12" } drop table if exists t1, t2, t3, t4; @@ -311,87 +306,86 @@ drop table if exists t; create table t(a int primary key, b int, c int, index idx(b)); explain format = 'brief' select t.c in (select count(*) from t s ignore index(idx), t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection 10000.00 root Column#14 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 10000.00 root Column#11 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 └─MergeJoin 12.50 root inner join, left key:test.t.a, right key:test.t.a - ├─IndexReader(Build) 10.00 root index:IndexRangeScan - │ └─IndexRangeScan 10.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo - └─IndexReader(Probe) 10.00 root index:IndexRangeScan - └─IndexRangeScan 10.00 cop[tikv] table:s, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo + ├─TableReader(Build) 1.00 root data:TableRangeScan + │ └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo + └─TableReader(Probe) 1.00 root data:TableRangeScan + └─TableRangeScan 1.00 cop[tikv] table:s range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection 10000.00 root Column#14 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 10000.00 root Column#11 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 - └─IndexJoin 12.50 root inner join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─IndexLookUp(Build) 10.00 root - │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo - │ └─TableRowIDScan(Probe) 10.00 cop[tikv] table:s keep order:false, stats:pseudo - └─IndexReader(Probe) 1.00 root index:IndexRangeScan - └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false, stats:pseudo + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─IndexJoin 12.50 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─IndexReader(Build) 10.00 root index:IndexRangeScan + │ └─IndexRangeScan 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo + └─TableReader(Probe) 1.00 root data:TableRangeScan + └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false, stats:pseudo explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.c = t1.a) from t; id estRows task access object operator info -Projection 10000.00 root Column#14 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 10000.00 root Column#11 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 - └─IndexJoin 12.49 root inner join, inner:IndexReader, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─IndexJoin 12.49 root inner join, inner:TableReader, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) ├─IndexLookUp(Build) 9.99 root │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo │ └─Selection(Probe) 9.99 cop[tikv] not(isnull(test.t.c)) │ └─TableRowIDScan 10.00 cop[tikv] table:s keep order:false, stats:pseudo - └─IndexReader(Probe) 1.00 root index:IndexRangeScan - └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.c)], keep order:false, stats:pseudo + └─TableReader(Probe) 1.00 root data:TableRangeScan + └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.c], keep order:false, stats:pseudo insert into t values(1, 1, 1), (2, 2 ,2), (3, 3, 3), (4, 3, 4),(5,3,5); analyze table t; explain format = 'brief' select t.c in (select count(*) from t s, t t1 where s.b = t.a and s.b = 3 and s.a = t1.a) from t; id estRows task access object operator info -Projection 5.00 root Column#14 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 5.00 root Column#11 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 - └─HashJoin 2.40 root inner join, equal:[eq(test.t.a, test.t.a)] - ├─TableReader(Build) 2.40 root data:Selection - │ └─Selection 2.40 cop[tikv] eq(3, test.t.a), eq(test.t.b, 3) - │ └─TableFullScan 5.00 cop[tikv] table:s keep order:false - └─TableReader(Probe) 4.00 root data:Selection - └─Selection 4.00 cop[tikv] eq(3, test.t.a) - └─TableFullScan 5.00 cop[tikv] table:t1 keep order:false + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─MergeJoin 2.40 root inner join, left key:test.t.a, right key:test.t.a + ├─TableReader(Build) 4.00 root data:Selection + │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) + │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:true + └─IndexReader(Probe) 2.40 root index:Selection + └─Selection 2.40 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain format = 'brief' select t.c in (select count(*) from t s left join t t1 on s.a = t1.a where 3 = t.a and s.b = 3) from t; id estRows task access object operator info -Projection 5.00 root Column#14 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 5.00 root Column#11 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 - └─IndexJoin 2.40 root left outer join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─TableReader(Build) 2.40 root data:Selection - │ └─Selection 2.40 cop[tikv] eq(3, test.t.a), eq(test.t.b, 3) - │ └─TableFullScan 5.00 cop[tikv] table:s keep order:false - └─IndexReader(Probe) 1.00 root index:Selection - └─Selection 1.00 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─MergeJoin 2.40 root left outer join, left key:test.t.a, right key:test.t.a + ├─TableReader(Build) 4.00 root data:Selection + │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) + │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:true + └─IndexReader(Probe) 2.40 root index:Selection + └─Selection 2.40 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain format = 'brief' select t.c in (select count(*) from t s right join t t1 on s.a = t1.a where 3 = t.a and t1.b = 3) from t; id estRows task access object operator info -Projection 5.00 root Column#14 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 5.00 root Column#11 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 - └─IndexJoin 2.40 root right outer join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─TableReader(Build) 2.40 root data:Selection - │ └─Selection 2.40 cop[tikv] eq(3, test.t.a), eq(test.t.b, 3) - │ └─TableFullScan 5.00 cop[tikv] table:t1 keep order:false - └─IndexReader(Probe) 1.00 root index:Selection - └─Selection 1.00 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan 1.00 cop[tikv] table:s, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─MergeJoin 2.40 root right outer join, left key:test.t.a, right key:test.t.a + ├─TableReader(Build) 4.00 root data:Selection + │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) + │ └─TableFullScan 5.00 cop[tikv] table:s keep order:true + └─IndexReader(Probe) 2.40 root index:Selection + └─Selection 2.40 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan 3.00 cop[tikv] table:t1, index:idx(b) range:[3,3], keep order:true drop table if exists t; create table t(a int unsigned); explain format = 'brief' select t.a = '123455' from t; @@ -459,12 +453,12 @@ id estRows task access object operator info TableDual 8000.00 root rows:0 explain format = 'brief' select null or a > 1 from t; id estRows task access object operator info -Projection 10000.00 root or(, gt(test.t.a, 1))->Column#3 -└─IndexReader 10000.00 root index:IndexFullScan - └─IndexFullScan 10000.00 cop[tikv] table:t, index:PRIMARY(a) keep order:false, stats:pseudo +Projection 10000.00 root or(, gt(test.t.a, 1))->Column#2 +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select * from t where a = 1 for update; id estRows task access object operator info -Point_Get 1.00 root table:t, index:PRIMARY(a) lock +Point_Get 1.00 root table:t handle:1, lock drop table if exists ta, tb; create table ta (a varchar(20)); create table tb (a varchar(20)); @@ -503,10 +497,10 @@ PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; explain format = 'brief' SELECT COUNT(1) FROM (SELECT COALESCE(b.region_name, '不详') region_name, SUM(a.registration_num) registration_num FROM (SELECT stat_date, show_date, region_id, 0 registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202 UNION ALL SELECT stat_date, show_date, region_id, registration_num registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202) a LEFT JOIN test02 b ON a.region_id = b.id WHERE registration_num > 0 AND a.stat_date >= '20191202' AND a.stat_date <= '20191202' GROUP BY a.stat_date , a.show_date , COALESCE(b.region_name, '不详') ) JLS; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#25 -└─HashAgg 8000.00 root group by:Column#38, Column#39, Column#40, funcs:firstrow(1)->Column#34 - └─Projection 10000.01 root Column#16, Column#17, coalesce(test.test02.region_name, 不详)->Column#40 - └─HashJoin 10000.01 root left outer join, equal:[eq(Column#18, test.test02.id)] +StreamAgg 1.00 root funcs:count(1)->Column#22 +└─HashAgg 8000.00 root group by:Column#32, Column#33, Column#34, funcs:firstrow(1)->Column#31 + └─Projection 10000.01 root Column#14, Column#15, coalesce(test.test02.region_name, 不详)->Column#34 + └─HashJoin 10000.01 root left outer join, equal:[eq(Column#16, test.test02.id)] ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:b keep order:false, stats:pseudo └─Union(Probe) 8000.01 root @@ -693,7 +687,8 @@ insert into t values (1, 1); explain format = 'brief' update t set j = -j where i = 1 and j = 1; id estRows task access object operator info Update N/A root N/A -└─Point_Get 1.00 root table:t, index:i(i, j) +└─Selection 1.00 root eq(test.t.j, 1) + └─Point_Get 1.00 root table:t handle:1 rollback; drop table if exists t; create table t(a int); diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index 9af4317aea632..92eee10bfc47c 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -28,10 +28,9 @@ TableReader 1999.00 root data:TableFullScan └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from t1 order by c2; id estRows task access object operator info -Projection 1999.00 root test.t1.c1, test.t1.c2, test.t1.c3 -└─IndexLookUp 1999.00 root - ├─IndexFullScan(Build) 1999.00 cop[tikv] table:t1, index:c2(c2) keep order:true - └─TableRowIDScan(Probe) 1999.00 cop[tikv] table:t1 keep order:false +IndexLookUp 1999.00 root +├─IndexFullScan(Build) 1999.00 cop[tikv] table:t1, index:c2(c2) keep order:true +└─TableRowIDScan(Probe) 1999.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from t2 order by c2; id estRows task access object operator info Sort 1985.00 root test.t2.c2 @@ -39,27 +38,24 @@ Sort 1985.00 root test.t2.c2 └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false explain format = 'brief' select * from t1 where t1.c1 > 0; id estRows task access object operator info -TableReader 1999.00 root data:Selection -└─Selection 1999.00 cop[tikv] gt(test.t1.c1, 0) - └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false +TableReader 1999.00 root data:TableRangeScan +└─TableRangeScan 1999.00 cop[tikv] table:t1 range:(0,+inf], keep order:false explain format = 'brief' select t1.c1, t1.c2 from t1 where t1.c2 = 1; id estRows task access object operator info -IndexLookUp 0.00 root -├─IndexRangeScan(Build) 0.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false -└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1 keep order:false +IndexReader 0.00 root index:IndexRangeScan +└─IndexRangeScan 0.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false explain format = 'brief' select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id estRows task access object operator info HashJoin 2481.25 root left outer join, equal:[eq(test.t1.c2, test.t2.c1)] ├─TableReader(Build) 1985.00 root data:Selection │ └─Selection 1985.00 cop[tikv] not(isnull(test.t2.c1)) │ └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false -└─TableReader(Probe) 1998.00 root data:Selection - └─Selection 1998.00 cop[tikv] gt(test.t1.c1, 1) - └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false +└─TableReader(Probe) 1998.00 root data:TableRangeScan + └─TableRangeScan 1998.00 cop[tikv] table:t1 range:(1,+inf], keep order:false explain format = 'brief' update t1 set t1.c2 = 2 where t1.c1 = 1; id estRows task access object operator info Update N/A root N/A -└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) +└─Point_Get 1.00 root table:t1 handle:1 explain format = 'brief' delete from t1 where t1.c2 = 1; id estRows task access object operator info Delete N/A root N/A @@ -68,14 +64,14 @@ Delete N/A root N/A └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id estRows task access object operator info -Projection 1985.00 root cast(Column#9, bigint(21) BINARY)->Column#8 +Projection 1985.00 root cast(Column#8, bigint(21) BINARY)->Column#7 └─HashJoin 1985.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] - ├─HashAgg(Build) 1985.00 root group by:test.t2.c2, funcs:count(test.t2.c2)->Column#9, funcs:firstrow(test.t2.c2)->test.t2.c2 + ├─HashAgg(Build) 1985.00 root group by:test.t2.c2, funcs:count(test.t2.c2)->Column#8, funcs:firstrow(test.t2.c2)->test.t2.c2 │ └─TableReader 1985.00 root data:Selection │ └─Selection 1985.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 1985.00 cop[tikv] table:b keep order:false - └─IndexReader(Probe) 1999.00 root index:IndexFullScan - └─IndexFullScan 1999.00 cop[tikv] table:a, index:PRIMARY(c1) keep order:false + └─TableReader(Probe) 1999.00 root data:TableFullScan + └─TableFullScan 1999.00 cop[tikv] table:a keep order:false explain format = 'brief' select * from t2 order by t2.c2 limit 0, 1; id estRows task access object operator info TopN 1.00 root test.t2.c2, offset:0, count:1 @@ -85,13 +81,13 @@ TopN 1.00 root test.t2.c2, offset:0, count:1 explain format = 'brief' select * from t1 where c1 > 1 and c2 = 1 and c3 < 1; id estRows task access object operator info IndexLookUp 0.00 root -├─IndexRangeScan(Build) 0.00 cop[tikv] table:t1, index:c2(c2) range:[1,1], keep order:false -└─Selection(Probe) 0.00 cop[tikv] gt(test.t1.c1, 1), lt(test.t1.c3, 1) +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t1, index:c2(c2) range:(1 1,1 +inf], keep order:false +└─Selection(Probe) 0.00 cop[tikv] lt(test.t1.c3, 1) └─TableRowIDScan 0.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from t1 where c1 = 1 and c2 > 1; id estRows task access object operator info Selection 0.50 root gt(test.t1.c2, 1) -└─Point_Get 1.00 root table:t1, index:PRIMARY(c1) +└─Point_Get 1.00 root table:t1 handle:1 explain format = 'brief' select c1 from t1 where c1 in (select c2 from t2); id estRows task access object operator info HashJoin 1985.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] @@ -99,14 +95,14 @@ HashJoin 1985.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] │ └─TableReader 1985.00 root data:Selection │ └─Selection 1985.00 cop[tikv] not(isnull(test.t2.c2)) │ └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false -└─IndexReader(Probe) 1999.00 root index:IndexFullScan - └─IndexFullScan 1999.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false +└─TableReader(Probe) 1999.00 root data:TableFullScan + └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false explain format = 'brief' select * from information_schema.columns; id estRows task access object operator info MemTableScan 10000.00 root table:COLUMNS explain format = 'brief' select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1; id estRows task access object operator info -Projection 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#9 +Projection 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#8 └─Apply 1999.00 root CARTESIAN left outer join ├─TableReader(Build) 1999.00 root data:TableFullScan │ └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false @@ -117,19 +113,18 @@ Projection 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#9 └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain format = 'brief' select * from t1 order by c1 desc limit 1; id estRows task access object operator info -Projection 1.00 root test.t1.c1, test.t1.c2, test.t1.c3 -└─IndexLookUp 1.00 root limit embedded(offset:0, count:1) - ├─Limit(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexFullScan 1.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:true, desc - └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Limit 1.00 root offset:0, count:1 +└─TableReader 1.00 root data:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan 1.00 cop[tikv] table:t1 keep order:true, desc set @@session.tidb_opt_insubq_to_join_and_agg=0; explain format = 'brief' select 1 in (select c2 from t2) from t1; id estRows task access object operator info HashJoin 1999.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) ├─TableReader(Build) 1985.00 root data:TableFullScan │ └─TableFullScan 1985.00 cop[tikv] table:t2 keep order:false -└─IndexReader(Probe) 1999.00 root index:IndexFullScan - └─IndexFullScan 1999.00 cop[tikv] table:t1, index:PRIMARY(c1) keep order:false +└─TableReader(Probe) 1999.00 root data:TableFullScan + └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false explain format="dot" select 1 in (select c2 from t2) from t1; dot contents @@ -138,23 +133,23 @@ subgraph cluster7{ node [style=filled, color=lightgrey] color=black label = "root" -"HashJoin_7" -> "IndexReader_13" -"HashJoin_7" -> "TableReader_15" +"HashJoin_7" -> "TableReader_9" +"HashJoin_7" -> "TableReader_13" } -subgraph cluster12{ +subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "cop" -"IndexFullScan_12" +"TableFullScan_8" } -subgraph cluster14{ +subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_14" +"TableFullScan_12" } -"IndexReader_13" -> "IndexFullScan_12" -"TableReader_15" -> "TableFullScan_14" +"TableReader_9" -> "TableFullScan_8" +"TableReader_13" -> "TableFullScan_12" } explain format = 'brief' select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 LIMIT 1; diff --git a/cmd/explaintest/r/explain_indexmerge.result b/cmd/explaintest/r/explain_indexmerge.result index 2abce3c9e76ba..4a048b40da7f7 100644 --- a/cmd/explaintest/r/explain_indexmerge.result +++ b/cmd/explaintest/r/explain_indexmerge.result @@ -22,19 +22,17 @@ TableReader 98.00 root data:Selection set session tidb_enable_index_merge = on; explain format = 'brief' select * from t where a < 50 or b < 50; id estRows task access object operator info -Projection 98.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 98.00 root - ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false - ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false - └─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false +IndexMerge 98.00 root +├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false +├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false +└─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where (a < 50 or b < 50) and f > 100; id estRows task access object operator info -Projection 98.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 98.00 root - ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false - ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false - └─Selection(Probe) 98.00 cop[tikv] gt(test.t.f, 100) - └─TableRowIDScan 98.00 cop[tikv] table:t keep order:false +IndexMerge 98.00 root +├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false +├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false +└─Selection(Probe) 98.00 cop[tikv] gt(test.t.f, 100) + └─TableRowIDScan 98.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where a < 50 or b < 5000000; id estRows task access object operator info TableReader 4999999.00 root data:Selection @@ -42,11 +40,10 @@ TableReader 4999999.00 root data:Selection └─TableFullScan 5000000.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where b < 50 or c < 50; id estRows task access object operator info -Projection 98.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 98.00 root - ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false - ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false - └─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false +IndexMerge 98.00 root +├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false +├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false +└─TableRowIDScan(Probe) 98.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where b < 50 or c < 5000000; id estRows task access object operator info TableReader 4999999.00 root data:Selection @@ -54,35 +51,33 @@ TableReader 4999999.00 root data:Selection └─TableFullScan 5000000.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where a < 50 or b < 50 or c < 50; id estRows task access object operator info -Projection 147.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 147.00 root - ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false - ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false - ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false - └─TableRowIDScan(Probe) 147.00 cop[tikv] table:t keep order:false +IndexMerge 147.00 root +├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false +├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false +├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tc(c) range:[-inf,50), keep order:false +└─TableRowIDScan(Probe) 147.00 cop[tikv] table:t keep order:false explain format = 'brief' select * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10; id estRows task access object operator info -Projection 0.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 0.00 root - ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tb(b) range:[-inf,10000), keep order:false - ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tc(c) range:[-inf,10000), keep order:false - └─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.a, 10), lt(test.t.d, 10)) - └─TableRowIDScan 19978.00 cop[tikv] table:t keep order:false +IndexMerge 0.00 root +├─TableRangeScan(Build) 9.00 cop[tikv] table:t range:[-inf,10), keep order:false +├─IndexRangeScan(Build) 9.00 cop[tikv] table:t, index:td(d) range:[-inf,10), keep order:false +└─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.b, 10000), lt(test.t.c, 10000)) + └─TableRowIDScan 18.00 cop[tikv] table:t keep order:false explain format="dot" select * from t where (a < 50 or b < 50) and f > 100; dot contents -digraph Projection_4 { -subgraph cluster4{ +digraph IndexMerge_12 { +subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "root" -"Projection_4" -> "IndexMerge_12" +"IndexMerge_12" } subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "cop" -"IndexRangeScan_8" +"TableRangeScan_8" } subgraph cluster9{ node [style=filled, color=lightgrey] @@ -96,7 +91,7 @@ color=black label = "cop" "Selection_11" -> "TableRowIDScan_10" } -"IndexMerge_12" -> "IndexRangeScan_8" +"IndexMerge_12" -> "TableRangeScan_8" "IndexMerge_12" -> "IndexRangeScan_9" "IndexMerge_12" -> "Selection_11" } @@ -104,27 +99,24 @@ label = "cop" set session tidb_enable_index_merge = off; explain format = 'brief' select /*+ use_index_merge(t, primary, tb, tc) */ * from t where a <= 500000 or b <= 1000000 or c <= 3000000; id estRows task access object operator info -Projection 3560000.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 3560000.00 root - ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,500000], keep order:false - ├─IndexRangeScan(Build) 1000000.00 cop[tikv] table:t, index:tb(b) range:[-inf,1000000], keep order:false - ├─IndexRangeScan(Build) 3000000.00 cop[tikv] table:t, index:tc(c) range:[-inf,3000000], keep order:false - └─TableRowIDScan(Probe) 3560000.00 cop[tikv] table:t keep order:false +IndexMerge 3560000.00 root +├─TableRangeScan(Build) 500000.00 cop[tikv] table:t range:[-inf,500000], keep order:false +├─IndexRangeScan(Build) 1000000.00 cop[tikv] table:t, index:tb(b) range:[-inf,1000000], keep order:false +├─IndexRangeScan(Build) 3000000.00 cop[tikv] table:t, index:tc(c) range:[-inf,3000000], keep order:false +└─TableRowIDScan(Probe) 3560000.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, tb, tc) */ * from t where b < 50 or c < 5000000; id estRows task access object operator info -Projection 4999999.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 4999999.00 root - ├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false - ├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tc(c) range:[-inf,5000000), keep order:false - └─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false +IndexMerge 4999999.00 root +├─IndexRangeScan(Build) 49.00 cop[tikv] table:t, index:tb(b) range:[-inf,50), keep order:false +├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tc(c) range:[-inf,5000000), keep order:false +└─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, tb, tc) */ * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10; id estRows task access object operator info -Projection 0.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 0.00 root - ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tb(b) range:[-inf,10000), keep order:false - ├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tc(c) range:[-inf,10000), keep order:false - └─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.a, 10), lt(test.t.d, 10)) - └─TableRowIDScan 19978.00 cop[tikv] table:t keep order:false +IndexMerge 0.00 root +├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tb(b) range:[-inf,10000), keep order:false +├─IndexRangeScan(Build) 9999.00 cop[tikv] table:t, index:tc(c) range:[-inf,10000), keep order:false +└─Selection(Probe) 0.00 cop[tikv] lt(test.t.f, 10), or(lt(test.t.a, 10), lt(test.t.d, 10)) + └─TableRowIDScan 19978.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, tb) */ * from t where b < 50 or c < 5000000; id estRows task access object operator info TableReader 4999999.00 root data:Selection @@ -137,11 +129,10 @@ TableReader 4999999.00 root data:Selection └─TableFullScan 5000000.00 cop[tikv] table:t keep order:false explain format = 'brief' select /*+ use_index_merge(t, primary, tb) */ * from t where a < 50 or b < 5000000; id estRows task access object operator info -Projection 4999999.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f -└─IndexMerge 4999999.00 root - ├─IndexRangeScan(Build) 1661666.67 cop[tikv] table:t, index:PRIMARY(a) range:[-inf,50), keep order:false - ├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tb(b) range:[-inf,5000000), keep order:false - └─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false +IndexMerge 4999999.00 root +├─TableRangeScan(Build) 49.00 cop[tikv] table:t range:[-inf,50), keep order:false +├─IndexRangeScan(Build) 4999999.00 cop[tikv] table:t, index:tb(b) range:[-inf,5000000), keep order:false +└─TableRowIDScan(Probe) 4999999.00 cop[tikv] table:t keep order:false set session tidb_enable_index_merge = on; drop table if exists t; CREATE TABLE t ( @@ -155,8 +146,7 @@ KEY `aid_c2` (`aid`,`c2`) ); desc select /*+ USE_INDEX_MERGE(t, aid_c1, aid_c2) */ * from t where (aid = 1 and c1='aaa') or (aid = 2 and c2='bbb'); id estRows task access object operator info -Projection_4 8.08 root test.t.id, test.t.aid, test.t.c1, test.t.c2 -└─IndexMerge_8 269.49 root - ├─IndexRangeScan_5(Build) 0.10 cop[tikv] table:t, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo - ├─IndexRangeScan_6(Build) 0.10 cop[tikv] table:t, index:aid_c2(aid, c2) range:[2 "bbb",2 "bbb"], keep order:false, stats:pseudo - └─TableRowIDScan_7(Probe) 269.49 cop[tikv] table:t keep order:false, stats:pseudo +IndexMerge_8 269.49 root +├─IndexRangeScan_5(Build) 0.10 cop[tikv] table:t, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo +├─IndexRangeScan_6(Build) 0.10 cop[tikv] table:t, index:aid_c2(aid, c2) range:[2 "bbb",2 "bbb"], keep order:false, stats:pseudo +└─TableRowIDScan_7(Probe) 269.49 cop[tikv] table:t keep order:false, stats:pseudo diff --git a/cmd/explaintest/r/explain_join_stats.result b/cmd/explaintest/r/explain_join_stats.result index 7a32346ea4673..15e68179c5085 100644 --- a/cmd/explaintest/r/explain_join_stats.result +++ b/cmd/explaintest/r/explain_join_stats.result @@ -6,20 +6,20 @@ create table lo(a int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (a)) ENGINE=InnoD load stats 's/explain_join_stats_lo.json'; explain format = 'brief' select count(*) from e, lo where lo.a=e.a and e.b=22336; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#6 +StreamAgg 1.00 root funcs:count(1)->Column#5 └─HashJoin 19977.00 root inner join, equal:[eq(test.lo.a, test.e.a)] - ├─IndexReader(Build) 250.00 root index:IndexFullScan - │ └─IndexFullScan 250.00 cop[tikv] table:lo, index:PRIMARY(a) keep order:false + ├─TableReader(Build) 250.00 root data:TableFullScan + │ └─TableFullScan 250.00 cop[tikv] table:lo keep order:false └─IndexLookUp(Probe) 19977.00 root ├─IndexRangeScan(Build) 19977.00 cop[tikv] table:e, index:idx_b(b) range:[22336,22336], keep order:false └─Selection(Probe) 19977.00 cop[tikv] not(isnull(test.e.a)) └─TableRowIDScan 19977.00 cop[tikv] table:e keep order:false explain format = 'brief' select /*+ TIDB_INLJ(e) */ count(*) from e, lo where lo.a=e.a and e.b=22336; id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#6 +StreamAgg 1.00 root funcs:count(1)->Column#5 └─IndexJoin 19977.00 root inner join, inner:IndexLookUp, outer key:test.lo.a, inner key:test.e.a, equal cond:eq(test.lo.a, test.e.a) - ├─IndexReader(Build) 250.00 root index:IndexFullScan - │ └─IndexFullScan 250.00 cop[tikv] table:lo, index:PRIMARY(a) keep order:false + ├─TableReader(Build) 250.00 root data:TableFullScan + │ └─TableFullScan 250.00 cop[tikv] table:lo keep order:false └─IndexLookUp(Probe) 79.91 root ├─Selection(Build) 4080.00 cop[tikv] not(isnull(test.e.a)) │ └─IndexRangeScan 4080.00 cop[tikv] table:e, index:idx_a(a) range: decided by [eq(test.e.a, test.lo.a)], keep order:false diff --git a/cmd/explaintest/r/partition_pruning.result b/cmd/explaintest/r/partition_pruning.result index c306f188eff22..b3c3a8b3169b9 100644 --- a/cmd/explaintest/r/partition_pruning.result +++ b/cmd/explaintest/r/partition_pruning.result @@ -16,16 +16,16 @@ PARTITION max VALUES LESS THAN MAXVALUE); INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8); explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo explain format = 'brief' SELECT * FROM t1 WHERE a < 7; id estRows task access object operator info -IndexReader 3323.33 root partition:all index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,7), keep order:false, stats:pseudo +TableReader 3333.33 root partition:all data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,7), keep order:false, stats:pseudo explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo DROP TABLE t1; # # Bug#49742: Partition Pruning not working correctly for RANGE @@ -46,8 +46,8 @@ a 0 explain format = 'brief' SELECT * FROM t1 WHERE a < 1; id estRows task access object operator info -IndexReader 3323.33 root partition:p0 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 2 order by a; a -1 @@ -55,8 +55,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a < 2; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 3 order by a; a -1 @@ -65,8 +65,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a < 3; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 4 order by a; a -1 @@ -76,8 +76,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a < 4; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 5 order by a; a -1 @@ -88,8 +88,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a < 5; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 6 order by a; a -1 @@ -101,8 +101,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a < 6; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3,p4,p5 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3,p4,p5 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 7 order by a; a -1 @@ -115,8 +115,8 @@ a 6 explain format = 'brief' SELECT * FROM t1 WHERE a < 7; id estRows task access object operator info -IndexReader 3323.33 root partition:all index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,7), keep order:false, stats:pseudo +TableReader 3333.33 root partition:all data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,7), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 1 order by a; a -1 @@ -124,8 +124,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 2 order by a; a -1 @@ -134,8 +134,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a <= 2; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 3 order by a; a -1 @@ -145,8 +145,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a <= 3; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 4 order by a; a -1 @@ -157,8 +157,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a <= 4; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 5 order by a; a -1 @@ -170,8 +170,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a <= 5; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3,p4,p5 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3,p4,p5 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 6 order by a; a -1 @@ -184,8 +184,8 @@ a 6 explain format = 'brief' SELECT * FROM t1 WHERE a <= 6; id estRows task access object operator info -IndexReader 3323.33 root partition:all index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6], keep order:false, stats:pseudo +TableReader 3333.33 root partition:all data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 7 order by a; a -1 @@ -199,57 +199,57 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a <= 7; id estRows task access object operator info -IndexReader 3323.33 root partition:all index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,7], keep order:false, stats:pseudo +TableReader 3333.33 root partition:all data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,7], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 1 order by a; a 1 explain format = 'brief' SELECT * FROM t1 WHERE a = 1; id estRows task access object operator info -IndexReader 1.00 root partition:p1 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[1,1], keep order:false, stats:pseudo +TableReader 1.00 root partition:p1 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[1,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 2 order by a; a 2 explain format = 'brief' SELECT * FROM t1 WHERE a = 2; id estRows task access object operator info -IndexReader 1.00 root partition:p2 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[2,2], keep order:false, stats:pseudo +TableReader 1.00 root partition:p2 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[2,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 3 order by a; a 3 explain format = 'brief' SELECT * FROM t1 WHERE a = 3; id estRows task access object operator info -IndexReader 1.00 root partition:p3 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[3,3], keep order:false, stats:pseudo +TableReader 1.00 root partition:p3 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[3,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 4 order by a; a 4 explain format = 'brief' SELECT * FROM t1 WHERE a = 4; id estRows task access object operator info -IndexReader 1.00 root partition:p4 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[4,4], keep order:false, stats:pseudo +TableReader 1.00 root partition:p4 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[4,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 5 order by a; a 5 explain format = 'brief' SELECT * FROM t1 WHERE a = 5; id estRows task access object operator info -IndexReader 1.00 root partition:p5 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[5,5], keep order:false, stats:pseudo +TableReader 1.00 root partition:p5 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[5,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 6 order by a; a 6 explain format = 'brief' SELECT * FROM t1 WHERE a = 6; id estRows task access object operator info -IndexReader 1.00 root partition:max index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[6,6], keep order:false, stats:pseudo +TableReader 1.00 root partition:max data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[6,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 7 order by a; a 7 explain format = 'brief' SELECT * FROM t1 WHERE a = 7; id estRows task access object operator info -IndexReader 1.00 root partition:max index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[7,7], keep order:false, stats:pseudo +TableReader 1.00 root partition:max data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[7,7], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 1 order by a; a 1 @@ -262,8 +262,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 1; id estRows task access object operator info -IndexReader 3333.33 root partition:p1,p2,p3,p4,p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[1,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p1,p2,p3,p4,p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 2 order by a; a 2 @@ -275,8 +275,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 2; id estRows task access object operator info -IndexReader 3333.33 root partition:p2,p3,p4,p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[2,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p2,p3,p4,p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 3 order by a; a 3 @@ -287,8 +287,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 3; id estRows task access object operator info -IndexReader 3333.33 root partition:p3,p4,p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[3,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p3,p4,p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 4 order by a; a 4 @@ -298,8 +298,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 4; id estRows task access object operator info -IndexReader 3333.33 root partition:p4,p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[4,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p4,p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 5 order by a; a 5 @@ -308,8 +308,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 5; id estRows task access object operator info -IndexReader 3333.33 root partition:p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[5,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 6 order by a; a 6 @@ -317,16 +317,16 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 6; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[6,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[6,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 7 order by a; a 7 8 explain format = 'brief' SELECT * FROM t1 WHERE a >= 7; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[7,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[7,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 1 order by a; a 2 @@ -338,8 +338,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 1; id estRows task access object operator info -IndexReader 3333.33 root partition:p2,p3,p4,p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(1,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p2,p3,p4,p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 2 order by a; a 3 @@ -350,8 +350,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 2; id estRows task access object operator info -IndexReader 3333.33 root partition:p3,p4,p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(2,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p3,p4,p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 3 order by a; a 4 @@ -361,8 +361,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 3; id estRows task access object operator info -IndexReader 3333.33 root partition:p4,p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(3,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p4,p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 4 order by a; a 5 @@ -371,8 +371,8 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 4; id estRows task access object operator info -IndexReader 3333.33 root partition:p5,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(4,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p5,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 5 order by a; a 6 @@ -380,23 +380,23 @@ a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 5; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(5,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 6 order by a; a 7 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 6; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(6,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(6,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 7 order by a; a 8 explain format = 'brief' SELECT * FROM t1 WHERE a > 7; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(7,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(7,+inf], keep order:false, stats:pseudo DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY) PARTITION BY RANGE (a) ( @@ -413,8 +413,8 @@ a 0 explain format = 'brief' SELECT * FROM t1 WHERE a < 1; id estRows task access object operator info -IndexReader 3323.33 root partition:p0 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 2 order by a; a -1 @@ -422,8 +422,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a < 2; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 3 order by a; a -1 @@ -432,8 +432,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a < 3; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 4 order by a; a -1 @@ -443,8 +443,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a < 4; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 5 order by a; a -1 @@ -455,8 +455,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a < 5; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5), keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a < 6 order by a; a -1 @@ -468,8 +468,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a < 6; id estRows task access object operator info -IndexReader 3323.33 root partition:all index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6), keep order:false, stats:pseudo +TableReader 3333.33 root partition:all data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6), keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 1 order by a; a -1 @@ -477,8 +477,8 @@ a 1 explain format = 'brief' SELECT * FROM t1 WHERE a <= 1; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,1], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 2 order by a; a -1 @@ -487,8 +487,8 @@ a 2 explain format = 'brief' SELECT * FROM t1 WHERE a <= 2; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,2], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 3 order by a; a -1 @@ -498,8 +498,8 @@ a 3 explain format = 'brief' SELECT * FROM t1 WHERE a <= 3; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,3], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 4 order by a; a -1 @@ -510,8 +510,8 @@ a 4 explain format = 'brief' SELECT * FROM t1 WHERE a <= 4; id estRows task access object operator info -IndexReader 3323.33 root partition:p0,p1,p2,p3,p4 index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,4], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p0,p1,p2,p3,p4 data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 5 order by a; a -1 @@ -523,8 +523,8 @@ a 5 explain format = 'brief' SELECT * FROM t1 WHERE a <= 5; id estRows task access object operator info -IndexReader 3323.33 root partition:all index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,5], keep order:false, stats:pseudo +TableReader 3333.33 root partition:all data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a <= 6 order by a; a -1 @@ -537,50 +537,50 @@ a 6 explain format = 'brief' SELECT * FROM t1 WHERE a <= 6; id estRows task access object operator info -IndexReader 3323.33 root partition:all index:IndexRangeScan -└─IndexRangeScan 3323.33 cop[tikv] table:t1, index:PRIMARY(a) range:[-inf,6], keep order:false, stats:pseudo +TableReader 3333.33 root partition:all data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[-inf,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 1; a 1 explain format = 'brief' SELECT * FROM t1 WHERE a = 1; id estRows task access object operator info -IndexReader 1.00 root partition:p1 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[1,1], keep order:false, stats:pseudo +TableReader 1.00 root partition:p1 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[1,1], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 2; a 2 explain format = 'brief' SELECT * FROM t1 WHERE a = 2; id estRows task access object operator info -IndexReader 1.00 root partition:p2 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[2,2], keep order:false, stats:pseudo +TableReader 1.00 root partition:p2 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[2,2], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 3; a 3 explain format = 'brief' SELECT * FROM t1 WHERE a = 3; id estRows task access object operator info -IndexReader 1.00 root partition:p3 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[3,3], keep order:false, stats:pseudo +TableReader 1.00 root partition:p3 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[3,3], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 4; a 4 explain format = 'brief' SELECT * FROM t1 WHERE a = 4; id estRows task access object operator info -IndexReader 1.00 root partition:p4 index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[4,4], keep order:false, stats:pseudo +TableReader 1.00 root partition:p4 data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[4,4], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 5; a 5 explain format = 'brief' SELECT * FROM t1 WHERE a = 5; id estRows task access object operator info -IndexReader 1.00 root partition:max index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[5,5], keep order:false, stats:pseudo +TableReader 1.00 root partition:max data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[5,5], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a = 6; a 6 explain format = 'brief' SELECT * FROM t1 WHERE a = 6; id estRows task access object operator info -IndexReader 1.00 root partition:max index:IndexRangeScan -└─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range:[6,6], keep order:false, stats:pseudo +TableReader 1.00 root partition:max data:TableRangeScan +└─TableRangeScan 1.00 cop[tikv] table:t1 range:[6,6], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 1 order by a; a 1 @@ -592,8 +592,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 1; id estRows task access object operator info -IndexReader 3333.33 root partition:p1,p2,p3,p4,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[1,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p1,p2,p3,p4,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 2 order by a; a 2 @@ -604,8 +604,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 2; id estRows task access object operator info -IndexReader 3333.33 root partition:p2,p3,p4,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[2,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p2,p3,p4,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 3 order by a; a 3 @@ -615,8 +615,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 3; id estRows task access object operator info -IndexReader 3333.33 root partition:p3,p4,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[3,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p3,p4,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 4 order by a; a 4 @@ -625,8 +625,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 4; id estRows task access object operator info -IndexReader 3333.33 root partition:p4,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[4,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p4,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 5 order by a; a 5 @@ -634,16 +634,16 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 5; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[5,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a >= 6 order by a; a 6 7 explain format = 'brief' SELECT * FROM t1 WHERE a >= 6; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:[6,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:[6,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 1 order by a; a 2 @@ -654,8 +654,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 1; id estRows task access object operator info -IndexReader 3333.33 root partition:p2,p3,p4,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(1,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p2,p3,p4,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(1,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 2 order by a; a 3 @@ -665,8 +665,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 2; id estRows task access object operator info -IndexReader 3333.33 root partition:p3,p4,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(2,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p3,p4,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(2,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 3 order by a; a 4 @@ -675,8 +675,8 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 3; id estRows task access object operator info -IndexReader 3333.33 root partition:p4,max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(3,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:p4,max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(3,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 4 order by a; a 5 @@ -684,23 +684,23 @@ a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 4; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(4,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(4,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 5 order by a; a 6 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 5; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(5,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(5,+inf], keep order:false, stats:pseudo SELECT * FROM t1 WHERE a > 6 order by a; a 7 explain format = 'brief' SELECT * FROM t1 WHERE a > 6; id estRows task access object operator info -IndexReader 3333.33 root partition:max index:IndexRangeScan -└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:PRIMARY(a) range:(6,+inf], keep order:false, stats:pseudo +TableReader 3333.33 root partition:max data:TableRangeScan +└─TableRangeScan 3333.33 cop[tikv] table:t1 range:(6,+inf], keep order:false, stats:pseudo DROP TABLE t1; # test of RANGE and index CREATE TABLE t1 (a DATE, KEY(a)) diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index 3e32db86c706a..d4133abd647fc 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -242,10 +242,9 @@ insert into t1 values(9, 10, 11); explain format = 'brief' select a, c from t1 use index(idx) order by a limit 5; id estRows task access object operator info TopN 5.00 root test.t1.a, offset:0, count:5 -└─IndexLookUp 5.00 root - ├─IndexFullScan(Build) 10000.00 cop[tikv] table:t1, index:idx(b, c) keep order:false, stats:pseudo - └─TopN(Probe) 5.00 cop[tikv] test.t1.a, offset:0, count:5 - └─TableRowIDScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─IndexReader 5.00 root index:TopN + └─TopN 5.00 cop[tikv] test.t1.a, offset:0, count:5 + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:idx(b, c) keep order:false, stats:pseudo select c, a from t1 use index(idx) order by a limit 5; c a 3 1 @@ -345,10 +344,10 @@ drop table if exists t; create table t(a bigint primary key, b bigint); desc select * from t where a = 1; id estRows task access object operator info -Point_Get_1 1.00 root table:t, index:PRIMARY(a) +Point_Get_1 1.00 root table:t handle:1 desc select * from t where a = '1'; id estRows task access object operator info -Point_Get_1 1.00 root table:t, index:PRIMARY(a) +Point_Get_1 1.00 root table:t handle:1 desc select sysdate(), sleep(1), sysdate(); id estRows task access object operator info Projection_3 1.00 root sysdate()->Column#1, sleep(1)->Column#2, sysdate()->Column#3 @@ -468,11 +467,11 @@ PRIMARY KEY (`id`) ); explain format = 'brief' select row_number() over( partition by i ) - x as rnk from t; id estRows task access object operator info -Projection 10000.00 root minus(Column#6, test.t.x)->Column#8 -└─Window 10000.00 root row_number()->Column#6 over(partition by test.t.i) +Projection 10000.00 root minus(Column#5, test.t.x)->Column#7 +└─Window 10000.00 root row_number()->Column#5 over(partition by test.t.i) └─Sort 10000.00 root test.t.i - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t range:[0,+inf], keep order:false, stats:pseudo create table precise_types ( a BIGINT UNSIGNED NOT NULL, b BIGINT NOT NULL, diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index 524a9effab119..50c83dc1800f6 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -17,17 +17,16 @@ insert into t values(1,1,1,1),(2,2,2,2),(3,2,2,2),(4,2,2,2),(5,2,2,2); analyze table t; explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c = 1 and s.d = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection 5.00 root Column#17 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) +Projection 5.00 root Column#14 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 - └─IndexJoin 0.50 root inner join, inner:IndexReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─IndexLookUp(Build) 1.00 root - │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) eq(test.t.c, 1) eq(test.t.d, test.t.a)], keep order:false - │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:s keep order:false - └─IndexReader(Probe) 1.00 root index:IndexRangeScan - └─IndexRangeScan 1.00 cop[tikv] table:t1, index:PRIMARY(a) range: decided by [eq(test.t.a, test.t.a)], keep order:false + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─IndexJoin 0.50 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─IndexReader(Build) 1.00 root index:IndexRangeScan + │ └─IndexRangeScan 1.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) eq(test.t.c, 1) eq(test.t.d, test.t.a)], keep order:false + └─TableReader(Probe) 1.00 root data:TableRangeScan + └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false drop table if exists t; create table t(a int, b int, c int); explain format = 'brief' select a from t t1 where t1.a = (select max(t2.a) from t t2 where t1.b=t2.b and t1.c=t2.b); diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index 697d377e5c0db..11a84495b2b37 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -185,7 +185,7 @@ id estRows task access object operator info Projection 100.00 root tpch.supplier.s_acctbal, tpch.supplier.s_name, tpch.nation.n_name, tpch.part.p_partkey, tpch.part.p_mfgr, tpch.supplier.s_address, tpch.supplier.s_phone, tpch.supplier.s_comment └─TopN 100.00 root tpch.supplier.s_acctbal:desc, tpch.nation.n_name, tpch.supplier.s_name, tpch.part.p_partkey, offset:0, count:100 └─Projection 155496.00 root tpch.part.p_partkey, tpch.part.p_mfgr, tpch.supplier.s_name, tpch.supplier.s_address, tpch.supplier.s_phone, tpch.supplier.s_acctbal, tpch.supplier.s_comment, tpch.nation.n_name - └─HashJoin 155496.00 root inner join, equal:[eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) eq(tpch.partsupp.ps_supplycost, Column#57)] + └─HashJoin 155496.00 root inner join, equal:[eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) eq(tpch.partsupp.ps_supplycost, Column#50)] ├─HashJoin(Build) 155496.00 root inner join, equal:[eq(tpch.partsupp.ps_partkey, tpch.part.p_partkey)] │ ├─TableReader(Build) 155496.00 root data:Selection │ │ └─Selection 155496.00 cop[tikv] eq(tpch.part.p_size, 30), like(tpch.part.p_type, "%STEEL", 92) @@ -202,8 +202,8 @@ Projection 100.00 root tpch.supplier.s_acctbal, tpch.supplier.s_name, tpch.nati │ │ └─TableFullScan 500000.00 cop[tikv] table:supplier keep order:false │ └─TableReader(Probe) 40000000.00 root data:TableFullScan │ └─TableFullScan 40000000.00 cop[tikv] table:partsupp keep order:false - └─Selection(Probe) 6524008.35 root not(isnull(Column#57)) - └─HashAgg 8155010.44 root group by:tpch.partsupp.ps_partkey, funcs:min(tpch.partsupp.ps_supplycost)->Column#57, funcs:firstrow(tpch.partsupp.ps_partkey)->tpch.partsupp.ps_partkey + └─Selection(Probe) 6524008.35 root not(isnull(Column#50)) + └─HashAgg 8155010.44 root group by:tpch.partsupp.ps_partkey, funcs:min(tpch.partsupp.ps_supplycost)->Column#50, funcs:firstrow(tpch.partsupp.ps_partkey)->tpch.partsupp.ps_partkey └─HashJoin 8155010.44 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] ├─HashJoin(Build) 100000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ ├─HashJoin(Build) 5.00 root inner join, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] @@ -250,10 +250,10 @@ revenue desc, o_orderdate limit 10; id estRows task access object operator info -Projection 10.00 root tpch.lineitem.l_orderkey, Column#37, tpch.orders.o_orderdate, tpch.orders.o_shippriority -└─TopN 10.00 root Column#37:desc, tpch.orders.o_orderdate, offset:0, count:10 - └─HashAgg 40252367.98 root group by:Column#58, Column#59, Column#60, funcs:sum(Column#54)->Column#37, funcs:firstrow(Column#55)->tpch.orders.o_orderdate, funcs:firstrow(Column#56)->tpch.orders.o_shippriority, funcs:firstrow(Column#57)->tpch.lineitem.l_orderkey - └─Projection 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#54, tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority +Projection 10.00 root tpch.lineitem.l_orderkey, Column#35, tpch.orders.o_orderdate, tpch.orders.o_shippriority +└─TopN 10.00 root Column#35:desc, tpch.orders.o_orderdate, offset:0, count:10 + └─HashAgg 40252367.98 root group by:Column#48, Column#49, Column#50, funcs:sum(Column#44)->Column#35, funcs:firstrow(Column#45)->tpch.orders.o_orderdate, funcs:firstrow(Column#46)->tpch.orders.o_shippriority, funcs:firstrow(Column#47)->tpch.lineitem.l_orderkey + └─Projection 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#44, tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority └─HashJoin 91515927.49 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] ├─HashJoin(Build) 22592975.51 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] │ ├─TableReader(Build) 1498236.00 root data:Selection @@ -296,8 +296,8 @@ order by o_orderpriority; id estRows task access object operator info Sort 1.00 root tpch.orders.o_orderpriority -└─Projection 1.00 root tpch.orders.o_orderpriority, Column#28 - └─HashAgg 1.00 root group by:tpch.orders.o_orderpriority, funcs:count(1)->Column#28, funcs:firstrow(tpch.orders.o_orderpriority)->tpch.orders.o_orderpriority +└─Projection 1.00 root tpch.orders.o_orderpriority, Column#27 + └─HashAgg 1.00 root group by:tpch.orders.o_orderpriority, funcs:count(1)->Column#27, funcs:firstrow(tpch.orders.o_orderpriority)->tpch.orders.o_orderpriority └─IndexHashJoin 2340750.00 root semi join, inner:IndexLookUp, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey) ├─TableReader(Build) 2925937.50 root data:Selection │ └─Selection 2925937.50 cop[tikv] ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1995-04-01) @@ -343,10 +343,10 @@ n_name order by revenue desc; id estRows task access object operator info -Sort 5.00 root Column#54:desc -└─Projection 5.00 root tpch.nation.n_name, Column#54 - └─HashAgg 5.00 root group by:Column#66, funcs:sum(Column#64)->Column#54, funcs:firstrow(Column#65)->tpch.nation.n_name - └─Projection 11822812.50 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#64, tpch.nation.n_name, tpch.nation.n_name +Sort 5.00 root Column#49:desc +└─Projection 5.00 root tpch.nation.n_name, Column#49 + └─HashAgg 5.00 root group by:Column#52, funcs:sum(Column#50)->Column#49, funcs:firstrow(Column#51)->tpch.nation.n_name + └─Projection 11822812.50 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#50, tpch.nation.n_name, tpch.nation.n_name └─Projection 11822812.50 root tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.nation.n_name └─HashJoin 11822812.50 root inner join, equal:[eq(tpch.supplier.s_nationkey, tpch.customer.c_nationkey) eq(tpch.orders.o_custkey, tpch.customer.c_custkey)] ├─TableReader(Build) 7500000.00 root data:TableFullScan @@ -445,10 +445,10 @@ supp_nation, cust_nation, l_year; id estRows task access object operator info -Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#55 -└─Projection 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#55, Column#57 - └─HashAgg 769.96 root group by:Column#55, tpch.nation.n_name, tpch.nation.n_name, funcs:sum(Column#56)->Column#57, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#55)->Column#55 - └─Projection 1957240.42 root tpch.nation.n_name, tpch.nation.n_name, extract(YEAR, tpch.lineitem.l_shipdate)->Column#55, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#56 +Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#50 +└─Projection 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#50, Column#52 + └─HashAgg 769.96 root group by:Column#50, tpch.nation.n_name, tpch.nation.n_name, funcs:sum(Column#51)->Column#52, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#50)->Column#50 + └─Projection 1957240.42 root tpch.nation.n_name, tpch.nation.n_name, extract(YEAR, tpch.lineitem.l_shipdate)->Column#50, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#51 └─Projection 1957240.42 root tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.lineitem.l_shipdate, tpch.nation.n_name, tpch.nation.n_name └─HashJoin 1957240.42 root inner join, equal:[eq(tpch.customer.c_nationkey, tpch.nation.n_nationkey)], other cond:or(and(eq(tpch.nation.n_name, "JAPAN"), eq(tpch.nation.n_name, "INDIA")), and(eq(tpch.nation.n_name, "INDIA"), eq(tpch.nation.n_name, "JAPAN"))) ├─TableReader(Build) 2.00 root data:Selection @@ -457,7 +457,7 @@ Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#55 └─HashJoin(Probe) 24465505.20 root inner join, equal:[eq(tpch.orders.o_custkey, tpch.customer.c_custkey)] ├─TableReader(Build) 7500000.00 root data:TableFullScan │ └─TableFullScan 7500000.00 cop[tikv] table:customer keep order:false - └─HashJoin(Probe) 24465505.20 root inner join, equal:[eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)] + └─IndexJoin(Probe) 24465505.20 root inner join, inner:TableReader, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) ├─HashJoin(Build) 24465505.20 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] │ ├─HashJoin(Build) 40000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ │ ├─TableReader(Build) 2.00 root data:Selection @@ -468,8 +468,8 @@ Sort 769.96 root tpch.nation.n_name, tpch.nation.n_name, Column#55 │ └─TableReader(Probe) 91446230.29 root data:Selection │ └─Selection 91446230.29 cop[tikv] ge(tpch.lineitem.l_shipdate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shipdate, 1996-12-31 00:00:00.000000) │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─TableReader(Probe) 75000000.00 root data:TableFullScan - └─TableFullScan 75000000.00 cop[tikv] table:orders keep order:false + └─TableReader(Probe) 1.00 root data:TableRangeScan + └─TableRangeScan 1.00 cop[tikv] table:orders range: decided by [tpch.lineitem.l_orderkey], keep order:false /* Q8 National Market Share Query This query determines how the market share of a given nation within a given region has changed over two years for @@ -518,11 +518,11 @@ o_year order by o_year; id estRows task access object operator info -Sort 719.02 root Column#69 -└─Projection 719.02 root Column#69, div(Column#71, Column#72)->Column#73 - └─HashAgg 719.02 root group by:Column#97, funcs:sum(Column#94)->Column#71, funcs:sum(Column#95)->Column#72, funcs:firstrow(Column#96)->Column#69 - └─Projection 563136.02 root case(eq(tpch.nation.n_name, INDIA), Column#70, 0)->Column#94, Column#70, Column#69, Column#69 - └─Projection 563136.02 root extract(YEAR, tpch.orders.o_orderdate)->Column#69, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#70, tpch.nation.n_name +Sort 719.02 root Column#62 +└─Projection 719.02 root Column#62, div(Column#64, Column#65)->Column#66 + └─HashAgg 719.02 root group by:Column#78, funcs:sum(Column#75)->Column#64, funcs:sum(Column#76)->Column#65, funcs:firstrow(Column#77)->Column#62 + └─Projection 563136.02 root case(eq(tpch.nation.n_name, INDIA), Column#63, 0)->Column#75, Column#63, Column#62, Column#62 + └─Projection 563136.02 root extract(YEAR, tpch.orders.o_orderdate)->Column#62, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#63, tpch.nation.n_name └─Projection 563136.02 root tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.orders.o_orderdate, tpch.nation.n_name └─HashJoin 563136.02 root inner join, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] ├─TableReader(Build) 25.00 root data:TableFullScan @@ -595,10 +595,10 @@ order by nation, o_year desc; id estRows task access object operator info -Sort 2406.00 root tpch.nation.n_name, Column#57:desc -└─Projection 2406.00 root tpch.nation.n_name, Column#57, Column#59 - └─HashAgg 2406.00 root group by:Column#57, tpch.nation.n_name, funcs:sum(Column#58)->Column#59, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#57)->Column#57 - └─Projection 241379546.70 root tpch.nation.n_name, extract(YEAR, tpch.orders.o_orderdate)->Column#57, minus(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), mul(tpch.partsupp.ps_supplycost, tpch.lineitem.l_quantity))->Column#58 +Sort 2406.00 root tpch.nation.n_name, Column#53:desc +└─Projection 2406.00 root tpch.nation.n_name, Column#53, Column#55 + └─HashAgg 2406.00 root group by:Column#53, tpch.nation.n_name, funcs:sum(Column#54)->Column#55, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(Column#53)->Column#53 + └─Projection 241379546.70 root tpch.nation.n_name, extract(YEAR, tpch.orders.o_orderdate)->Column#53, minus(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), mul(tpch.partsupp.ps_supplycost, tpch.lineitem.l_quantity))->Column#54 └─Projection 241379546.70 root tpch.lineitem.l_quantity, tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.partsupp.ps_supplycost, tpch.orders.o_orderdate, tpch.nation.n_name └─HashJoin 241379546.70 root inner join, equal:[eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)] ├─TableReader(Build) 75000000.00 root data:TableFullScan @@ -662,10 +662,10 @@ order by revenue desc limit 20; id estRows task access object operator info -Projection 20.00 root tpch.customer.c_custkey, tpch.customer.c_name, Column#42, tpch.customer.c_acctbal, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_comment -└─TopN 20.00 root Column#42:desc, offset:0, count:20 - └─HashAgg 3017307.69 root group by:Column#59, Column#60, Column#61, Column#62, Column#63, Column#64, Column#65, funcs:sum(Column#51)->Column#42, funcs:firstrow(Column#52)->tpch.customer.c_custkey, funcs:firstrow(Column#53)->tpch.customer.c_name, funcs:firstrow(Column#54)->tpch.customer.c_address, funcs:firstrow(Column#55)->tpch.customer.c_phone, funcs:firstrow(Column#56)->tpch.customer.c_acctbal, funcs:firstrow(Column#57)->tpch.customer.c_comment, funcs:firstrow(Column#58)->tpch.nation.n_name - └─Projection 12222016.17 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#51, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.nation.n_name, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_acctbal, tpch.customer.c_phone, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_comment +Projection 20.00 root tpch.customer.c_custkey, tpch.customer.c_name, Column#39, tpch.customer.c_acctbal, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_comment +└─TopN 20.00 root Column#39:desc, offset:0, count:20 + └─HashAgg 3017307.69 root group by:Column#53, Column#54, Column#55, Column#56, Column#57, Column#58, Column#59, funcs:sum(Column#45)->Column#39, funcs:firstrow(Column#46)->tpch.customer.c_custkey, funcs:firstrow(Column#47)->tpch.customer.c_name, funcs:firstrow(Column#48)->tpch.customer.c_address, funcs:firstrow(Column#49)->tpch.customer.c_phone, funcs:firstrow(Column#50)->tpch.customer.c_acctbal, funcs:firstrow(Column#51)->tpch.customer.c_comment, funcs:firstrow(Column#52)->tpch.nation.n_name + └─Projection 12222016.17 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#45, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.nation.n_name, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_acctbal, tpch.customer.c_phone, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_comment └─Projection 12222016.17 root tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount, tpch.nation.n_name └─IndexHashJoin 12222016.17 root inner join, inner:IndexLookUp, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey) ├─HashJoin(Build) 3017307.69 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] @@ -717,11 +717,11 @@ and n_name = 'MOZAMBIQUE' order by value desc; id estRows task access object operator info -Projection 1304801.67 root tpch.partsupp.ps_partkey, Column#39 -└─Sort 1304801.67 root Column#39:desc - └─Selection 1304801.67 root gt(Column#39, NULL) - └─HashAgg 1631002.09 root group by:Column#54, funcs:sum(Column#52)->Column#39, funcs:firstrow(Column#53)->tpch.partsupp.ps_partkey - └─Projection 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->Column#52, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey +Projection 1304801.67 root tpch.partsupp.ps_partkey, Column#35 +└─Sort 1304801.67 root Column#35:desc + └─Selection 1304801.67 root gt(Column#35, NULL) + └─HashAgg 1631002.09 root group by:Column#44, funcs:sum(Column#42)->Column#35, funcs:firstrow(Column#43)->tpch.partsupp.ps_partkey + └─Projection 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->Column#42, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey └─HashJoin 1631002.09 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] ├─HashJoin(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ ├─TableReader(Build) 1.00 root data:Selection @@ -772,17 +772,16 @@ order by l_shipmode; id estRows task access object operator info Sort 1.00 root tpch.lineitem.l_shipmode -└─Projection 1.00 root tpch.lineitem.l_shipmode, Column#28, Column#29 - └─HashAgg 1.00 root group by:Column#46, funcs:sum(Column#43)->Column#28, funcs:sum(Column#44)->Column#29, funcs:firstrow(Column#45)->tpch.lineitem.l_shipmode - └─Projection 10023369.01 root cast(case(or(eq(tpch.orders.o_orderpriority, 1-URGENT), eq(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#43, cast(case(and(ne(tpch.orders.o_orderpriority, 1-URGENT), ne(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#44, tpch.lineitem.l_shipmode, tpch.lineitem.l_shipmode +└─Projection 1.00 root tpch.lineitem.l_shipmode, Column#27, Column#28 + └─HashAgg 1.00 root group by:Column#40, funcs:sum(Column#37)->Column#27, funcs:sum(Column#38)->Column#28, funcs:firstrow(Column#39)->tpch.lineitem.l_shipmode + └─Projection 10023369.01 root cast(case(or(eq(tpch.orders.o_orderpriority, 1-URGENT), eq(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#37, cast(case(and(ne(tpch.orders.o_orderpriority, 1-URGENT), ne(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(22,0) BINARY)->Column#38, tpch.lineitem.l_shipmode, tpch.lineitem.l_shipmode └─Projection 10023369.01 root tpch.orders.o_orderpriority, tpch.lineitem.l_shipmode - └─IndexJoin 10023369.01 root inner join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) + └─IndexJoin 10023369.01 root inner join, inner:TableReader, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) ├─TableReader(Build) 10023369.01 root data:Selection │ └─Selection 10023369.01 cop[tikv] ge(tpch.lineitem.l_receiptdate, 1997-01-01 00:00:00.000000), in(tpch.lineitem.l_shipmode, "RAIL", "FOB"), lt(tpch.lineitem.l_commitdate, tpch.lineitem.l_receiptdate), lt(tpch.lineitem.l_receiptdate, 1998-01-01), lt(tpch.lineitem.l_shipdate, tpch.lineitem.l_commitdate) │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─IndexLookUp(Probe) 1.00 root - ├─IndexRangeScan(Build) 1.00 cop[tikv] table:orders, index:PRIMARY(O_ORDERKEY) range: decided by [eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)], keep order:false - └─TableRowIDScan(Probe) 1.00 cop[tikv] table:orders keep order:false + └─TableReader(Probe) 1.00 root data:TableRangeScan + └─TableRangeScan 1.00 cop[tikv] table:orders range: decided by [tpch.lineitem.l_orderkey], keep order:false /* Q13 Customer Distribution Query This query seeks relationships between customers and the size of their orders. @@ -813,13 +812,13 @@ order by custdist desc, c_count desc; id estRows task access object operator info -Sort 7500000.00 root Column#21:desc, Column#20:desc -└─Projection 7500000.00 root Column#20, Column#21 - └─HashAgg 7500000.00 root group by:Column#20, funcs:count(1)->Column#21, funcs:firstrow(Column#20)->Column#20 - └─HashAgg 7500000.00 root group by:tpch.customer.c_custkey, funcs:count(tpch.orders.o_orderkey)->Column#20 +Sort 7500000.00 root Column#19:desc, Column#18:desc +└─Projection 7500000.00 root Column#18, Column#19 + └─HashAgg 7500000.00 root group by:Column#18, funcs:count(1)->Column#19, funcs:firstrow(Column#18)->Column#18 + └─HashAgg 7500000.00 root group by:tpch.customer.c_custkey, funcs:count(tpch.orders.o_orderkey)->Column#18 └─HashJoin 60000000.00 root left outer join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] - ├─IndexReader(Build) 7500000.00 root index:IndexFullScan - │ └─IndexFullScan 7500000.00 cop[tikv] table:customer, index:PRIMARY(C_CUSTKEY) keep order:false + ├─TableReader(Build) 7500000.00 root data:TableFullScan + │ └─TableFullScan 7500000.00 cop[tikv] table:customer keep order:false └─TableReader(Probe) 60000000.00 root data:Selection └─Selection 60000000.00 cop[tikv] not(like(tpch.orders.o_comment, "%pending%deposits%", 92)) └─TableFullScan 75000000.00 cop[tikv] table:orders keep order:false @@ -845,15 +844,15 @@ l_partkey = p_partkey and l_shipdate >= '1996-12-01' and l_shipdate < date_add('1996-12-01', interval '1' month); id estRows task access object operator info -Projection 1.00 root div(mul(100.00, Column#28), Column#29)->Column#30 -└─StreamAgg 1.00 root funcs:sum(Column#38)->Column#28, funcs:sum(Column#39)->Column#29 - └─Projection 4121984.49 root case(like(tpch.part.p_type, PROMO%, 92), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), 0)->Column#38, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#39 - └─HashJoin 4121984.49 root inner join, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] +Projection 1.00 root div(mul(100.00, Column#27), Column#28)->Column#29 +└─StreamAgg 1.00 root funcs:sum(Column#31)->Column#27, funcs:sum(Column#32)->Column#28 + └─Projection 4121984.49 root case(like(tpch.part.p_type, PROMO%, 92), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), 0)->Column#31, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#32 + └─IndexJoin 4121984.49 root inner join, inner:TableReader, outer key:tpch.lineitem.l_partkey, inner key:tpch.part.p_partkey, equal cond:eq(tpch.lineitem.l_partkey, tpch.part.p_partkey) ├─TableReader(Build) 4121984.49 root data:Selection │ └─Selection 4121984.49 cop[tikv] ge(tpch.lineitem.l_shipdate, 1996-12-01 00:00:00.000000), lt(tpch.lineitem.l_shipdate, 1997-01-01) │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─TableReader(Probe) 10000000.00 root data:TableFullScan - └─TableFullScan 10000000.00 cop[tikv] table:part keep order:false + └─TableReader(Probe) 1.00 root data:TableRangeScan + └─TableRangeScan 1.00 cop[tikv] table:part range: decided by [tpch.lineitem.l_partkey], keep order:false /* Q15 Top Supplier Query This query determines the top supplier so it can be rewarded, given more business, or identified for special recognition. @@ -934,9 +933,9 @@ p_brand, p_type, p_size; id estRows task access object operator info -Sort 14.41 root Column#25:desc, tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size -└─Projection 14.41 root tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size, Column#25 - └─HashAgg 14.41 root group by:tpch.part.p_brand, tpch.part.p_size, tpch.part.p_type, funcs:count(distinct tpch.partsupp.ps_suppkey)->Column#25, funcs:firstrow(tpch.part.p_brand)->tpch.part.p_brand, funcs:firstrow(tpch.part.p_type)->tpch.part.p_type, funcs:firstrow(tpch.part.p_size)->tpch.part.p_size +Sort 14.41 root Column#23:desc, tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size +└─Projection 14.41 root tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size, Column#23 + └─HashAgg 14.41 root group by:tpch.part.p_brand, tpch.part.p_size, tpch.part.p_type, funcs:count(distinct tpch.partsupp.ps_suppkey)->Column#23, funcs:firstrow(tpch.part.p_brand)->tpch.part.p_brand, funcs:firstrow(tpch.part.p_type)->tpch.part.p_type, funcs:firstrow(tpch.part.p_size)->tpch.part.p_size └─HashJoin 3863988.24 root anti semi join, equal:[eq(tpch.partsupp.ps_suppkey, tpch.supplier.s_suppkey)] ├─TableReader(Build) 400000.00 root data:Selection │ └─Selection 400000.00 cop[tikv] like(tpch.supplier.s_comment, "%Customer%Complaints%", 92) @@ -977,18 +976,18 @@ where l_partkey = p_partkey ); id estRows task access object operator info -Projection 1.00 root div(Column#47, 7.0)->Column#48 -└─StreamAgg 1.00 root funcs:sum(tpch.lineitem.l_extendedprice)->Column#47 - └─HashJoin 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:lt(tpch.lineitem.l_quantity, mul(0.2, Column#45)) +Projection 1.00 root div(Column#46, 7.0)->Column#47 +└─StreamAgg 1.00 root funcs:sum(tpch.lineitem.l_extendedprice)->Column#46 + └─HashJoin 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:lt(tpch.lineitem.l_quantity, mul(0.2, Column#44)) ├─HashJoin(Build) 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)] │ ├─TableReader(Build) 9736.49 root data:Selection │ │ └─Selection 9736.49 cop[tikv] eq(tpch.part.p_brand, "Brand#44"), eq(tpch.part.p_container, "WRAP PKG") │ │ └─TableFullScan 10000000.00 cop[tikv] table:part keep order:false │ └─TableReader(Probe) 300005811.00 root data:TableFullScan │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false - └─HashAgg(Probe) 9943040.00 root group by:tpch.lineitem.l_partkey, funcs:avg(Column#54, Column#55)->Column#45, funcs:firstrow(tpch.lineitem.l_partkey)->tpch.lineitem.l_partkey + └─HashAgg(Probe) 9943040.00 root group by:tpch.lineitem.l_partkey, funcs:avg(Column#50, Column#51)->Column#44, funcs:firstrow(tpch.lineitem.l_partkey)->tpch.lineitem.l_partkey └─TableReader 9943040.00 root data:HashAgg - └─HashAgg 9943040.00 cop[tikv] group by:tpch.lineitem.l_partkey, funcs:count(tpch.lineitem.l_quantity)->Column#54, funcs:sum(tpch.lineitem.l_quantity)->Column#55 + └─HashAgg 9943040.00 cop[tikv] group by:tpch.lineitem.l_partkey, funcs:count(tpch.lineitem.l_quantity)->Column#50, funcs:sum(tpch.lineitem.l_quantity)->Column#51 └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false /* Q18 Large Volume Customer Query @@ -1033,15 +1032,15 @@ o_totalprice desc, o_orderdate limit 100; id estRows task access object operator info -Projection 100.00 root tpch.customer.c_name, tpch.customer.c_custkey, tpch.orders.o_orderkey, tpch.orders.o_orderdate, tpch.orders.o_totalprice, Column#56 +Projection 100.00 root tpch.customer.c_name, tpch.customer.c_custkey, tpch.orders.o_orderkey, tpch.orders.o_orderdate, tpch.orders.o_totalprice, Column#54 └─TopN 100.00 root tpch.orders.o_totalprice:desc, tpch.orders.o_orderdate, offset:0, count:100 - └─HashAgg 59251097.60 root group by:tpch.customer.c_custkey, tpch.customer.c_name, tpch.orders.o_orderdate, tpch.orders.o_orderkey, tpch.orders.o_totalprice, funcs:sum(tpch.lineitem.l_quantity)->Column#56, funcs:firstrow(tpch.customer.c_custkey)->tpch.customer.c_custkey, funcs:firstrow(tpch.customer.c_name)->tpch.customer.c_name, funcs:firstrow(tpch.orders.o_orderkey)->tpch.orders.o_orderkey, funcs:firstrow(tpch.orders.o_totalprice)->tpch.orders.o_totalprice, funcs:firstrow(tpch.orders.o_orderdate)->tpch.orders.o_orderdate + └─HashAgg 59251097.60 root group by:tpch.customer.c_custkey, tpch.customer.c_name, tpch.orders.o_orderdate, tpch.orders.o_orderkey, tpch.orders.o_totalprice, funcs:sum(tpch.lineitem.l_quantity)->Column#54, funcs:firstrow(tpch.customer.c_custkey)->tpch.customer.c_custkey, funcs:firstrow(tpch.customer.c_name)->tpch.customer.c_name, funcs:firstrow(tpch.orders.o_orderkey)->tpch.orders.o_orderkey, funcs:firstrow(tpch.orders.o_totalprice)->tpch.orders.o_totalprice, funcs:firstrow(tpch.orders.o_orderdate)->tpch.orders.o_orderdate └─HashJoin 240004648.80 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] ├─HashJoin(Build) 59251097.60 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] - │ ├─Selection(Build) 59251097.60 root gt(Column#54, 314) - │ │ └─HashAgg 74063872.00 root group by:tpch.lineitem.l_orderkey, funcs:sum(Column#76)->Column#54, funcs:firstrow(tpch.lineitem.l_orderkey)->tpch.lineitem.l_orderkey + │ ├─Selection(Build) 59251097.60 root gt(Column#52, 314) + │ │ └─HashAgg 74063872.00 root group by:tpch.lineitem.l_orderkey, funcs:sum(Column#66)->Column#52, funcs:firstrow(tpch.lineitem.l_orderkey)->tpch.lineitem.l_orderkey │ │ └─TableReader 74063872.00 root data:HashAgg - │ │ └─HashAgg 74063872.00 cop[tikv] group by:tpch.lineitem.l_orderkey, funcs:sum(tpch.lineitem.l_quantity)->Column#76 + │ │ └─HashAgg 74063872.00 cop[tikv] group by:tpch.lineitem.l_orderkey, funcs:sum(tpch.lineitem.l_quantity)->Column#66 │ │ └─TableFullScan 300005811.00 cop[tikv] table:lineitem keep order:false │ └─HashJoin(Probe) 75000000.00 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] │ ├─TableReader(Build) 7500000.00 root data:TableFullScan @@ -1096,8 +1095,8 @@ and l_shipmode in ('AIR', 'AIR REG') and l_shipinstruct = 'DELIVER IN PERSON' ); id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#35)->Column#28 -└─Projection 733887.82 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#35 +StreamAgg 1.00 root funcs:sum(Column#28)->Column#27 +└─Projection 733887.82 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->Column#28 └─HashJoin 733887.82 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:or(and(and(eq(tpch.part.p_brand, "Brand#52"), in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(tpch.lineitem.l_quantity, 4), and(le(tpch.lineitem.l_quantity, 14), le(tpch.part.p_size, 5)))), or(and(and(eq(tpch.part.p_brand, "Brand#11"), in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(tpch.lineitem.l_quantity, 18), and(le(tpch.lineitem.l_quantity, 28), le(tpch.part.p_size, 10)))), and(and(eq(tpch.part.p_brand, "Brand#51"), in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(tpch.lineitem.l_quantity, 29), and(le(tpch.lineitem.l_quantity, 39), le(tpch.part.p_size, 15)))))) ├─TableReader(Build) 24323.12 root data:Selection │ └─Selection 24323.12 cop[tikv] ge(tpch.part.p_size, 1), or(and(eq(tpch.part.p_brand, "Brand#52"), and(in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(tpch.part.p_size, 5))), or(and(eq(tpch.part.p_brand, "Brand#11"), and(in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(tpch.part.p_size, 10))), and(eq(tpch.part.p_brand, "Brand#51"), and(in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(tpch.part.p_size, 15))))) @@ -1162,8 +1161,8 @@ Sort 20000.00 root tpch.supplier.s_name │ └─TableFullScan 500000.00 cop[tikv] table:supplier keep order:false └─HashAgg(Probe) 257492.04 root group by:tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey └─Projection 257492.04 root tpch.partsupp.ps_suppkey - └─Selection 257492.04 root gt(cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY), mul(0.5, Column#47)) - └─HashAgg 321865.05 root group by:tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_availqty)->tpch.partsupp.ps_availqty, funcs:sum(tpch.lineitem.l_quantity)->Column#47 + └─Selection 257492.04 root gt(cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY), mul(0.5, Column#44)) + └─HashAgg 321865.05 root group by:tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_availqty)->tpch.partsupp.ps_availqty, funcs:sum(tpch.lineitem.l_quantity)->Column#44 └─HashJoin 9711455.06 root left outer join, equal:[eq(tpch.partsupp.ps_partkey, tpch.lineitem.l_partkey) eq(tpch.partsupp.ps_suppkey, tpch.lineitem.l_suppkey)] ├─IndexHashJoin(Build) 321865.05 root inner join, inner:IndexLookUp, outer key:tpch.part.p_partkey, inner key:tpch.partsupp.ps_partkey, equal cond:eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) │ ├─TableReader(Build) 80007.93 root data:Selection @@ -1224,12 +1223,12 @@ numwait desc, s_name limit 100; id estRows task access object operator info -Projection 100.00 root tpch.supplier.s_name, Column#75 -└─TopN 100.00 root Column#75:desc, tpch.supplier.s_name, offset:0, count:100 - └─HashAgg 12800.00 root group by:tpch.supplier.s_name, funcs:count(1)->Column#75, funcs:firstrow(tpch.supplier.s_name)->tpch.supplier.s_name +Projection 100.00 root tpch.supplier.s_name, Column#72 +└─TopN 100.00 root Column#72:desc, tpch.supplier.s_name, offset:0, count:100 + └─HashAgg 12800.00 root group by:tpch.supplier.s_name, funcs:count(1)->Column#72, funcs:firstrow(tpch.supplier.s_name)->tpch.supplier.s_name └─IndexHashJoin 7828961.66 root anti semi join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey), other cond:ne(tpch.lineitem.l_suppkey, tpch.lineitem.l_suppkey) ├─IndexHashJoin(Build) 9786202.08 root semi join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.lineitem.l_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey), other cond:ne(tpch.lineitem.l_suppkey, tpch.lineitem.l_suppkey), ne(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey) - │ ├─IndexJoin(Build) 12232752.60 root inner join, inner:IndexLookUp, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) + │ ├─IndexJoin(Build) 12232752.60 root inner join, inner:TableReader, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey, equal cond:eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey) │ │ ├─HashJoin(Build) 12232752.60 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] │ │ │ ├─HashJoin(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ │ │ │ ├─TableReader(Build) 1.00 root data:Selection @@ -1240,10 +1239,9 @@ Projection 100.00 root tpch.supplier.s_name, Column#75 │ │ │ └─TableReader(Probe) 240004648.80 root data:Selection │ │ │ └─Selection 240004648.80 cop[tikv] gt(tpch.lineitem.l_receiptdate, tpch.lineitem.l_commitdate) │ │ │ └─TableFullScan 300005811.00 cop[tikv] table:l1 keep order:false - │ │ └─IndexLookUp(Probe) 1.00 root - │ │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:orders, index:PRIMARY(O_ORDERKEY) range: decided by [eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)], keep order:false - │ │ └─Selection(Probe) 1.00 cop[tikv] eq(tpch.orders.o_orderstatus, "F") - │ │ └─TableRowIDScan 1.00 cop[tikv] table:orders keep order:false + │ │ └─TableReader(Probe) 0.49 root data:Selection + │ │ └─Selection 0.49 cop[tikv] eq(tpch.orders.o_orderstatus, "F") + │ │ └─TableRangeScan 1.00 cop[tikv] table:orders range: decided by [tpch.lineitem.l_orderkey], keep order:false │ └─IndexLookUp(Probe) 4.05 root │ ├─IndexRangeScan(Build) 4.05 cop[tikv] table:l2, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey)], keep order:false │ └─TableRowIDScan(Probe) 4.05 cop[tikv] table:l2 keep order:false @@ -1298,10 +1296,10 @@ cntrycode order by cntrycode; id estRows task access object operator info -Sort 1.00 root Column#30 -└─Projection 1.00 root Column#30, Column#31, Column#32 - └─HashAgg 1.00 root group by:Column#30, funcs:count(1)->Column#31, funcs:sum(tpch.customer.c_acctbal)->Column#32, funcs:firstrow(Column#30)->Column#30 - └─Projection 0.00 root substring(tpch.customer.c_phone, 1, 2)->Column#30, tpch.customer.c_acctbal +Sort 1.00 root Column#27 +└─Projection 1.00 root Column#27, Column#28, Column#29 + └─HashAgg 1.00 root group by:Column#27, funcs:count(1)->Column#28, funcs:sum(tpch.customer.c_acctbal)->Column#29, funcs:firstrow(Column#27)->Column#27 + └─Projection 0.00 root substring(tpch.customer.c_phone, 1, 2)->Column#27, tpch.customer.c_acctbal └─HashJoin 0.00 root anti semi join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] ├─TableReader(Build) 75000000.00 root data:TableFullScan │ └─TableFullScan 75000000.00 cop[tikv] table:orders keep order:false diff --git a/cmd/explaintest/r/window_function.result b/cmd/explaintest/r/window_function.result index b677b48ca8795..6c92b63dcd0d3 100644 --- a/cmd/explaintest/r/window_function.result +++ b/cmd/explaintest/r/window_function.result @@ -109,8 +109,8 @@ insert into t1 values(1, 1), (2, 1); analyze table t1; explain format = 'brief' select sum(a) over(partition by b) from t1; id estRows task access object operator info -Projection 2.00 root Column#5 -└─Window 2.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#5 over(partition by test.t1.b) +Projection 2.00 root Column#4 +└─Window 2.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#4 over(partition by test.t1.b) └─Sort 2.00 root test.t1.b └─TableReader 2.00 root data:TableFullScan └─TableFullScan 2.00 cop[tikv] table:t1 keep order:false @@ -118,9 +118,9 @@ insert into t1 values(3, 3); analyze table t1; explain format = 'brief' select sum(a) over(partition by b) from t1; id estRows task access object operator info -Projection 3.00 root Column#5 +Projection 3.00 root Column#4 └─Shuffle 3.00 root execution info: concurrency:2, data sources:[TableReader] - └─Window 3.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#5 over(partition by test.t1.b) + └─Window 3.00 root sum(cast(test.t1.a, decimal(32,0) BINARY))->Column#4 over(partition by test.t1.b) └─Sort 3.00 root test.t1.b └─TableReader 3.00 root data:TableFullScan └─TableFullScan 3.00 cop[tikv] table:t1 keep order:false From b7d23a69f006cfb09e1280ff33beab6db20cdfbf Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 17 Mar 2021 14:36:29 +0800 Subject: [PATCH 10/16] fix several integration tests --- ddl/db_change_test.go | 2 +- ddl/db_test.go | 2 +- executor/join_test.go | 2 +- sessionctx/binloginfo/binloginfo_test.go | 13 +++++++------ statistics/selectivity_test.go | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ddl/db_change_test.go b/ddl/db_change_test.go index 9a889ab7bb04c..99a2de6ee3ef5 100644 --- a/ddl/db_change_test.go +++ b/ddl/db_change_test.go @@ -930,7 +930,7 @@ func (s *testStateChangeSuiteBase) CheckResult(tk *testkit.TestKit, sql string, } func (s *testStateChangeSuite) TestShowIndex(c *C) { - _, err := s.se.Execute(context.Background(), `create table t(c1 int primary key, c2 int)`) + _, err := s.se.Execute(context.Background(), `create table t(c1 int primary key nonclustered, c2 int)`) c.Assert(err, IsNil) defer func() { _, err := s.se.Execute(context.Background(), "drop table t") diff --git a/ddl/db_test.go b/ddl/db_test.go index e18b7d06efc45..bf9686e14423e 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -2423,7 +2423,7 @@ func (s *testDBSuite7) TestSelectInViewFromAnotherDB(c *C) { _, _ = s.s.Execute(context.Background(), "create database test_db2") tk := testkit.NewTestKit(c, s.store) tk.MustExec("use " + s.schemaName) - tk.MustExec("drop table t if exists t;") + tk.MustExec("drop table if exists t;") tk.MustExec("create table t(a int)") tk.MustExec("use test_db2") tk.MustExec("create sql security invoker view v as select * from " + s.schemaName + ".t") diff --git a/executor/join_test.go b/executor/join_test.go index 1edac17004362..98064ea08345f 100644 --- a/executor/join_test.go +++ b/executor/join_test.go @@ -2311,7 +2311,7 @@ func (s *testSuite9) TestIssue18572_1(c *C) { c.Assert(rs.Close(), IsNil) } -func (s *testSuite9) TestIssue18572_2(c *C) { +func (s *testSuiteJoinSerial) TestIssue18572_2(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) tk.MustExec("drop table if exists t1") tk.MustExec("create table t1(a int, b int, index idx(b));") diff --git a/sessionctx/binloginfo/binloginfo_test.go b/sessionctx/binloginfo/binloginfo_test.go index 0083c1cf9ac3d..209af568820e7 100644 --- a/sessionctx/binloginfo/binloginfo_test.go +++ b/sessionctx/binloginfo/binloginfo_test.go @@ -256,14 +256,15 @@ func (s *testBinlogSuite) TestBinlog(c *C) { binlog.MutationType_Insert, }) - // Test cannot build clustered index tables when binlog client exists. - tk.MustExec("create table local_clustered_index (c1 varchar(255) primary key clustered);") - warnMsg := "Warning 1105 cannot build clustered index table because the binlog is ON" - tk.MustQuery("show warnings;").Check(testkit.Rows(warnMsg)) + // Cannot create common clustered index table when binlog client exists. + errMsg := "[ddl:8200]Cannot create clustered index table when the binlog is ON" + tk.MustGetErrMsg("create table local_clustered_index (c1 varchar(255) primary key clustered);", errMsg) + // Create int clustered index table when binlog client exists. + tk.MustExec("create table local_clustered_index (c1 bigint primary key clustered);") tk.MustQuery("select tidb_pk_type from information_schema.tables where table_name = 'local_clustered_index' and table_schema = 'test';"). - Check(testkit.Rows("NONCLUSTERED")) + Check(testkit.Rows("CLUSTERED")) tk.MustExec("drop table if exists local_clustered_index;") - // Test clustered index tables will not write binlog. + // Test common clustered index tables will not write binlog. tk.Se.GetSessionVars().BinlogClient = nil tk.MustExec("create table local_clustered_index (c1 varchar(255) primary key clustered);") tk.MustQuery("select tidb_pk_type from information_schema.tables where table_name = 'local_clustered_index' and table_schema = 'test';"). diff --git a/statistics/selectivity_test.go b/statistics/selectivity_test.go index c19935e3375bd..f371d2189b0b7 100644 --- a/statistics/selectivity_test.go +++ b/statistics/selectivity_test.go @@ -613,7 +613,7 @@ func (s *testStatsSuite) TestStatsVer2(c *C) { testKit.MustExec("analyze table ct1 with 2 topn, 3 buckets") testKit.MustExec("drop table if exists ct2") - testKit.MustExec("create table ct2 (a int, b int, c int, primary key(a, b))") + testKit.MustExec("create table ct2 (a int, b int, c int, primary key(a, b) clustered)") testKit.MustExec("insert into ct2 values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5), (6, 6, 6), (7, 7, 7), (8, 8, 8)") testKit.MustExec("analyze table ct2 with 2 topn, 3 buckets") From c5c862d9f6ffe7dc7bfc7f596d7f98da3666d1f4 Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 17 Mar 2021 15:26:24 +0800 Subject: [PATCH 11/16] change failpoint testsuite to serialsuite --- executor/join_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/join_test.go b/executor/join_test.go index 98064ea08345f..76afe571f3d41 100644 --- a/executor/join_test.go +++ b/executor/join_test.go @@ -2292,7 +2292,7 @@ func (s *testSuiteJoin1) TestInvalidEnumVal(c *C) { rows.Check(testkit.Rows("a a", " ", " ", " ", " ")) } -func (s *testSuite9) TestIssue18572_1(c *C) { +func (s *testSuiteJoinSerial) TestIssue18572_1(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) tk.MustExec("drop table if exists t1") tk.MustExec("create table t1(a int, b int, index idx(b));") @@ -2330,7 +2330,7 @@ func (s *testSuiteJoinSerial) TestIssue18572_2(c *C) { c.Assert(rs.Close(), IsNil) } -func (s *testSuite9) TestIssue18572_3(c *C) { +func (s *testSuiteJoinSerial) TestIssue18572_3(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) tk.MustExec("drop table if exists t1") tk.MustExec("create table t1(a int, b int, index idx(b));") From 8dc54e6369c316a9757b4b2ee19a5949d3a81508 Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 17 Mar 2021 22:15:44 +0800 Subject: [PATCH 12/16] disallow using shard_row_id_bits with clustered index --- ddl/ddl_api.go | 4 ++-- executor/ddl_test.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index b369b7b100e7a..6616422d6feee 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2164,7 +2164,7 @@ func handleTableOptions(options []*ast.TableOption, tbInfo *model.TableInfo) err case ast.TableOptionCompression: tbInfo.Compression = op.StrValue case ast.TableOptionShardRowID: - if op.UintValue > 0 && tbInfo.PKIsHandle { + if op.UintValue > 0 && (tbInfo.PKIsHandle || tbInfo.IsCommonHandle) { return errUnsupportedShardRowIDBits } tbInfo.ShardRowIDBits = op.UintValue @@ -2592,7 +2592,7 @@ func (d *ddl) ShardRowID(ctx sessionctx.Context, tableIdent ast.Ident, uVal uint // Nothing need to do. return nil } - if uVal > 0 && t.Meta().PKIsHandle { + if uVal > 0 && (t.Meta().PKIsHandle || t.Meta().IsCommonHandle) { return errUnsupportedShardRowIDBits } err = verifyNoOverflowShardBits(d.sessPool, t, uVal) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index b530f7cd0d3a1..5ea9171649c71 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -790,12 +790,17 @@ func (s *testSuite8) TestShardRowIDBits(c *C) { tk.MustExec("alter table auto shard_row_id_bits = 0") tk.MustExec("drop table auto") + errMsg := "[ddl:8200]Unsupported shard_row_id_bits for table with primary key as row id" + tk.MustGetErrMsg("create table auto (id varchar(255) primary key clustered, b int) shard_row_id_bits = 4;", errMsg) + tk.MustExec("create table auto (id varchar(255) primary key clustered, b int) shard_row_id_bits = 0;") + tk.MustGetErrMsg("alter table auto shard_row_id_bits = 5;", errMsg) + tk.MustExec("alter table auto shard_row_id_bits = 0;") + tk.MustExec("drop table if exists auto;") + // After PR 10759, shard_row_id_bits is not supported with pk_is_handle tables. - err = tk.ExecToErr("create table auto (id int not null auto_increment primary key, b int) shard_row_id_bits = 4") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported shard_row_id_bits for table with primary key as row id") + tk.MustGetErrMsg("create table auto (id int not null auto_increment primary key, b int) shard_row_id_bits = 4", errMsg) tk.MustExec("create table auto (id int not null auto_increment primary key, b int) shard_row_id_bits = 0") - err = tk.ExecToErr("alter table auto shard_row_id_bits = 5") - c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported shard_row_id_bits for table with primary key as row id") + tk.MustGetErrMsg("alter table auto shard_row_id_bits = 5", errMsg) tk.MustExec("alter table auto shard_row_id_bits = 0") // Hack an existing table with shard_row_id_bits and primary key as handle From 0624444d6034ab6aa6e826eba4089b7e2863cb15 Mon Sep 17 00:00:00 2001 From: lysu Date: Thu, 18 Mar 2021 13:36:04 +0800 Subject: [PATCH 13/16] fix test --- cmd/explaintest/r/clustered_index.result | 42 +++++++++++------------- cmd/explaintest/t/clustered_index.test | 2 +- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/cmd/explaintest/r/clustered_index.result b/cmd/explaintest/r/clustered_index.result index b6040f2a0eec3..5fc18247bdad4 100644 --- a/cmd/explaintest/r/clustered_index.result +++ b/cmd/explaintest/r/clustered_index.result @@ -3,7 +3,7 @@ create database with_cluster_index; drop database if exists wout_cluster_index; create database wout_cluster_index; use with_cluster_index; -create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) clustered, unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; +create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) clustered, key idx_1 ( col_3 ), unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) clustered, unique key idx_7 ( col_5 ) ) ; create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) clustered, key idx_9 ( col_11 ) ) ; create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) clustered, key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; @@ -26,9 +26,9 @@ load stats 's/wout_cluster_index_tbl_3.json'; load stats 's/wout_cluster_index_tbl_4.json'; explain select count(*) from with_cluster_index.tbl_0 where col_0 < 5429 ; id estRows task access object operator info -StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 +StreamAgg_17 1.00 root funcs:count(Column#8)->Column#6 └─IndexReader_18 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 └─IndexRangeScan_16 798.90 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,5429), keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 < 5429 ; id estRows task access object operator info @@ -38,9 +38,9 @@ StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 └─IndexRangeScan_16 798.90 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,5429), keep order:false explain select count(*) from with_cluster_index.tbl_0 where col_0 < 41 ; id estRows task access object operator info -StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 +StreamAgg_17 1.00 root funcs:count(Column#8)->Column#6 └─IndexReader_18 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 └─IndexRangeScan_16 41.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,41), keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 < 41 ; id estRows task access object operator info @@ -61,11 +61,10 @@ Projection_4 4509.00 root wout_cluster_index.tbl_2.col_14 └─TableFullScan_5 4673.00 cop[tikv] table:tbl_2 keep order:false explain select sum( col_4 ) from with_cluster_index.tbl_0 where col_3 != '1993-12-02' ; id estRows task access object operator info -StreamAgg_37 1.00 root funcs:sum(Column#20)->Column#7 -└─TableReader_38 1.00 root data:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:sum(with_cluster_index.tbl_0.col_4)->Column#20 - └─Selection_36 2244.00 cop[tikv] ne(with_cluster_index.tbl_0.col_3, 1993-12-02 00:00:00.000000) - └─TableFullScan_35 2244.00 cop[tikv] table:tbl_0 keep order:false +StreamAgg_17 1.00 root funcs:sum(Column#8)->Column#6 +└─TableReader_18 1.00 root data:StreamAgg_9 + └─StreamAgg_9 1.00 cop[tikv] funcs:sum(with_cluster_index.tbl_0.col_4)->Column#8 + └─TableRangeScan_16 2244.00 cop[tikv] table:tbl_0 range:[-inf,1993-12-02 00:00:00), (1993-12-02 00:00:00,+inf], keep order:false explain select sum( col_4 ) from wout_cluster_index.tbl_0 where col_3 != '1993-12-02' ; id estRows task access object operator info StreamAgg_37 1.00 root funcs:sum(Column#20)->Column#7 @@ -83,20 +82,19 @@ IndexReader_6 1.00 root index:IndexRangeScan_5 └─IndexRangeScan_5 1.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,0], keep order:false explain select col_3 from with_cluster_index.tbl_0 where col_3 >= '1981-09-15' ; id estRows task access object operator info -IndexReader_10 1859.31 root index:IndexRangeScan_9 -└─IndexRangeScan_9 1859.31 cop[tikv] table:tbl_0, index:idx_2(col_3) range:[1981-09-15 00:00:00,+inf], keep order:false +TableReader_6 1859.31 root data:TableRangeScan_5 +└─TableRangeScan_5 1859.31 cop[tikv] table:tbl_0 range:[1981-09-15 00:00:00,+inf], keep order:false explain select col_3 from wout_cluster_index.tbl_0 where col_3 >= '1981-09-15' ; id estRows task access object operator info IndexReader_10 1859.31 root index:IndexRangeScan_9 └─IndexRangeScan_9 1859.31 cop[tikv] table:tbl_0, index:idx_2(col_3) range:[1981-09-15 00:00:00,+inf], keep order:false explain select tbl_2.col_14 , tbl_0.col_1 from with_cluster_index.tbl_2 right join with_cluster_index.tbl_0 on col_3 = col_11 ; id estRows task access object operator info -IndexJoin_10 2533.51 root right outer join, inner:IndexReader_9, outer key:with_cluster_index.tbl_0.col_3, inner key:with_cluster_index.tbl_2.col_11, equal cond:eq(with_cluster_index.tbl_0.col_3, with_cluster_index.tbl_2.col_11) -├─TableReader_35(Build) 2244.00 root data:TableFullScan_34 -│ └─TableFullScan_34 2244.00 cop[tikv] table:tbl_0 keep order:false -└─IndexReader_9(Probe) 1.13 root index:Selection_8 - └─Selection_8 1.13 cop[tikv] not(isnull(with_cluster_index.tbl_2.col_11)) - └─IndexRangeScan_7 1.17 cop[tikv] table:tbl_2, index:idx_9(col_11) range: decided by [eq(with_cluster_index.tbl_2.col_11, with_cluster_index.tbl_0.col_3)], keep order:false +MergeJoin_6 2533.51 root right outer join, left key:with_cluster_index.tbl_2.col_11, right key:with_cluster_index.tbl_0.col_3 +├─IndexReader_21(Build) 4509.00 root index:IndexFullScan_20 +│ └─IndexFullScan_20 4509.00 cop[tikv] table:tbl_2, index:idx_9(col_11) keep order:true +└─TableReader_23(Probe) 2244.00 root data:TableFullScan_22 + └─TableFullScan_22 2244.00 cop[tikv] table:tbl_0 keep order:true explain select tbl_2.col_14 , tbl_0.col_1 from wout_cluster_index.tbl_2 right join wout_cluster_index.tbl_0 on col_3 = col_11 ; id estRows task access object operator info HashJoin_22 2533.51 root right outer join, equal:[eq(wout_cluster_index.tbl_2.col_11, wout_cluster_index.tbl_0.col_3)] @@ -107,9 +105,9 @@ HashJoin_22 2533.51 root right outer join, equal:[eq(wout_cluster_index.tbl_2.c └─TableFullScan_41 4673.00 cop[tikv] table:tbl_2 keep order:false explain select count(*) from with_cluster_index.tbl_0 where col_0 <= 0 ; id estRows task access object operator info -StreamAgg_16 1.00 root funcs:count(Column#9)->Column#7 +StreamAgg_16 1.00 root funcs:count(Column#8)->Column#6 └─IndexReader_17 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 └─IndexRangeScan_11 1.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,0], keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 <= 0 ; id estRows task access object operator info @@ -119,9 +117,9 @@ StreamAgg_16 1.00 root funcs:count(Column#9)->Column#7 └─IndexRangeScan_11 1.00 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[-inf,0], keep order:false explain select count(*) from with_cluster_index.tbl_0 where col_0 >= 803163 ; id estRows task access object operator info -StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 +StreamAgg_17 1.00 root funcs:count(Column#8)->Column#6 └─IndexReader_18 1.00 root index:StreamAgg_9 - └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 + └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#8 └─IndexRangeScan_16 109.70 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[803163,+inf], keep order:false explain select count(*) from wout_cluster_index.tbl_0 where col_0 >= 803163 ; id estRows task access object operator info diff --git a/cmd/explaintest/t/clustered_index.test b/cmd/explaintest/t/clustered_index.test index 0f2d234c16b2c..9415781f7caf1 100644 --- a/cmd/explaintest/t/clustered_index.test +++ b/cmd/explaintest/t/clustered_index.test @@ -4,7 +4,7 @@ drop database if exists wout_cluster_index; create database wout_cluster_index; use with_cluster_index; -create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) , key idx_1 ( col_3 ) clustered, unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; +create table tbl_0 ( col_0 decimal not null , col_1 blob(207) , col_2 text , col_3 datetime default '1986-07-01' , col_4 bigint unsigned default 1504335725690712365 , primary key idx_0 ( col_3,col_2(1),col_1(6) ) clustered, key idx_1 ( col_3 ), unique key idx_2 ( col_3 ) , unique key idx_3 ( col_0 ) , key idx_4 ( col_1(1),col_2(1) ) , key idx_5 ( col_2(1) ) ) ; create table tbl_1 ( col_5 char(135) , col_6 bit(17) default 50609 not null , col_7 char(202) default 'IoQWYoGdbbgBDlxpDHQ' , col_8 char(213) , col_9 time not null , primary key idx_6 ( col_6 ) clustered, unique key idx_7 ( col_5 ) ) ; create table tbl_2 ( col_10 datetime default '1976-05-11' , col_11 datetime , col_12 float , col_13 double(56,29) default 18.0118 , col_14 char not null , primary key idx_8 ( col_14,col_13,col_10 ) clustered, key idx_9 ( col_11 ) ) ; create table tbl_3 ( col_15 tinyint default -91 not null , col_16 bit(61) default 990141831018971350 not null , col_17 double(244,22) default 3985 not null , col_18 binary(32) default 'kxMlWqvpxXNBlxoU' , col_19 text(401) , primary key idx_10 ( col_18,col_19(4) ) clustered, key idx_11 ( col_17,col_18,col_19(2),col_15,col_16 ) , unique key idx_12 ( col_17 ) ) ; From f68bbf75beb36ca7127daf950914e3a93fb1556f Mon Sep 17 00:00:00 2001 From: lysu Date: Thu, 18 Mar 2021 14:07:30 +0800 Subject: [PATCH 14/16] let failpoint test in serial suite to make test stable --- executor/analyze_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/analyze_test.go b/executor/analyze_test.go index d535707738173..66b7e03f52549 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -731,7 +731,7 @@ func (s *testFastAnalyze) TestFastAnalyzeRetryRowCount(c *C) { c.Assert(row[5], Equals, "30") } -func (s *testSuite9) TestFailedAnalyzeRequest(c *C) { +func (s *testSuite10) TestFailedAnalyzeRequest(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists t") From 42e53aeaca70ff5b6036092e0be039455ecb154a Mon Sep 17 00:00:00 2001 From: tangenta Date: Thu, 18 Mar 2021 14:32:53 +0800 Subject: [PATCH 15/16] disallow non primary key to be clustered --- ddl/ddl_api.go | 6 ++++++ session/clustered_index_test.go | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 6616422d6feee..57a8f203b6575 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -1407,6 +1407,12 @@ func buildTableInfo( tbInfo.Columns = append(tbInfo.Columns, hiddenCol) tblColumns = append(tblColumns, table.ToColumn(hiddenCol)) } + // Check clustered on non-primary key. + if constr.Option != nil && constr.Option.PrimaryKeyTp != model.PrimaryKeyTypeDefault && + constr.Tp != ast.ConstraintPrimaryKey { + msg := mysql.Message("CLUSTERED/NONCLUSTERED keyword is only supported for primary key", nil) + return nil, dbterror.ClassDDL.NewStdErr(errno.ErrUnsupportedDDLOperation, msg) + } if constr.Tp == ast.ConstraintForeignKey { for _, fk := range tbInfo.ForeignKeys { if fk.Name.L == strings.ToLower(constr.Name) { diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index 2df4e40143ad3..28be2c0ec50a5 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -445,6 +445,17 @@ func (s *testClusteredSuite) TestClusteredIndexSyntax(c *C) { assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] nonclustered */);", nonClustered) assertPkType("create table t (a int, b varchar(255), primary key(b, a) clustered);", clustered) assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] clustered */);", clustered) + + tk.MustGetErrCode("create table t (a varchar(255) unique key clustered);", errno.ErrParse) + tk.MustGetErrCode("create table t (a varchar(255), foreign key (a) reference t1(a) clustered);", errno.ErrParse) + tk.MustGetErrCode("create table t (a varchar(255), foreign key (a) clustered reference t1(a));", errno.ErrParse) + tk.MustGetErrCode("create table t (a varchar(255) clustered);", errno.ErrParse) + + errMsg := "[ddl:8200]CLUSTERED/NONCLUSTERED keyword is only supported for primary key" + tk.MustGetErrMsg("create table t (a varchar(255), unique key(a) clustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), unique index(a) clustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), key(a) clustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), index(a) clustered);", errMsg) } func (s *testClusteredSerialSuite) TestPrefixClusteredIndexAddIndexAndRecover(c *C) { From 0ad5e3d7c1439c7480332adc3c2358a0d4e262c8 Mon Sep 17 00:00:00 2001 From: tangenta Date: Thu, 18 Mar 2021 14:40:06 +0800 Subject: [PATCH 16/16] add negative tests for nonclustered keyword --- session/clustered_index_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index 28be2c0ec50a5..f9336b9f4991b 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -453,9 +453,15 @@ func (s *testClusteredSuite) TestClusteredIndexSyntax(c *C) { errMsg := "[ddl:8200]CLUSTERED/NONCLUSTERED keyword is only supported for primary key" tk.MustGetErrMsg("create table t (a varchar(255), unique key(a) clustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), unique key(a) nonclustered);", errMsg) tk.MustGetErrMsg("create table t (a varchar(255), unique index(a) clustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), unique index(a) nonclustered);", errMsg) tk.MustGetErrMsg("create table t (a varchar(255), key(a) clustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), key(a) nonclustered);", errMsg) tk.MustGetErrMsg("create table t (a varchar(255), index(a) clustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), index(a) nonclustered);", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), b decimal(5, 4), primary key (a, b) clustered, key (b) clustered)", errMsg) + tk.MustGetErrMsg("create table t (a varchar(255), b decimal(5, 4), primary key (a, b) clustered, key (b) nonclustered)", errMsg) } func (s *testClusteredSerialSuite) TestPrefixClusteredIndexAddIndexAndRecover(c *C) {