|
| 1 | +# Copyright 2026 PingCAP, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +mysql> DROP DATABASE IF EXISTS test_100; |
| 16 | +mysql> CREATE DATABASE test_100; |
| 17 | +mysql> CREATE TABLE test_100.t1 (a INT, b INT); |
| 18 | +# prepare some rows inserted before column with default value added |
| 19 | +mysql> INSERT INTO test_100.t1 VALUES (1, 2), (2, 3); |
| 20 | +mysql> ALTER TABLE test_100.t1 set tiflash replica 1; |
| 21 | +func> wait_table test_100 t1 |
| 22 | +# add new column with default value and insert some rows |
| 23 | +mysql> ALTER TABLE test_100.t1 ADD COLUMN site_code VARCHAR(64) NOT NULL DEFAULT '100'; |
| 24 | +mysql> INSERT INTO test_100.t1 VALUES (12, 13, '100'); |
| 25 | +# change the default value so that it may share the same structure with another table |
| 26 | +mysql> ALTER TABLE test_100.t1 MODIFY COLUMN site_code VARCHAR(64) NOT NULL DEFAULT ''; |
| 27 | +mysql> ALTER TABLE test_100.t1 ADD PRIMARY KEY (a, site_code); |
| 28 | + |
| 29 | +mysql> DROP DATABASE IF EXISTS test_200; |
| 30 | +mysql> CREATE DATABASE test_200; |
| 31 | +mysql> CREATE TABLE test_200.t1 (a INT, b INT); |
| 32 | +# prepare some rows inserted before column with default value added |
| 33 | +mysql> INSERT INTO test_200.t1 VALUES (1, 2), (2, 3); |
| 34 | +mysql> ALTER TABLE test_200.t1 set tiflash replica 1; |
| 35 | +func> wait_table test_200 t1 |
| 36 | +# add new column with default value and insert some rows |
| 37 | +mysql> ALTER TABLE test_200.t1 ADD COLUMN site_code VARCHAR(64) NOT NULL DEFAULT '200'; |
| 38 | +mysql> INSERT INTO test_200.t1 VALUES (12, 13, '200'); |
| 39 | +# change the default value so that it may share the same structure with test_100.t1 |
| 40 | +mysql> ALTER TABLE test_200.t1 MODIFY COLUMN site_code VARCHAR(64) NOT NULL DEFAULT ''; |
| 41 | +mysql> ALTER TABLE test_200.t1 ADD PRIMARY KEY (a, site_code); |
| 42 | + |
| 43 | +mysql> set session tidb_isolation_read_engines='tiflash'; select * from test_100.t1 order by a; |
| 44 | ++----+----+-----------+ |
| 45 | +| a | b | site_code | |
| 46 | ++----+----+-----------+ |
| 47 | +| 1 | 2 | 100 | |
| 48 | +| 2 | 3 | 100 | |
| 49 | +| 12 | 13 | 100 | |
| 50 | ++----+----+-----------+ |
| 51 | + |
| 52 | +mysql> set session tidb_isolation_read_engines='tiflash'; select * from test_200.t1 order by a; |
| 53 | ++----+----+-----------+ |
| 54 | +| a | b | site_code | |
| 55 | ++----+----+-----------+ |
| 56 | +| 1 | 2 | 200 | |
| 57 | +| 2 | 3 | 200 | |
| 58 | +| 12 | 13 | 200 | |
| 59 | ++----+----+-----------+ |
0 commit comments