Skip to content

Commit

Permalink
Resolve the conflict
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed May 10, 2021
2 parents 7d8c27f + 04da3ce commit a18f522
Show file tree
Hide file tree
Showing 163 changed files with 4,346 additions and 1,189 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# TiDB Changelog
All notable changes to this project will be documented in this file. See also [Release Notes](https://github.com/pingcap/docs/blob/master/releases/rn.md), [TiKV Changelog](https://github.com/tikv/tikv/blob/master/CHANGELOG.md) and [PD Changelog](https://github.com/tikv/pd/blob/master/CHANGELOG.md).
All notable changes to this project will be documented in this file. See also [Release Notes](https://github.com/pingcap/docs/blob/master/releases/release-notes.md), [TiKV Changelog](https://github.com/tikv/tikv/blob/master/CHANGELOG.md) and [PD Changelog](https://github.com/tikv/pd/blob/master/CHANGELOG.md).

## [3.0.4] 2019-10-08
## New features
Expand Down
2 changes: 1 addition & 1 deletion ddl/backfilling.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func newBackfillWorker(sessCtx sessionctx.Context, worker *worker, id int, t tab
sessCtx: sessCtx,
taskCh: make(chan *reorgBackfillTask, 1),
resultCh: make(chan *backfillResult, 1),
priority: tikvstore.PriorityLow,
priority: kv.PriorityLow,
}
}

Expand Down
12 changes: 11 additions & 1 deletion ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,11 @@ func (w *worker) onModifyColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver in
return w.doModifyColumn(d, t, job, dbInfo, tblInfo, jobParam.newCol, oldCol, jobParam.pos)
}

if err = isGeneratedRelatedColumn(tblInfo, jobParam.newCol, oldCol); err != nil {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}

if jobParam.changingCol == nil {
changingColPos := &ast.ColumnPosition{Tp: ast.ColumnPositionNone}
newColName := model.NewCIStr(genChangingColumnUniqueName(tblInfo, oldCol))
Expand Down Expand Up @@ -1256,7 +1261,7 @@ func (w *updateColumnWorker) fetchRowColVals(txn kv.Transaction, taskRange reorg
}

func (w *updateColumnWorker) getRowRecord(handle kv.Handle, recordKey []byte, rawRow []byte) error {
_, err := w.rowDecoder.DecodeAndEvalRowWithMap(w.sessCtx, handle, rawRow, time.UTC, timeutil.SystemLocation(), w.rowMap)
_, err := w.rowDecoder.DecodeTheExistedColumnMap(w.sessCtx, handle, rawRow, time.UTC, w.rowMap)
if err != nil {
return errors.Trace(errCantDecodeRecord.GenWithStackByArgs("column", err))
}
Expand Down Expand Up @@ -1294,6 +1299,11 @@ func (w *updateColumnWorker) getRowRecord(handle kv.Handle, recordKey []byte, ra
})

w.rowMap[w.newColInfo.ID] = newColVal
_, err = w.rowDecoder.EvalRemainedExprColumnMap(w.sessCtx, timeutil.SystemLocation(), w.rowMap)
if err != nil {
return errors.Trace(err)
}

newColumnIDs := make([]int64, 0, len(w.rowMap))
newRow := make([]types.Datum, 0, len(w.rowMap))
for colID, val := range w.rowMap {
Expand Down
45 changes: 45 additions & 0 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,20 @@ func (s *testColumnTypeChangeSuite) TestChangingAttributeOfColumnWithFK(c *C) {
tk.MustExec("drop table if exists orders, users")
}

func (s *testColumnTypeChangeSuite) TestAlterPrimaryKeyToNull(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.Se.GetSessionVars().EnableChangeColumnType = true

tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t(a int not null, b int not null, primary key(a, b));")
tk.MustGetErrCode("alter table t modify a bigint null;", mysql.ErrPrimaryCantHaveNull)
tk.MustGetErrCode("alter table t change column a a bigint null;", mysql.ErrPrimaryCantHaveNull)
tk.MustExec("create table t1(a int not null, b int not null, primary key(a));")
tk.MustGetErrCode("alter table t modify a bigint null;", mysql.ErrPrimaryCantHaveNull)
tk.MustGetErrCode("alter table t change column a a bigint null;", mysql.ErrPrimaryCantHaveNull)
}

// Close issue #23202
func (s *testColumnTypeChangeSuite) TestDDLExitWhenCancelMeetPanic(c *C) {
tk := testkit.NewTestKit(c, s.store)
Expand Down Expand Up @@ -1752,3 +1766,34 @@ func (s *testColumnTypeChangeSuite) TestDDLExitWhenCancelMeetPanic(c *C) {
c.Assert(job.ErrorCount, Equals, int64(4))
c.Assert(job.Error.Error(), Equals, "[ddl:-1]panic in handling DDL logic and error count beyond the limitation 3, cancelled")
}

// Close issue #24253
func (s *testColumnTypeChangeSuite) TestChangeIntToBitWillPanicInBackfillIndexes(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
// Enable column change variable.
tk.Se.GetSessionVars().EnableChangeColumnType = true

tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE `t` (" +
" `a` int(11) DEFAULT NULL," +
" `b` varchar(10) DEFAULT NULL," +
" `c` decimal(10,2) DEFAULT NULL," +
" KEY `idx1` (`a`)," +
" UNIQUE KEY `idx2` (`a`)," +
" KEY `idx3` (`a`,`b`)," +
" KEY `idx4` (`a`,`b`,`c`)" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")
tk.MustExec("insert into t values(19,1,1),(17,2,2)")
tk.MustExec("alter table t modify a bit(5) not null")
tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" +
" `a` bit(5) NOT NULL,\n" +
" `b` varchar(10) DEFAULT NULL,\n" +
" `c` decimal(10,2) DEFAULT NULL,\n" +
" KEY `idx1` (`a`),\n" +
" UNIQUE KEY `idx2` (`a`),\n" +
" KEY `idx3` (`a`,`b`),\n" +
" KEY `idx4` (`a`,`b`,`c`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustQuery("select * from t").Check(testkit.Rows("\x13 1 1.00", "\x11 2 2.00"))
}
20 changes: 20 additions & 0 deletions ddl/db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,26 @@ func (s *testStateChangeSuite) TestParallelAlterModifyColumn(c *C) {
s.testControlParallelExecSQL(c, sql, sql, f)
}

func (s *testStateChangeSuite) TestParallelAddGeneratedColumnAndAlterModifyColumn(c *C) {
_, err := s.se.Execute(context.Background(), "set global tidb_enable_change_column_type = 1")
c.Assert(err, IsNil)
defer func() {
_, err = s.se.Execute(context.Background(), "set global tidb_enable_change_column_type = 0")
c.Assert(err, IsNil)
}()
domain.GetDomain(s.se).GetGlobalVarsCache().Disable()

sql1 := "ALTER TABLE t ADD COLUMN f INT GENERATED ALWAYS AS(a+1);"
sql2 := "ALTER TABLE t MODIFY COLUMN a tinyint;"
f := func(c *C, err1, err2 error) {
c.Assert(err1, IsNil)
c.Assert(err2.Error(), Equals, "[ddl:8200]Unsupported modify column: tidb_enable_change_column_type is true, oldCol is a dependent column 'a' for generated column")
_, err := s.se.Execute(context.Background(), "select * from t")
c.Assert(err, IsNil)
}
s.testControlParallelExecSQL(c, sql1, sql2, f)
}

func (s *testStateChangeSuite) TestParallelAlterModifyColumnAndAddPK(c *C) {
_, err := s.se.Execute(context.Background(), "set global tidb_enable_change_column_type = 1")
c.Assert(err, IsNil)
Expand Down
38 changes: 37 additions & 1 deletion ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/testutil"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
tmysql "github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
Expand Down Expand Up @@ -583,6 +584,12 @@ create table log_message_1 (

tk.MustExec("drop table if exists t;")
tk.MustExec(`create table t(a int) partition by range (a) (partition p0 values less than (18446744073709551615));`)

tk.MustExec("drop table if exists t;")
tk.MustExec(`create table t(a binary) partition by range columns (a) (partition p0 values less than (X'0C'));`)
tk.MustExec(`alter table t add partition (partition p1 values less than (X'0D'), partition p2 values less than (X'0E'));`)
tk.MustExec(`insert into t values (X'0B'), (X'0C'), (X'0D')`)
tk.MustQuery(`select * from t where a < X'0D'`).Check(testkit.Rows("\x0B", "\x0C"))
}

func (s *testIntegrationSuite1) TestDisableTablePartition(c *C) {
Expand Down Expand Up @@ -743,6 +750,7 @@ func (s *testIntegrationSuite1) TestCreateTableWithListPartition(c *C) {
"create table t (a bigint) partition by list (a) (partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')));",
"create table t (a datetime) partition by list (to_seconds(a)) (partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')));",
"create table t (a int, b int generated always as (a+1) virtual) partition by list (b + 1) (partition p0 values in (1));",
"create table t(a binary) partition by list columns (a) (partition p0 values in (X'0C'));",
s.generatePartitionTableByNum(ddl.PartitionCountLimit),
}

Expand Down Expand Up @@ -3334,7 +3342,7 @@ func (s *testIntegrationSuite7) TestAddPartitionForTableWithWrongType(c *C) {

_, 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)
c.Assert(ddl.ErrRangeNotIncreasing.Equal(err), IsTrue)

_, err = tk.Exec("alter table t_char add partition (partition p1 values less than (10))")
c.Assert(err, NotNil)
Expand Down Expand Up @@ -3378,3 +3386,31 @@ func (s *testIntegrationSuite7) TestPartitionListWithNewCollation(c *C) {
str := tk.MustQuery(`desc select * from t11 where a = 'b';`).Rows()[0][3].(string)
c.Assert(strings.Contains(str, "partition:p0"), IsTrue)
}

func (s *testIntegrationSuite7) TestAddTableWithPartition(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists global_partition_table;")
tk.MustGetErrCode("create global temporary table global_partition_table (a int, b int) partition by hash(a) partitions 3 ON COMMIT DELETE ROWS;", errno.ErrPartitionNoTemporary)
tk.MustExec("drop table if exists global_partition_table;")
tk.MustExec("drop table if exists partition_table;")
_, err := tk.Exec("create table partition_table (a int, b int) partition by hash(a) partitions 3;")
c.Assert(err, IsNil)
tk.MustExec("drop table if exists partition_table;")
tk.MustExec("drop table if exists partition_range_table;")
tk.MustGetErrCode(`create global temporary table partition_range_table (c1 smallint(6) not null, c2 char(5) default null) partition by range ( c1 ) (
partition p0 values less than (10),
partition p1 values less than (20),
partition p2 values less than (30),
partition p3 values less than (MAXVALUE)
) ON COMMIT DELETE ROWS;`, errno.ErrPartitionNoTemporary)
tk.MustExec("drop table if exists partition_range_table;")
tk.MustExec("drop table if exists partition_list_table;")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustGetErrCode(`create global temporary table partition_list_table (id int) partition by list (id) (
partition p0 values in (1,2),
partition p1 values in (3,4),
partition p3 values in (5,null)
) ON COMMIT DELETE ROWS;`, errno.ErrPartitionNoTemporary)
tk.MustExec("drop table if exists partition_list_table;")
}
31 changes: 31 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var _ = Suite(&testDBSuite5{&testDBSuite{}})
var _ = Suite(&testDBSuite6{&testDBSuite{}})
var _ = Suite(&testDBSuite7{&testDBSuite{}})
var _ = SerialSuites(&testSerialDBSuite{&testDBSuite{}})
var _ = Suite(&testDBSuite8{&testDBSuite{}})

const defaultBatchSize = 1024
const defaultReorgBatchSize = 256
Expand Down Expand Up @@ -145,6 +146,7 @@ type testDBSuite5 struct{ *testDBSuite }
type testDBSuite6 struct{ *testDBSuite }
type testDBSuite7 struct{ *testDBSuite }
type testSerialDBSuite struct{ *testDBSuite }
type testDBSuite8 struct{ *testDBSuite }

func testAddIndexWithPK(tk *testkit.TestKit) {
tk.MustExec("drop table if exists test_add_index_with_pk")
Expand Down Expand Up @@ -6700,3 +6702,32 @@ func (s *testSerialDBSuite) TestJsonUnmarshalErrWhenPanicInCancellingPath(c *C)
_, err := tk.Exec("alter table test_add_index_after_add_col add unique index cc(c);")
c.Assert(err.Error(), Equals, "[kv:1062]Duplicate entry '0' for key 'cc'")
}

// For Close issue #24288
// see https://github.com/pingcap/tidb/issues/24288
func (s *testDBSuite8) TestDdlMaxLimitOfIdentifier(c *C) {
tk := testkit.NewTestKit(c, s.store)

// create/drop database test
longDbName := strings.Repeat("库", mysql.MaxDatabaseNameLength-1)
tk.MustExec(fmt.Sprintf("create database %s", longDbName))
defer func() {
tk.MustExec(fmt.Sprintf("drop database %s", longDbName))
}()
tk.MustExec(fmt.Sprintf("use %s", longDbName))

// create/drop table,index test
longTblName := strings.Repeat("表", mysql.MaxTableNameLength-1)
longColName := strings.Repeat("三", mysql.MaxColumnNameLength-1)
longIdxName := strings.Repeat("索", mysql.MaxIndexIdentifierLen-1)
tk.MustExec(fmt.Sprintf("create table %s(f1 int primary key,f2 int, %s varchar(50))", longTblName, longColName))
tk.MustExec(fmt.Sprintf("create index %s on %s(%s)", longIdxName, longTblName, longColName))
defer func() {
tk.MustExec(fmt.Sprintf("drop index %s on %s", longIdxName, longTblName))
tk.MustExec(fmt.Sprintf("drop table %s", longTblName))
}()

// alter table
tk.MustExec(fmt.Sprintf("alter table %s change f2 %s int", longTblName, strings.Repeat("二", mysql.MaxColumnNameLength-1)))

}
Loading

0 comments on commit a18f522

Please sign in to comment.