(t *testing.T, tp testAddIndexType, createTableSQL, idxTp string)
| 174 | ) |
| 175 | |
| 176 | func testAddIndex(t *testing.T, tp testAddIndexType, createTableSQL, idxTp string) { |
| 177 | isTestShardRowID := (testShardRowID & tp) > 0 |
| 178 | // we wrap type on store to implement WithDDLChecker, but shard row ID test will fail at checking the type of store |
| 179 | // sp, ok := d.store.(kv.SplittableStore) |
| 180 | // since hard row ID is not in the use case of SchemaTracker(WithDDLChecker) by design, we disable it |
| 181 | var opts []mockstore.MockTiKVStoreOption |
| 182 | if !isTestShardRowID { |
| 183 | opts = append(opts, mockstore.WithDDLChecker()) |
| 184 | } |
| 185 | |
| 186 | store := testkit.CreateMockStoreWithSchemaLease(t, indexModifyLease, opts...) |
| 187 | |
| 188 | tk := testkit.NewTestKit(t, store) |
| 189 | tk.MustExec("use test") |
| 190 | isTestPartition := (testPartition & tp) > 0 |
| 191 | if isTestShardRowID { |
| 192 | atomic.StoreUint32(&ddl.EnableSplitTableRegion, 1) |
| 193 | tk.MustExec("set global tidb_scatter_region = 'table'") |
| 194 | defer func() { |
| 195 | atomic.StoreUint32(&ddl.EnableSplitTableRegion, 0) |
| 196 | tk.MustExec("set global tidb_scatter_region = ''") |
| 197 | }() |
| 198 | } |
| 199 | if (testClusteredIndex & tp) > 0 { |
| 200 | tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn |
| 201 | } |
| 202 | tk.MustExec("drop table if exists test_add_index") |
| 203 | tk.MustExec(createTableSQL) |
| 204 | |
| 205 | done := make(chan error, 1) |
| 206 | start := -10 |
| 207 | num := defaultBatchSize |
| 208 | // first add some rows |
| 209 | batchInsert(tk, "test_add_index", start, num) |
| 210 | |
| 211 | // Add some discrete rows. |
| 212 | maxBatch := 20 |
| 213 | batchCnt := 100 |
| 214 | otherKeys := make([]int, 0, batchCnt*maxBatch) |
| 215 | // Make sure there are no duplicate keys. |
| 216 | base := defaultBatchSize * 20 |
| 217 | for i := 1; i < batchCnt; i++ { |
| 218 | if isTestShardRowID { |
| 219 | base = i % 4 << 61 |
| 220 | } |
| 221 | n := base + i*defaultBatchSize + i |
| 222 | for j := 0; j < rand.Intn(maxBatch); j++ { |
| 223 | n += j |
| 224 | sql := fmt.Sprintf("insert into test_add_index values (%d, %d, %d)", n, n, n) |
| 225 | tk.MustExec(sql) |
| 226 | otherKeys = append(otherKeys, n) |
| 227 | } |
| 228 | } |
| 229 | // Encounter the value of math.MaxInt64 in middle of |
| 230 | v := math.MaxInt64 - defaultBatchSize/2 |
| 231 | tk.MustExec(fmt.Sprintf("insert into test_add_index values (%d, %d, %d)", v, v, v)) |
| 232 | otherKeys = append(otherKeys, v) |
| 233 |
no test coverage detected