Skip to content

Commit daaa36f

Browse files
committed
randgen: use hidden rowid column in columnFamilyMutator
This commit extends the column family mutator to work in the special (but somewhat common) case when the table has a single column that is not the primary key. When the user doesn't specify a primary key, CREATE TABLE adds a hidden 'rowid' column to use as the primary key. We now use this column in addition to the explicitly defined column to exercise randomized column families. In particular, this would have caught the CIText bug with multiple column families from a couple weeks ago. Additionally, this commit extends the logic test framework to support `statement disable-cf-mutator ok` variant which disables the CF mutator if applicable (it's applied only to CREATE TABLE stmts). Previously, the only way to disable the mutator was to explicitly include column family definitions, and `disable-cf-mutator` seems nicer. This new option is used in many places to make the output of SHOW CREATE TABLE deterministic. An attempt is made to minimize the test churn while also disabling the CF mutator in reduced scopes. Release note: None
1 parent d80409c commit daaa36f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+208
-101
lines changed

pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ TABLE regional_by_table_no_region ALTER TABLE regional_by_table_no_region CONFI
995995
statement ok
996996
DROP TABLE regional_by_table_no_region
997997

998-
statement ok
998+
statement disable-cf-mutator ok
999999
CREATE TABLE regional_by_table_no_region (i int)
10001000

10011001
statement ok

pkg/ccl/logictestccl/testdata/logic_test/multi_region

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ CREATE TABLE partition_by_table_in_mr_database (
386386
)
387387
LOCALITY REGIONAL BY TABLE
388388

389-
statement ok
389+
statement disable-cf-mutator ok
390390
CREATE TABLE regional_primary_region_table (a int) LOCALITY REGIONAL BY TABLE IN PRIMARY REGION
391391

392392
query T
@@ -421,7 +421,7 @@ CREATE INDEX bad_idx ON regional_primary_region_table(a) PARTITION BY LIST (a) (
421421
PARTITION one VALUES IN (1)
422422
)
423423

424-
statement ok
424+
statement disable-cf-mutator ok
425425
CREATE TABLE regional_implicit_primary_region_table (a int) LOCALITY REGIONAL BY TABLE
426426

427427
query T
@@ -446,7 +446,7 @@ TABLE regional_implicit_primary_region_table ALTER TABLE regional_implicit_prim
446446
voter_constraints = '{+region=ca-central-1: 2}',
447447
lease_preferences = '[[+region=ca-central-1]]'
448448

449-
statement ok
449+
statement disable-cf-mutator ok
450450
CREATE TABLE "regional_us-east-1_table" (a int) LOCALITY REGIONAL BY TABLE IN "us-east-1"
451451

452452
query T
@@ -474,7 +474,7 @@ TABLE "regional_us-east-1_table" ALTER TABLE "regional_us-east-1_table" CONFIGU
474474
statement error region "test4" has not been added to database "multi_region_test_db"\nHINT: available regions: ap-southeast-2, ca-central-1, us-east-1
475475
CREATE TABLE regional_test4_table (a int) LOCALITY REGIONAL BY TABLE IN "test4"
476476

477-
statement ok
477+
statement disable-cf-mutator ok
478478
CREATE TABLE global_table (a int) LOCALITY GLOBAL
479479

480480
query T
@@ -1046,6 +1046,8 @@ ALTER DATABASE no_initial_region SET PRIMARY REGION "us-east-1"
10461046

10471047
statement ok
10481048
DROP TABLE idx_with_partition_by;
1049+
1050+
statement disable-cf-mutator ok
10491051
CREATE TABLE no_initial_region.t(k INT)
10501052

10511053
statement ok

pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ CREATE DATABASE non_mr_backup;
11861186
statement ok
11871187
USE non_mr_backup
11881188

1189-
statement ok
1189+
statement disable-cf-mutator ok
11901190
CREATE TABLE non_mr_table (i int)
11911191

11921192
# For comparing the zone configurations before restore.

pkg/sql/logictest/logic.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ import (
227227
// statement ok
228228
// CREATE TABLE kv (k INT PRIMARY KEY, v INT)
229229
//
230+
// - statement disable-cf-mutator ok
231+
// Like "statement ok" but disables the column family mutator if applicable.
232+
//
230233
// - statement notice <regexp>
231234
// Like "statement ok" but expects a notice that matches the given regexp.
232235
//
@@ -2732,6 +2735,7 @@ func (t *logicTest) processSubtest(
27322735
fields = fields[:len(fields)-2]
27332736
}
27342737
fullyConsumed := len(fields) == 1
2738+
var disableCFMutator bool
27352739
// Parse "statement (notice|error) <regexp>"
27362740
if m := noticeRE.FindStringSubmatch(s.Text()); m != nil {
27372741
stmt.expectNotice = m[1]
@@ -2740,6 +2744,9 @@ func (t *logicTest) processSubtest(
27402744
stmt.expectErrCode = m[1]
27412745
stmt.expectErr = m[2]
27422746
fullyConsumed = true
2747+
} else if len(fields) == 3 && fields[1] == "disable-cf-mutator" && fields[2] == "ok" {
2748+
disableCFMutator = true
2749+
fullyConsumed = true
27432750
} else if len(fields) == 2 && fields[1] == "ok" {
27442751
// Match 'ok' only if there are no options after it.
27452752
fullyConsumed = true
@@ -2758,11 +2765,11 @@ func (t *logicTest) processSubtest(
27582765
err = testutils.SucceedsWithinError(func() error {
27592766
t.purgeZoneConfig()
27602767
var tempErr error
2761-
cont, tempErr = t.execStatement(stmt)
2768+
cont, tempErr = t.execStatement(stmt, disableCFMutator)
27622769
return tempErr
27632770
}, t.retryDuration)
27642771
} else {
2765-
cont, err = t.execStatement(stmt)
2772+
cont, err = t.execStatement(stmt, disableCFMutator)
27662773
}
27672774
if err != nil {
27682775
if !cont {
@@ -3594,7 +3601,7 @@ func (t *logicTest) unexpectedError(sql string, pos string, err error) (bool, er
35943601

35953602
var uniqueHashPattern = regexp.MustCompile(`UNIQUE.*USING\s+HASH`)
35963603

3597-
func (t *logicTest) execStatement(stmt logicStatement) (bool, error) {
3604+
func (t *logicTest) execStatement(stmt logicStatement, disableCFMutator bool) (bool, error) {
35983605
db := t.db
35993606
t.noticeBuffer = nil
36003607
if *showSQL {
@@ -3606,7 +3613,7 @@ func (t *logicTest) execStatement(stmt logicStatement) (bool, error) {
36063613
// reserialized with a UNIQUE constraint, not a UNIQUE INDEX, which may not
36073614
// be parsable because constraints do not support all the options that
36083615
// indexes do.
3609-
if !uniqueHashPattern.MatchString(stmt.sql) {
3616+
if !uniqueHashPattern.MatchString(stmt.sql) && !disableCFMutator {
36103617
var changed bool
36113618
execSQL, changed = randgen.ApplyString(t.rng, execSQL, randgen.ColumnFamilyMutator)
36123619
if changed {

pkg/sql/logictest/testdata/logic_test/alter_column_type

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ statement error default for column "x" cannot be cast automatically to type DATE
329329
ALTER TABLE t7 ALTER COLUMN x TYPE DATE USING x::DATE;
330330

331331
# Ensure a runtime error correctly rolls back and the table is unchanged.
332-
statement ok
332+
statement disable-cf-mutator ok
333333
CREATE TABLE t8 (x STRING)
334334

335335
statement ok
@@ -560,7 +560,7 @@ true
560560
true
561561

562562
# Ensure ALTER COLUMN TYPE rolls back if is not applicable to value in the column.
563-
statement ok
563+
statement disable-cf-mutator ok
564564
CREATE TABLE t24 (x STRING);
565565

566566
statement ok
@@ -1890,7 +1890,7 @@ SELECT value FROM information_schema.session_variables where variable='use_decla
18901890
statement ok
18911891
set use_declarative_schema_changer = 'unsafe_always';
18921892

1893-
statement ok
1893+
statement disable-cf-mutator ok
18941894
create table t_droppedcol (dropme int);
18951895

18961896
statement ok

pkg/sql/logictest/testdata/logic_test/alter_primary_key

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ ALTER TABLE t ADD PRIMARY KEY (x)
707707
statement ok
708708
DROP TABLE IF EXISTS t;
709709

710-
statement ok
710+
statement disable-cf-mutator ok
711711
CREATE TABLE t (x INT NOT NULL)
712712

713713
statement ok
@@ -736,7 +736,7 @@ t CREATE TABLE public.t (
736736
statement ok
737737
DROP TABLE IF EXISTS t;
738738

739-
statement ok
739+
statement disable-cf-mutator ok
740740
CREATE TABLE t (x INT NOT NULL);
741741

742742
statement ok
@@ -766,7 +766,7 @@ t CREATE TABLE public.t (
766766
statement ok
767767
DROP TABLE IF EXISTS t;
768768

769-
statement ok
769+
statement disable-cf-mutator ok
770770
CREATE TABLE t (x INT NOT NULL);
771771

772772
statement ok

pkg/sql/logictest/testdata/logic_test/alter_table

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,8 @@ subtest add_col_references
12661266
statement ok
12671267
DROP TABLE IF EXISTS t1, t2;
12681268
CREATE TABLE t1 (x INT PRIMARY KEY);
1269+
1270+
statement disable-cf-mutator ok
12691271
CREATE TABLE t2 (y INT)
12701272

12711273
statement ok
@@ -1307,7 +1309,7 @@ t2 CREATE TABLE public.t2 (
13071309

13081310
# Test that only one index gets created when adding a column
13091311
# with references and unique.
1310-
statement ok
1312+
statement disable-cf-mutator ok
13111313
CREATE TABLE t3 (y INT)
13121314

13131315
statement ok
@@ -1411,7 +1413,7 @@ DROP TABLE t1, t2 CASCADE
14111413
statement ok
14121414
SET create_table_with_schema_locked=false
14131415

1414-
statement ok
1416+
statement disable-cf-mutator ok
14151417
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
14161418
SET LOCAL autocommit_before_ddl = false;
14171419
CREATE TABLE t1 (x INT PRIMARY KEY);
@@ -1434,7 +1436,7 @@ t2 CREATE TABLE public.t2 (
14341436
statement ok
14351437
DROP TABLE t1, t2 CASCADE
14361438

1437-
statement ok
1439+
statement disable-cf-mutator ok
14381440
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
14391441
SET LOCAL autocommit_before_ddl = false;
14401442
CREATE TABLE t1 (x INT PRIMARY KEY);
@@ -1458,7 +1460,7 @@ t2 CREATE TABLE public.t2 (
14581460
statement ok
14591461
DROP TABLE t1, t2 CASCADE
14601462

1461-
statement ok
1463+
statement disable-cf-mutator ok
14621464
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
14631465
SET LOCAL autocommit_before_ddl = false;
14641466
CREATE TABLE t1 (x INT PRIMARY KEY);
@@ -1489,6 +1491,8 @@ DROP TABLE t1, t2 CASCADE;
14891491

14901492
statement ok
14911493
CREATE TABLE t1 (x INT PRIMARY KEY);
1494+
1495+
statement disable-cf-mutator ok
14921496
CREATE TABLE t2 (y INT)
14931497

14941498
statement ok
@@ -1517,6 +1521,8 @@ DROP TABLE t1, t2 CASCADE;
15171521

15181522
statement ok
15191523
CREATE TABLE t1 (x INT PRIMARY KEY);
1524+
1525+
statement disable-cf-mutator ok
15201526
CREATE TABLE t2 (x INT)
15211527

15221528
statement ok
@@ -1544,7 +1550,11 @@ DROP TABLE t1, t2 CASCADE
15441550
statement ok
15451551
CREATE TABLE t1 (x INT PRIMARY KEY);
15461552
INSERT INTO t1 VALUES (1);
1553+
1554+
statement disable-cf-mutator ok
15471555
CREATE TABLE t2 (y INT);
1556+
1557+
statement ok
15481558
INSERT INTO t2 VALUES (2)
15491559

15501560
statement error pq: foreign key violation
@@ -2210,7 +2220,7 @@ subtest generated_as_identity
22102220
statement ok
22112221
DROP TABLE IF EXISTS t;
22122222

2213-
statement ok
2223+
statement disable-cf-mutator ok
22142224
CREATE TABLE t (a INT UNIQUE)
22152225

22162226
statement ok
@@ -2368,7 +2378,7 @@ ALTER TABLE t ALTER COLUMN b TYPE numeric(10,2)
23682378
statement ok
23692379
DROP TABLE IF EXISTS t;
23702380

2371-
statement ok
2381+
statement disable-cf-mutator ok
23722382
CREATE TABLE t (a INT UNIQUE)
23732383

23742384
statement ok
@@ -2438,7 +2448,7 @@ ALTER TABLE t ALTER COLUMN b TYPE numeric(10,2)
24382448
statement ok
24392449
DROP TABLE IF EXISTS t;
24402450

2441-
statement ok
2451+
statement disable-cf-mutator ok
24422452
CREATE TABLE t (id INT NOT NULL)
24432453

24442454
statement ok
@@ -2876,7 +2886,7 @@ RESET create_table_with_schema_locked
28762886

28772887
subtest table_settings
28782888

2879-
statement ok
2889+
statement disable-cf-mutator ok
28802890
CREATE TABLE t5 (a int)
28812891

28822892
# Turn on automatic stats collection
@@ -4738,7 +4748,7 @@ skipif config local-legacy-schema-changer
47384748
statement ok
47394749
set use_declarative_schema_changer = 'unsafe_always';
47404750

4741-
statement ok
4751+
statement disable-cf-mutator ok
47424752
create table t_droppedcol (dropme int);
47434753

47444754
statement ok
@@ -4827,7 +4837,7 @@ subtest end
48274837

48284838
subtest serial_columns
48294839

4830-
statement ok
4840+
statement disable-cf-mutator ok
48314841
create table t1_serial_columns(n int);
48324842

48334843
statement ok
@@ -5148,7 +5158,7 @@ subtest end
51485158
# not break as seen in #128420
51495159
subtest add_unique_and_alter_primary_key
51505160

5151-
statement ok
5161+
statement disable-cf-mutator ok
51525162
CREATE TABLE t_128420 (i int not null);
51535163

51545164
# Not supported in mixed version configurations

pkg/sql/logictest/testdata/logic_test/array

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ query T
477477
SELECT ARRAY[ROW()] FROM ident
478478
----
479479

480-
statement ok
480+
statement disable-cf-mutator ok
481481
CREATE TABLE a (b INT ARRAY)
482482

483483
onlyif config schema-locked-disabled
@@ -505,7 +505,7 @@ DROP TABLE a
505505

506506
# Int array columns.
507507

508-
statement ok
508+
statement disable-cf-mutator ok
509509
CREATE TABLE a (b INT[])
510510

511511
statement ok
@@ -631,7 +631,7 @@ DROP TABLE a
631631

632632
# Ensure that additional type info stays when used as an array.
633633

634-
statement ok
634+
statement disable-cf-mutator ok
635635
CREATE TABLE a (b SMALLINT[])
636636

637637
onlyif config schema-locked-disabled

pkg/sql/logictest/testdata/logic_test/bit

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ FROM bits x, bits y
191191

192192
subtest bit_ordering
193193

194-
statement ok
194+
statement disable-cf-mutator ok
195195
CREATE TABLE obits(x VARBIT);
196-
INSERT INTO obits(x) VALUES
196+
197+
statement ok
198+
INSERT INTO obits(x) VALUES
197199
(B'0'),
198200
(B'1'),
199201
(B'0000'),
@@ -258,9 +260,11 @@ SELECT ARRAY[B'101011'] AS a, '{111001}'::VARBIT[] AS b
258260
a b
259261
{101011} {111001}
260262

261-
statement ok
263+
statement disable-cf-mutator ok
262264
CREATE TABLE obitsa(x VARBIT(20)[]);
263-
INSERT INTO obitsa(x) VALUES
265+
266+
statement ok
267+
INSERT INTO obitsa(x) VALUES
264268
(ARRAY[B'01', B'']),
265269
(ARRAY[B'01', B'0']),
266270
(ARRAY[B'01', B'1']),

pkg/sql/logictest/testdata/logic_test/builtin_function

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# tenant-capability-override-opt: can_check_consistency=true
22

3-
statement ok
3+
statement disable-cf-mutator ok
44
CREATE TABLE foo (a int)
55

66
statement ok

0 commit comments

Comments
 (0)