forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattributes_sql_test.go
556 lines (487 loc) · 20.4 KB
/
attributes_sql_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ddl_test
import (
"context"
"fmt"
"math"
"testing"
"time"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/store/gcworker"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util/gcutil"
"github.com/stretchr/testify/require"
tikvutil "github.com/tikv/client-go/v2/util"
)
// MockGC is used to make GC work in the test environment.
func MockGC(tk *testkit.TestKit) (string, string, string, func()) {
originGC := util.IsEmulatorGCEnable()
resetGC := func() {
if originGC {
util.EmulatorGCEnable()
} else {
util.EmulatorGCDisable()
}
}
// disable emulator GC.
// Otherwise emulator GC will delete table record as soon as possible after execute drop table ddl.
util.EmulatorGCDisable()
timeBeforeDrop := time.Now().Add(0 - 48*60*60*time.Second).Format(tikvutil.GCTimeFormat)
timeAfterDrop := time.Now().Add(48 * 60 * 60 * time.Second).Format(tikvutil.GCTimeFormat)
safePointSQL := `INSERT HIGH_PRIORITY INTO mysql.tidb VALUES ('tikv_gc_safe_point', '%[1]s', '')
ON DUPLICATE KEY
UPDATE variable_value = '%[1]s'`
// clear GC variables first.
tk.MustExec("delete from mysql.tidb where variable_name in ( 'tikv_gc_safe_point','tikv_gc_enable' )")
return timeBeforeDrop, timeAfterDrop, safePointSQL, resetGC
}
func TestAlterTableAttributes(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table alter_t (c int);`)
// normal cases
tk.MustExec(`alter table alter_t attributes="merge_option=allow";`)
tk.MustExec(`alter table alter_t attributes="merge_option=allow,key=value";`)
// space cases
tk.MustExec(`alter table alter_t attributes=" merge_option=allow ";`)
tk.MustExec(`alter table alter_t attributes=" merge_option = allow , key = value ";`)
// without equal
tk.MustExec(`alter table alter_t attributes " merge_option=allow ";`)
tk.MustExec(`alter table alter_t attributes " merge_option=allow , key=value ";`)
}
func TestAlterTablePartitionAttributes(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table alter_p (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11),
PARTITION p2 VALUES LESS THAN (16),
PARTITION p3 VALUES LESS THAN (21)
);`)
// normal cases
tk.MustExec(`alter table alter_p partition p0 attributes="merge_option=allow";`)
tk.MustExec(`alter table alter_p partition p1 attributes="merge_option=allow,key=value";`)
// space cases
tk.MustExec(`alter table alter_p partition p2 attributes=" merge_option=allow ";`)
tk.MustExec(`alter table alter_p partition p3 attributes=" merge_option = allow , key = value ";`)
// without equal
tk.MustExec(`alter table alter_p partition p1 attributes " merge_option=allow ";`)
tk.MustExec(`alter table alter_p partition p1 attributes " merge_option=allow , key=value ";`)
// reset all
tk.MustExec(`alter table alter_p partition p0 attributes default;`)
tk.MustExec(`alter table alter_p partition p1 attributes default;`)
tk.MustExec(`alter table alter_p partition p2 attributes default;`)
tk.MustExec(`alter table alter_p partition p3 attributes default;`)
// add table level attribute
tk.MustExec(`alter table alter_p attributes="merge_option=deny";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 1)
// add a new partition p4
tk.MustExec(`alter table alter_p add partition (PARTITION p4 VALUES LESS THAN (60));`)
rows1 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows1, 1)
require.NotEqual(t, rows[0][3], rows1[0][3])
// drop the new partition p4
tk.MustExec(`alter table alter_p drop partition p4;`)
rows2 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows2, 1)
require.Equal(t, rows[0][3], rows2[0][3])
// add a new partition p5
tk.MustExec(`alter table alter_p add partition (PARTITION p5 VALUES LESS THAN (80));`)
rows3 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows3, 1)
require.NotEqual(t, rows[0][3], rows3[0][3])
// truncate the new partition p5
tk.MustExec(`alter table alter_p truncate partition p5;`)
rows4 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows4, 1)
require.NotEqual(t, rows3[0][3], rows4[0][3])
require.NotEqual(t, rows[0][3], rows4[0][3])
}
func TestTruncateTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table truncate_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
// add attributes
tk.MustExec(`alter table truncate_t attributes="key=value";`)
tk.MustExec(`alter table truncate_t partition p0 attributes="key1=value1";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
// truncate table
tk.MustExec(`truncate table truncate_t;`)
rows1 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows1, 2)
// check table truncate_t's attribute
require.Equal(t, "schema/test/truncate_t", rows1[0][0])
require.Equal(t, `"key=value"`, rows1[0][2])
require.NotEqual(t, rows[0][3], rows1[0][3])
// check partition p0's attribute
require.Equal(t, "schema/test/truncate_t/p0", rows1[1][0])
require.Equal(t, `"key1=value1"`, rows1[1][2])
require.NotEqual(t, rows[1][3], rows1[1][3])
// test only table
tk.MustExec(`create table truncate_ot (c int);`)
// add attribute
tk.MustExec(`alter table truncate_ot attributes="key=value";`)
rows2 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows2, 3)
// truncate table
tk.MustExec(`truncate table truncate_ot;`)
rows3 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows3, 3)
// check table truncate_ot's attribute
require.Equal(t, "schema/test/truncate_ot", rows3[0][0])
require.Equal(t, `"key=value"`, rows3[0][2])
require.NotEqual(t, rows2[0][3], rows3[0][3])
}
func TestRenameTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table rename_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
// add attributes
tk.MustExec(`alter table rename_t attributes="key=value";`)
tk.MustExec(`alter table rename_t partition p0 attributes="key1=value1";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
// rename table
tk.MustExec(`rename table rename_t to rename_t1;`)
rows1 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows1, 2)
// check table rename_t1's attribute
require.Equal(t, "schema/test/rename_t1", rows1[0][0])
require.Equal(t, `"key=value"`, rows1[0][2])
require.Equal(t, rows[0][3], rows1[0][3])
// check partition p0's attribute
require.Equal(t, "schema/test/rename_t1/p0", rows1[1][0])
require.Equal(t, `"key1=value1"`, rows1[1][2])
require.Equal(t, rows[1][3], rows1[1][3])
// test only table
tk.MustExec(`create table rename_ot (c int);`)
// add attribute
tk.MustExec(`alter table rename_ot attributes="key=value";`)
rows2 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows2, 3)
// rename table
tk.MustExec(`rename table rename_ot to rename_ot1;`)
rows3 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows3, 3)
// check table rename_ot1's attribute
require.Equal(t, "schema/test/rename_ot1", rows3[0][0])
require.Equal(t, `"key=value"`, rows3[0][2])
require.Equal(t, rows2[0][3], rows3[0][3])
}
func TestRecoverTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table recover_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
timeBeforeDrop, _, safePointSQL, resetGC := MockGC(tk)
defer resetGC()
// Set GC safe point
tk.MustExec(fmt.Sprintf(safePointSQL, timeBeforeDrop))
// Set GC enable.
require.NoError(t, gcutil.EnableGC(tk.Session()))
// add attributes
tk.MustExec(`alter table recover_t attributes="key=value";`)
tk.MustExec(`alter table recover_t partition p0 attributes="key1=value1";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
// drop table
tk.MustExec(`drop table recover_t;`)
// recover table
tk.MustExec(`recover table recover_t;`)
rows1 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows1, 2)
// check table recover_t's attribute
require.Equal(t, "schema/test/recover_t", rows1[0][0])
require.Equal(t, `"key=value"`, rows1[0][2])
require.Equal(t, rows[0][3], rows1[0][3])
// check partition p0's attribute
require.Equal(t, "schema/test/recover_t/p0", rows1[1][0])
require.Equal(t, `"key1=value1"`, rows1[1][2])
require.Equal(t, rows[1][3], rows1[1][3])
}
func TestFlashbackTable(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
_, err := infosync.GlobalInfoSyncerInit(context.Background(), dom.DDL().GetID(), dom.ServerID, dom.GetEtcdClient(), true)
require.NoError(t, err)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table flash_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
timeBeforeDrop, _, safePointSQL, resetGC := MockGC(tk)
defer resetGC()
// Set GC safe point
tk.MustExec(fmt.Sprintf(safePointSQL, timeBeforeDrop))
// Set GC enable.
err = gcutil.EnableGC(tk.Session())
require.NoError(t, err)
// add attributes
tk.MustExec(`alter table flash_t attributes="key=value";`)
tk.MustExec(`alter table flash_t partition p0 attributes="key1=value1";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
// drop table
tk.MustExec(`drop table flash_t;`)
// flashback table
tk.MustExec(`flashback table flash_t to flash_t1;`)
rows1 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows1, 2)
// check table flash_t1's attribute
require.Equal(t, "schema/test/flash_t1", rows1[0][0])
require.Equal(t, `"key=value"`, rows1[0][2])
require.Equal(t, rows[0][3], rows1[0][3])
// check partition p0's attribute
require.Equal(t, "schema/test/flash_t1/p0", rows1[1][0])
require.Equal(t, `"key1=value1"`, rows1[1][2])
require.Equal(t, rows[1][3], rows1[1][3])
// truncate table
tk.MustExec(`truncate table flash_t1;`)
// flashback table
tk.MustExec(`flashback table flash_t1 to flash_t2;`)
rows2 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows1, 2)
// check table flash_t2's attribute
require.Equal(t, "schema/test/flash_t2", rows2[0][0])
require.Equal(t, `"key=value"`, rows2[0][2])
require.Equal(t, rows[0][3], rows2[0][3])
// check partition p0's attribute
require.Equal(t, "schema/test/flash_t2/p0", rows2[1][0])
require.Equal(t, `"key1=value1"`, rows2[1][2])
require.Equal(t, rows[1][3], rows2[1][3])
}
func TestDropTable(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
_, err := infosync.GlobalInfoSyncerInit(context.Background(), dom.DDL().GetID(), dom.ServerID, dom.GetEtcdClient(), true)
require.NoError(t, err)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table drop_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
failpoint.Enable("github.com/pingcap/tidb/store/gcworker/ignoreDeleteRangeFailed", `return`)
defer func() {
failpoint.Disable("github.com/pingcap/tidb/store/gcworker/ignoreDeleteRangeFailed")
}()
timeBeforeDrop, _, safePointSQL, resetGC := MockGC(tk)
defer resetGC()
// Set GC safe point
tk.MustExec(fmt.Sprintf(safePointSQL, timeBeforeDrop))
// Set GC enable.
err = gcutil.EnableGC(tk.Session())
require.NoError(t, err)
gcWorker, err := gcworker.NewMockGCWorker(store)
require.NoError(t, err)
// add attributes
tk.MustExec(`alter table drop_t attributes="key=value";`)
tk.MustExec(`alter table drop_t partition p0 attributes="key1=value1";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
// drop table
tk.MustExec(`drop table drop_t;`)
err = gcWorker.DeleteRanges(context.Background(), uint64(math.MaxInt64))
require.NoError(t, err)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 0)
tk.MustExec("use test")
tk.MustExec(`create table drop_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 0)
}
func TestCreateWithSameName(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
_, err := infosync.GlobalInfoSyncerInit(context.Background(), dom.DDL().GetID(), dom.ServerID, dom.GetEtcdClient(), true)
require.NoError(t, err)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table recreate_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
failpoint.Enable("github.com/pingcap/tidb/store/gcworker/ignoreDeleteRangeFailed", `return`)
defer func() {
failpoint.Disable("github.com/pingcap/tidb/store/gcworker/ignoreDeleteRangeFailed")
}()
timeBeforeDrop, _, safePointSQL, resetGC := MockGC(tk)
defer resetGC()
// Set GC safe point
tk.MustExec(fmt.Sprintf(safePointSQL, timeBeforeDrop))
// Set GC enable.
err = gcutil.EnableGC(tk.Session())
require.NoError(t, err)
gcWorker, err := gcworker.NewMockGCWorker(store)
require.NoError(t, err)
// add attributes
tk.MustExec(`alter table recreate_t attributes="key=value";`)
tk.MustExec(`alter table recreate_t partition p0 attributes="key1=value1";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
// drop table
tk.MustExec(`drop table recreate_t;`)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 0)
tk.MustExec(`create table recreate_t (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
// add attributes
tk.MustExec(`alter table recreate_t attributes="key=value";`)
tk.MustExec(`alter table recreate_t partition p1 attributes="key1=value1";`)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
err = gcWorker.DeleteRanges(context.Background(), uint64(math.MaxInt64))
require.NoError(t, err)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 2)
// drop table
tk.MustExec(`drop table recreate_t;`)
err = gcWorker.DeleteRanges(context.Background(), uint64(math.MaxInt64))
require.NoError(t, err)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 0)
}
func TestPartition(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
_, err := infosync.GlobalInfoSyncerInit(context.Background(), dom.DDL().GetID(), dom.ServerID, dom.GetEtcdClient(), true)
require.NoError(t, err)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table part (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11),
PARTITION p2 VALUES LESS THAN (20)
);`)
tk.MustExec(`create table part1 (c int);`)
// add attributes
tk.MustExec(`alter table part attributes="key=value";`)
tk.MustExec(`alter table part partition p0 attributes="key1=value1";`)
tk.MustExec(`alter table part partition p1 attributes="key2=value2";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows, 3)
// drop partition
// partition p0's attribute will be deleted
tk.MustExec(`alter table part drop partition p0;`)
rows1 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows1, 2)
require.Equal(t, "schema/test/part", rows1[0][0])
require.Equal(t, `"key=value"`, rows1[0][2])
// table attribute only contains three ranges now
require.NotEqual(t, rows[0][3], rows1[0][3])
require.Equal(t, "schema/test/part/p1", rows1[1][0])
require.Equal(t, `"key2=value2"`, rows1[1][2])
require.Equal(t, rows[2][3], rows1[1][3])
// truncate partition
// partition p1's key range will be updated
tk.MustExec(`alter table part truncate partition p1;`)
rows2 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows2, 2)
require.Equal(t, "schema/test/part", rows2[0][0])
require.Equal(t, `"key=value"`, rows2[0][2])
require.NotEqual(t, rows1[0][3], rows2[0][3])
require.Equal(t, "schema/test/part/p1", rows2[1][0])
require.Equal(t, `"key2=value2"`, rows2[1][2])
require.NotEqual(t, rows1[1][3], rows2[1][3])
// exchange partition
// partition p1's attribute will be exchanged to table part1
tk.MustExec(`set @@tidb_enable_exchange_partition=1;`)
tk.MustExec(`alter table part exchange partition p1 with table part1;`)
rows3 := tk.MustQuery(`select * from information_schema.attributes;`).Sort().Rows()
require.Len(t, rows3, 2)
require.Equal(t, "schema/test/part", rows3[0][0])
require.Equal(t, `"key=value"`, rows3[0][2])
require.Equal(t, rows2[0][3], rows3[0][3])
require.Equal(t, "schema/test/part1", rows3[1][0])
require.Equal(t, `"key2=value2"`, rows3[1][2])
require.Equal(t, rows2[1][3], rows3[1][3])
}
func TestDropSchema(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
_, err := infosync.GlobalInfoSyncerInit(context.Background(), dom.DDL().GetID(), dom.ServerID, dom.GetEtcdClient(), true)
require.NoError(t, err)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table drop_s1 (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
tk.MustExec(`create table drop_s2 (c int);`)
// add attributes
tk.MustExec(`alter table drop_s1 attributes="key=value";`)
tk.MustExec(`alter table drop_s1 partition p0 attributes="key1=value1";`)
tk.MustExec(`alter table drop_s2 attributes="key=value";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Rows()
require.Len(t, rows, 3)
// drop database
tk.MustExec(`drop database test`)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Rows()
require.Len(t, rows, 0)
}
func TestDefaultKeyword(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
_, err := infosync.GlobalInfoSyncerInit(context.Background(), dom.DDL().GetID(), dom.ServerID, dom.GetEtcdClient(), true)
require.NoError(t, err)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table def (c int)
PARTITION BY RANGE (c) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11)
);`)
// add attributes
tk.MustExec(`alter table def attributes="key=value";`)
tk.MustExec(`alter table def partition p0 attributes="key1=value1";`)
rows := tk.MustQuery(`select * from information_schema.attributes;`).Rows()
require.Len(t, rows, 2)
// reset the partition p0's attribute
tk.MustExec(`alter table def partition p0 attributes=default;`)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Rows()
require.Len(t, rows, 1)
// reset the table def's attribute
tk.MustExec(`alter table def attributes=default;`)
rows = tk.MustQuery(`select * from information_schema.attributes;`).Rows()
require.Len(t, rows, 0)
}