Skip to content

Commit

Permalink
Merge branch 'release-4.0' into release-4.0-a426a0e5ff45
Browse files Browse the repository at this point in the history
  • Loading branch information
dyzsr committed Nov 25, 2020
2 parents 8722c0a + e8e9e76 commit 75c5bf5
Show file tree
Hide file tree
Showing 99 changed files with 2,598 additions and 1,803 deletions.
24 changes: 11 additions & 13 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,18 @@ StreamAgg_12 1.00 root funcs:sum(Column#10)->Column#8
└─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
explain select 1 in (select c2 from t2) from t1;
id estRows task access object operator info
HashJoin_7 10000.00 root CARTESIAN left outer semi join
├─TableReader_14(Build) 10.00 root data:Selection_13
│ └─Selection_13 10.00 cop[tikv] eq(1, test.t2.c2)
│ └─TableFullScan_12 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
HashJoin_7 10000.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2)
├─TableReader_13(Build) 10000.00 root data:TableFullScan_12
│ └─TableFullScan_12 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
└─TableReader_9(Probe) 10000.00 root data:TableFullScan_8
└─TableFullScan_8 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
explain select sum(6 in (select c2 from t2)) from t1;
id estRows task access object operator info
StreamAgg_12 1.00 root funcs:sum(Column#10)->Column#8
└─Projection_22 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10
└─HashJoin_21 10000.00 root CARTESIAN left outer semi join
├─TableReader_20(Build) 10.00 root data:Selection_19
│ └─Selection_19 10.00 cop[tikv] eq(6, test.t2.c2)
│ └─TableFullScan_18 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
└─Projection_21 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10
└─HashJoin_20 10000.00 root CARTESIAN left outer semi join, other cond:eq(6, test.t2.c2)
├─TableReader_19(Build) 10000.00 root data:TableFullScan_18
│ └─TableFullScan_18 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
└─TableReader_15(Probe) 10000.00 root data:TableFullScan_14
└─TableFullScan_14 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;
Expand Down Expand Up @@ -285,22 +283,22 @@ node [style=filled, color=lightgrey]
color=black
label = "root"
"HashJoin_7" -> "TableReader_9"
"HashJoin_7" -> "TableReader_14"
"HashJoin_7" -> "TableReader_13"
}
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableFullScan_8"
}
subgraph cluster13{
subgraph cluster12{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_13" -> "TableFullScan_12"
"TableFullScan_12"
}
"TableReader_9" -> "TableFullScan_8"
"TableReader_14" -> "Selection_13"
"TableReader_13" -> "TableFullScan_12"
}

drop table if exists t1, t2, t3, t4;
Expand Down
15 changes: 7 additions & 8 deletions cmd/explaintest/r/explain_easy_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ Limit_10 1.00 root offset:0, count:1
set @@session.tidb_opt_insubq_to_join_and_agg=0;
explain select 1 in (select c2 from t2) from t1;
id estRows task access object operator info
HashJoin_7 1999.00 root CARTESIAN left outer semi join
├─TableReader_14(Build) 0.00 root data:Selection_13
│ └─Selection_13 0.00 cop[tikv] eq(1, test.t2.c2)
│ └─TableFullScan_12 1985.00 cop[tikv] table:t2 keep order:false
HashJoin_7 1999.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2)
├─TableReader_13(Build) 1985.00 root data:TableFullScan_12
│ └─TableFullScan_12 1985.00 cop[tikv] table:t2 keep order:false
└─TableReader_9(Probe) 1999.00 root data:TableFullScan_8
└─TableFullScan_8 1999.00 cop[tikv] table:t1 keep order:false
explain format="dot" select 1 in (select c2 from t2) from t1;
Expand All @@ -135,22 +134,22 @@ node [style=filled, color=lightgrey]
color=black
label = "root"
"HashJoin_7" -> "TableReader_9"
"HashJoin_7" -> "TableReader_14"
"HashJoin_7" -> "TableReader_13"
}
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableFullScan_8"
}
subgraph cluster13{
subgraph cluster12{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_13" -> "TableFullScan_12"
"TableFullScan_12"
}
"TableReader_9" -> "TableFullScan_8"
"TableReader_14" -> "Selection_13"
"TableReader_13" -> "TableFullScan_12"
}

explain select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 LIMIT 1;
Expand Down
23 changes: 1 addition & 22 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ const (
DefStatusHost = "0.0.0.0"
// DefStoreLivenessTimeout is the default value for store liveness timeout.
DefStoreLivenessTimeout = "5s"
// DefTiDBRedactLog is the default value for redact log.
DefTiDBRedactLog = 0
)

// Valid config maps
Expand Down Expand Up @@ -146,8 +144,6 @@ type Config struct {
SkipRegisterToDashboard bool `toml:"skip-register-to-dashboard" json:"skip-register-to-dashboard"`
// EnableTelemetry enables the usage data report to PingCAP.
EnableTelemetry bool `toml:"enable-telemetry" json:"enable-telemetry"`
// EnableRedactLog indicates that whether redact log, 0 is disable. 1 is enable.
EnableRedactLog int32 `toml:"enable-redact-log" json:"enable-redact-log"`
}

// UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed
Expand Down Expand Up @@ -697,7 +693,6 @@ var defaultConf = Config{
},
EnableCollectExecutionInfo: true,
EnableTelemetry: true,
EnableRedactLog: DefTiDBRedactLog,
}

var (
Expand Down Expand Up @@ -731,6 +726,7 @@ var deprecatedConfig = map[string]struct{}{
"txn-local-latches.capacity": {},
"max-txn-time-use": {},
"experimental.allow-auto-random": {},
"enable-redact-log": {}, // use variable tidb_redact_log instead
}

func isAllDeprecatedConfigItems(items []string) bool {
Expand Down Expand Up @@ -934,23 +930,6 @@ var TableLockDelayClean = func() uint64 {
return GetGlobalConfig().DelayCleanTableLock
}

// RedactLogEnabled uses to check whether enabled the log redact.
func RedactLogEnabled() bool {
return atomic.LoadInt32(&GetGlobalConfig().EnableRedactLog) == 1
}

// SetRedactLog uses to set log redact status.
func SetRedactLog(enable bool) {
value := int32(0)
if enable {
value = 1
}
g := GetGlobalConfig()
newConf := *g
newConf.EnableRedactLog = value
StoreGlobalConfig(&newConf)
}

// ToLogConfig converts *Log to *logutil.LogConfig.
func (l *Log) ToLogConfig() *logutil.LogConfig {
return logutil.NewLogConfig(l.Level, l.Format, l.SlowQueryFile, l.File, l.getDisableTimestamp(), func(config *zaplog.Config) { config.DisableErrorVerbose = l.getDisableErrorStack() })
Expand Down
2 changes: 1 addition & 1 deletion ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ func (s *testColumnSuite) TestModifyColumn(c *C) {
err error
}{
{"int", "bigint", nil},
{"int", "int unsigned", errUnsupportedModifyColumn.GenWithStackByArgs("length 10 is less than origin 11")},
{"int", "int unsigned", errUnsupportedModifyColumn.GenWithStackByArgs("can't change unsigned integer to signed or vice versa")},
{"varchar(10)", "text", nil},
{"varbinary(10)", "blob", nil},
{"text", "blob", errUnsupportedModifyCharset.GenWithStackByArgs("charset from utf8mb4 to binary")},
Expand Down
116 changes: 115 additions & 1 deletion ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
)
Expand Down Expand Up @@ -333,9 +334,12 @@ func (s *testIntegrationSuite2) TestCreateTableWithHashPartition(c *C) {
PARTITION p1 VALUES LESS THAN (200),
PARTITION p2 VALUES LESS THAN MAXVALUE)`)
tk.MustGetErrCode("select * from t_sub partition (p0)", tmysql.ErrPartitionClauseOnNonpartitioned)
tk.MustGetErrCode("create table t_hash(a int) partition by hash (a) partitions 3 (partition p1, partition p2, partition p2);", tmysql.ErrSameNamePartition)
}

func (s *testIntegrationSuite1) TestCreateTableWithRangeColumnPartition(c *C) {
func (s *testIntegrationSuite7) TestCreateTableWithRangeColumnPartition(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists log_message_1;")
Expand Down Expand Up @@ -456,6 +460,13 @@ create table log_message_1 (
"PARTITION p1 VALUES LESS THAN (20190906));",
ddl.ErrWrongTypeColumnValue,
},
{
"create table t(a char(10) collate utf8mb4_bin) " +
"partition by range columns (a) (" +
"partition p0 values less than ('a'), " +
"partition p1 values less than ('G'));",
ddl.ErrRangeNotIncreasing,
},
}
for i, t := range cases {
_, err := tk.Exec(t.sql)
Expand All @@ -465,13 +476,25 @@ create table log_message_1 (
))
}

tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1 (a int, b char(3)) partition by range columns (a, b) (" +
"partition p0 values less than (1, 'a')," +
"partition p1 values less than (2, maxvalue))")

tk.MustExec("drop table if exists t2;")
tk.MustExec("create table t2 (a int, b char(3)) partition by range columns (b) (" +
"partition p0 values less than ( 'a')," +
"partition p1 values less than (maxvalue))")

tk.MustExec("drop table if exists t;")
tk.MustExec(`create table t(a char(10) collate utf8mb4_general_ci) partition by range columns (a) (
partition p0 values less than ('a'),
partition p1 values less than ('G'));`)

tk.MustExec("drop table if exists t;")
tk.MustExec(`create table t(a int) partition by range columns (a) (
partition p0 values less than (10),
partition p1 values less than (20));`)
}

func (s *testIntegrationSuite3) TestCreateTableWithKeyPartition(c *C) {
Expand Down Expand Up @@ -1883,3 +1906,94 @@ func (s *testIntegrationSuite3) TestCommitWhenSchemaChange(c *C) {
tk.MustExec("admin check table schema_change")
tk.MustQuery("select * from schema_change").Check(testkit.Rows())
}

func (s *testIntegrationSuite7) TestCreatePartitionTableWithWrongType(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
var err error
_, err = tk.Exec(`create table t(
b int(10)
) partition by range columns (b) (
partition p0 values less than (0x10),
partition p3 values less than (0x20)
)`)
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec(`create table t(
b int(10)
) partition by range columns (b) (
partition p0 values less than ('g'),
partition p3 values less than ('k')
)`)
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec(`create table t(
b char(10)
) partition by range columns (b) (
partition p0 values less than (30),
partition p3 values less than (60)
)`)
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec(`create table t(
b datetime
) partition by range columns (b) (
partition p0 values less than ('g'),
partition p3 values less than ('m')
)`)
c.Assert(err, NotNil)
}

func (s *testIntegrationSuite7) TestAddPartitionForTableWithWrongType(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop tables if exists t_int, t_char, t_date")
tk.MustExec(`create table t_int(b int(10))
partition by range columns (b) (
partition p0 values less than (10)
)`)

tk.MustExec(`create table t_char(b char(10))
partition by range columns (b) (
partition p0 values less than ('a')
)`)

tk.MustExec(`create table t_date(b datetime)
partition by range columns (b) (
partition p0 values less than ('2020-09-01')
)`)

var err error

_, err = tk.Exec("alter table t_int add partition (partition p1 values less than ('g'))")
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec("alter table t_int add partition (partition p1 values less than (0x20))")
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec("alter table t_char add partition (partition p1 values less than (0x20))")
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec("alter table t_char add partition (partition p1 values less than (10))")
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec("alter table t_date add partition (partition p1 values less than ('m'))")
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec("alter table t_date add partition (partition p1 values less than (0x20))")
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)

_, err = tk.Exec("alter table t_date add partition (partition p1 values less than (20))")
c.Assert(err, NotNil)
c.Assert(ddl.ErrWrongTypeColumnValue.Equal(err), IsTrue)
}
19 changes: 19 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4930,3 +4930,22 @@ func init() {
domain.SchemaOutOfDateRetryInterval = int64(50 * time.Millisecond)
domain.SchemaOutOfDateRetryTimes = int32(50)
}

// Test issue #20529.
func (s *testSerialDBSuite) TestColumnTypeChangeIgnoreDisplayLength(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

// Change int to int(3).
// Although display length is increased, the default flen is decreased, reorg is needed.
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
tk.MustExec("alter table t modify column a int(3)")

// Change int to bigint(1)
// Although display length is decreased, default flen is the same, reorg is not needed.
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
tk.MustExec("alter table t modify column a bigint(1)")
tk.MustExec("drop table if exists t")
}
Loading

0 comments on commit 75c5bf5

Please sign in to comment.