Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <disxiaofei@163.com>
  • Loading branch information
Yisaer committed Dec 1, 2021
2 parents 6c2a430 + a046014 commit ebac47a
Show file tree
Hide file tree
Showing 56 changed files with 1,186 additions and 243 deletions.
12 changes: 12 additions & 0 deletions cmd/explaintest/r/explain_generate_column_substitute.result
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,15 @@ select * from PK_S_MULTI_30_tmp use index (eidx) where truncate(col1, 3) <= trun
COL1 COL2 COL3
-1.7976931348623157e308 0 0
-1.7976931348623157e308 1 0
create table t004(a date);
insert into t004 values ('2021-08-20');
select * from t004 where timestampadd(microsecond, 1, a) = timestampadd(microsecond, 1, '2021-08-20');
a
2021-08-20
alter table t004 add index eidx ((timestampadd(microsecond, 1, a)));
select * from t004 use index(eidx) where timestampadd(microsecond, 1, a) = timestampadd(microsecond, 1, '2021-08-20');
a
2021-08-20
select * from t004 ignore index (eidx) where timestampadd(microsecond, 1, a) = timestampadd(microsecond, 1, '2021-08-20');
a
2021-08-20
7 changes: 7 additions & 0 deletions cmd/explaintest/t/explain_generate_column_substitute.test
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,10 @@ select * from `PK_S_MULTI_30_tmp` ignore index (expression_index) where floor(c
alter table PK_S_MULTI_30_tmp add index eidx ((truncate(col1, 3)));
select * from PK_S_MULTI_30_tmp ignore index (eidx) where truncate(col1, 3) <= truncate(-1.7976931348623157e308, 3);
select * from PK_S_MULTI_30_tmp use index (eidx) where truncate(col1, 3) <= truncate(-1.7976931348623157e308, 3);

create table t004(a date);
insert into t004 values ('2021-08-20');
select * from t004 where timestampadd(microsecond, 1, a) = timestampadd(microsecond, 1, '2021-08-20');
alter table t004 add index eidx ((timestampadd(microsecond, 1, a)));
select * from t004 use index(eidx) where timestampadd(microsecond, 1, a) = timestampadd(microsecond, 1, '2021-08-20');
select * from t004 ignore index (eidx) where timestampadd(microsecond, 1, a) = timestampadd(microsecond, 1, '2021-08-20');
2 changes: 2 additions & 0 deletions ddl/backfilling.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ func (w *worker) writePhysicalTableRecord(t table.PhysicalTable, bfWorkerType ba
backfillWorkers = append(backfillWorkers, idxWorker.backfillWorker)
go idxWorker.backfillWorker.run(reorgInfo.d, idxWorker, job)
case typeUpdateColumnWorker:
// Setting InCreateOrAlterStmt tells the difference between SELECT casting and ALTER COLUMN casting.
sessCtx.GetSessionVars().StmtCtx.InCreateOrAlterStmt = true
updateWorker := newUpdateColumnWorker(sessCtx, w, i, t, oldColInfo, colInfo, decodeColMap, reorgInfo.ReorgMeta.SQLMode)
updateWorker.priority = job.Priority
backfillWorkers = append(backfillWorkers, updateWorker.backfillWorker)
Expand Down
46 changes: 46 additions & 0 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,52 @@ func (s *testColumnTypeChangeSuite) TestCastToTimeStampDecodeError(c *C) {
tk.MustQuery("select timestamp(cast('1000-11-11 12-3-1' as date));").Check(testkit.Rows("1000-11-11 00:00:00"))
}

// https://github.com/pingcap/tidb/issues/25285.
func (s *testColumnTypeChangeSuite) TestCastFromZeroIntToTimeError(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")

prepare := func() {
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int);")
tk.MustExec("insert into t values (0);")
}
const errCodeNone = -1
testCases := []struct {
sqlMode string
errCode int
}{
{"STRICT_TRANS_TABLES", mysql.ErrTruncatedWrongValue},
{"STRICT_ALL_TABLES", mysql.ErrTruncatedWrongValue},
{"NO_ZERO_IN_DATE", errCodeNone},
{"NO_ZERO_DATE", errCodeNone},
{"ALLOW_INVALID_DATES", errCodeNone},
{"", errCodeNone},
}
for _, tc := range testCases {
prepare()
tk.MustExec(fmt.Sprintf("set @@sql_mode = '%s';", tc.sqlMode))
if tc.sqlMode == "NO_ZERO_DATE" {
tk.MustQuery(`select date(0);`).Check(testkit.Rows("<nil>"))
} else {
tk.MustQuery(`select date(0);`).Check(testkit.Rows("0000-00-00"))
}
tk.MustQuery(`select time(0);`).Check(testkit.Rows("00:00:00"))
if tc.errCode == errCodeNone {
tk.MustExec("alter table t modify column a date;")
prepare()
tk.MustExec("alter table t modify column a datetime;")
prepare()
tk.MustExec("alter table t modify column a timestamp;")
} else {
tk.MustGetErrCode("alter table t modify column a date;", mysql.ErrTruncatedWrongValue)
tk.MustGetErrCode("alter table t modify column a datetime;", mysql.ErrTruncatedWrongValue)
tk.MustGetErrCode("alter table t modify column a timestamp;", mysql.ErrTruncatedWrongValue)
}
}
tk.MustExec("drop table if exists t;")
}

func (s *testColumnTypeChangeSuite) TestChangeFromTimeToYear(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
Expand Down
9 changes: 3 additions & 6 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5474,8 +5474,7 @@ func (s *testDBSuite1) TestModifyColumnTime_YearToDate(c *C) {
{"year", `"69"`, "date", "", errno.ErrTruncatedWrongValue},
{"year", `"70"`, "date", "", errno.ErrTruncatedWrongValue},
{"year", `"99"`, "date", "", errno.ErrTruncatedWrongValue},
// MySQL will get "Data truncation: Incorrect date value: '0000'", but TiDB treat 00 as valid datetime.
{"year", `00`, "date", "0000-00-00", 0},
{"year", `00`, "date", "", errno.ErrTruncatedWrongValue},
{"year", `69`, "date", "", errno.ErrTruncatedWrongValue},
{"year", `70`, "date", "", errno.ErrTruncatedWrongValue},
{"year", `99`, "date", "", errno.ErrTruncatedWrongValue},
Expand All @@ -5492,8 +5491,7 @@ func (s *testDBSuite1) TestModifyColumnTime_YearToDatetime(c *C) {
{"year", `"69"`, "datetime", "", errno.ErrTruncatedWrongValue},
{"year", `"70"`, "datetime", "", errno.ErrTruncatedWrongValue},
{"year", `"99"`, "datetime", "", errno.ErrTruncatedWrongValue},
// MySQL will get "Data truncation: Incorrect date value: '0000'", but TiDB treat 00 as valid datetime.
{"year", `00`, "datetime", "0000-00-00 00:00:00", 0},
{"year", `00`, "datetime", "", errno.ErrTruncatedWrongValue},
{"year", `69`, "datetime", "", errno.ErrTruncatedWrongValue},
{"year", `70`, "datetime", "", errno.ErrTruncatedWrongValue},
{"year", `99`, "datetime", "", errno.ErrTruncatedWrongValue},
Expand All @@ -5510,8 +5508,7 @@ func (s *testDBSuite1) TestModifyColumnTime_YearToTimestamp(c *C) {
{"year", `"69"`, "timestamp", "", errno.ErrTruncatedWrongValue},
{"year", `"70"`, "timestamp", "", errno.ErrTruncatedWrongValue},
{"year", `"99"`, "timestamp", "", errno.ErrTruncatedWrongValue},
// MySQL will get "Data truncation: Incorrect date value: '0000'", but TiDB treat 00 as valid datetime.
{"year", `00`, "timestamp", "0000-00-00 00:00:00", 0},
{"year", `00`, "timestamp", "", errno.ErrTruncatedWrongValue},
{"year", `69`, "timestamp", "", errno.ErrTruncatedWrongValue},
{"year", `70`, "timestamp", "", errno.ErrTruncatedWrongValue},
{"year", `99`, "timestamp", "", errno.ErrTruncatedWrongValue},
Expand Down
8 changes: 8 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4721,6 +4721,14 @@ func (d *ddl) AlterTableSetTiFlashReplica(ctx sessionctx.Context, ident ast.Iden
return ErrOptOnTemporaryTable.GenWithStackByArgs("set tiflash replica")
}

// Ban setting replica count for tables which has charset not supported by TiFlash
for _, col := range tb.Cols() {
_, ok := charset.TiFlashSupportedCharsets[col.Charset]
if !ok {
return errAlterReplicaForUnsupportedCharsetTable.GenWithStackByArgs(col.Charset)
}
}

tbReplicaInfo := tb.Meta().TiFlashReplica
if tbReplicaInfo != nil && tbReplicaInfo.Count == replicaInfo.Count &&
len(tbReplicaInfo.LocationLabels) == len(replicaInfo.Labels) {
Expand Down
2 changes: 2 additions & 0 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ var (
errFkColumnCannotDrop = dbterror.ClassDDL.NewStd(mysql.ErrFkColumnCannotDrop)
errFKIncompatibleColumns = dbterror.ClassDDL.NewStd(mysql.ErrFKIncompatibleColumns)

errAlterReplicaForUnsupportedCharsetTable = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "ALTER table replica for table contain %s charset"), nil))

errOnlyOnRangeListPartition = dbterror.ClassDDL.NewStd(mysql.ErrOnlyOnRangeListPartition)
// errWrongKeyColumn is for table column cannot be indexed.
errWrongKeyColumn = dbterror.ClassDDL.NewStd(mysql.ErrWrongKeyColumn)
Expand Down
8 changes: 8 additions & 0 deletions distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ func (builder *RequestBuilder) SetStreaming(streaming bool) *RequestBuilder {
return builder
}

// SetPaging sets "Paging" flag for "kv.Request".
func (builder *RequestBuilder) SetPaging(paging bool) *RequestBuilder {
builder.Request.Paging = paging
return builder
}

// SetConcurrency sets "Concurrency" for "kv.Request".
func (builder *RequestBuilder) SetConcurrency(concurrency int) *RequestBuilder {
builder.Request.Concurrency = concurrency
Expand Down Expand Up @@ -715,6 +721,8 @@ func encodeIndexKey(sc *stmtctx.StatementContext, ran *ranger.Range) ([]byte, []
}
}

// NOTE: this is a hard-code operation to avoid wrong results when accessing unique index with NULL;
// Please see https://github.com/pingcap/tidb/issues/29650 for more details
if hasNull {
// Append 0 to make unique-key range [null, null] to be a scan rather than point-get.
high = kv.Key(high).Next()
Expand Down
4 changes: 4 additions & 0 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
ResultRows: GetResultRowsCount(a.Ctx, a.Plan),
ExecRetryCount: a.retryCount,
IsExplicitTxn: sessVars.TxnCtx.IsExplicit,
IsWriteCacheTable: sessVars.StmtCtx.WaitLockLeaseTime > 0,
}
if a.retryCount > 0 {
slowItems.ExecRetryTime = costTime - sessVars.DurationParse - sessVars.DurationCompile - time.Since(a.retryStartTime)
Expand Down Expand Up @@ -1193,6 +1194,9 @@ func (a *ExecStmt) SummaryStmt(succ bool) {
if tikvExecDetailRaw != nil {
tikvExecDetail = *(tikvExecDetailRaw.(*util.ExecDetails))
}
if stmtCtx.WaitLockLeaseTime > 0 {
execDetail.BackoffSleep["waitLockLeaseForCacheTable"] = stmtCtx.WaitLockLeaseTime
}
stmtExecInfo := &stmtsummary.StmtExecInfo{
SchemaName: strings.ToLower(sessVars.CurrentDB),
OriginalSQL: sql,
Expand Down
4 changes: 2 additions & 2 deletions executor/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func (h *CoprocessorDAGHandler) buildDAGExecutor(req *coprocessor.Request) (Exec
Username: dagReq.User.UserName,
Hostname: dagReq.User.UserHost,
}
authName, authHost, success := pm.GetAuthWithoutVerification(dagReq.User.UserName, dagReq.User.UserHost)
if success {
authName, authHost, success := pm.MatchIdentity(dagReq.User.UserName, dagReq.User.UserHost, false)
if success && pm.GetAuthWithoutVerification(authName, authHost) {
h.sctx.GetSessionVars().User.AuthUsername = authName
h.sctx.GetSessionVars().User.AuthHostname = authHost
h.sctx.GetSessionVars().ActiveRoles = pm.GetDefaultRoles(authName, authHost)
Expand Down
54 changes: 25 additions & 29 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8782,47 +8782,46 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) {

cases := []struct {
sql string
tagLabels []tipb.ResourceGroupTagLabel
tagLabels map[tipb.ResourceGroupTagLabel]struct{}
ignore bool
}{
{
sql: "insert into t values(1,1),(2,2),(3,3)",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
{
sql: "select * from t use index (idx) where a=1",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {},
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
{
sql: "select * from t use index (idx) where a in (1,2,3)",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {},
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
{
sql: "select * from t use index (idx) where a>1",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {},
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
{
sql: "select * from t where b>1",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {},
},
},
{
sql: "select a from t use index (idx) where a>1",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
{
Expand All @@ -8831,9 +8830,9 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) {
},
{
sql: "insert into t values(4,4)",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow: {},
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
{
Expand All @@ -8842,15 +8841,14 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) {
},
{
sql: "update t set a=5,b=5 where a=5",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
{
sql: "replace into t values(6,6)",
tagLabels: []tipb.ResourceGroupTagLabel{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex,
tagLabels: map[tipb.ResourceGroupTagLabel]struct{}{
tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex: {},
},
},
}
Expand All @@ -8874,10 +8872,8 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) {
}
c.Assert(sqlDigest.String(), Equals, expectSQLDigest.String(), commentf)
c.Assert(planDigest.String(), Equals, expectPlanDigest.String())
if len(ca.tagLabels) > 0 {
c.Assert(tagLabel, Equals, ca.tagLabels[0])
ca.tagLabels = ca.tagLabels[1:] // next label
}
_, ok := ca.tagLabels[tagLabel]
c.Assert(ok, Equals, true)
checkCnt++
}

Expand Down
2 changes: 1 addition & 1 deletion executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ func getColumnValueFactoryByName(sctx sessionctx.Context, colName string, column
return true, nil
}, nil
case variable.SlowLogPrepared, variable.SlowLogSucc, variable.SlowLogPlanFromCache, variable.SlowLogPlanFromBinding,
variable.SlowLogIsInternalStr, variable.SlowLogIsExplicitTxn:
variable.SlowLogIsInternalStr, variable.SlowLogIsExplicitTxn, variable.SlowLogIsWriteCacheTable:
return func(row []types.Datum, value string, tz *time.Location, checker *slowLogChecker) (valid bool, err error) {
v, err := strconv.ParseBool(value)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions executor/slow_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ select * from t;`
`0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0.38,0.021,0,0,0,1,637,0,10,10,10,10,100,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,` +
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,0,0,` +
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` +
`0,0,1,1,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
`0,0,1,0,1,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
`update t set i = 1;,select * from t;`
c.Assert(expectRecordString, Equals, recordString)

Expand All @@ -184,7 +184,7 @@ select * from t;`
`0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0.38,0.021,0,0,0,1,637,0,10,10,10,10,100,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,` +
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,0,0,` +
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` +
`0,0,1,1,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
`0,0,1,0,1,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
`update t set i = 1;,select * from t;`
c.Assert(expectRecordString, Equals, recordString)

Expand Down
17 changes: 17 additions & 0 deletions executor/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/israce"
"github.com/pingcap/tidb/util/kvcache"
"github.com/pingcap/tidb/util/testkit"
Expand Down Expand Up @@ -84,6 +85,22 @@ func (s *tiflashTestSuite) TearDownSuite(c *C) {
c.Assert(s.store.Close(), IsNil)
}

func (s *tiflashTestSuite) TestNonsupportCharsetTable(c *C) {
collate.SetCharsetFeatEnabledForTest(true)
defer collate.SetCharsetFeatEnabledForTest(false)
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 char(10) charset gbk collate gbk_bin)")
err := tk.ExecToErr("alter table t set tiflash replica 1")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported ALTER table replica for table contain gbk charset")

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a char(10) charset utf8)")
tk.MustExec("alter table t set tiflash replica 1")
}

func (s *tiflashTestSuite) TestReadPartitionTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
17 changes: 15 additions & 2 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (b *builtinDateSig) evalTime(row chunk.Row) (types.Time, bool, error) {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
}

if expr.IsZero() {
if expr.IsZero() && b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, expr.String()))
}

Expand Down Expand Up @@ -6714,7 +6714,20 @@ func (c *timestampAddFunctionClass) getFunction(ctx sessionctx.Context, args []E
if err != nil {
return nil, err
}
bf.tp = &types.FieldType{Tp: mysql.TypeString, Flen: mysql.MaxDatetimeWidthNoFsp, Decimal: types.UnspecifiedLength}
flen := mysql.MaxDatetimeWidthNoFsp
con, ok := args[0].(*Constant)
if !ok {
return nil, errors.New("should not happened")
}
unit, null, err := con.EvalString(ctx, chunk.Row{})
if null || err != nil {
return nil, errors.New("should not happened")
}
if unit == ast.TimeUnitMicrosecond.String() {
flen = mysql.MaxDatetimeWidthWithFsp
}

bf.tp.Flen = flen
sig := &builtinTimestampAddSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_TimestampAdd)
return sig, nil
Expand Down
Loading

0 comments on commit ebac47a

Please sign in to comment.