From 8f4ecb6e41aa8641922f018bd50b87f74e9a8a4a Mon Sep 17 00:00:00 2001 From: Peter Mattis Date: Wed, 13 Jun 2018 16:35:44 -0400 Subject: [PATCH 1/2] roachtest: use --sequential when generating store dumps This makes the mapping from cockroach node ID to roachprod node ID the identify function. Release note: None --- pkg/cmd/roachtest/store_gen.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/roachtest/store_gen.go b/pkg/cmd/roachtest/store_gen.go index 2819fb5cf1ca..60e2300ae4f3 100644 --- a/pkg/cmd/roachtest/store_gen.go +++ b/pkg/cmd/roachtest/store_gen.go @@ -65,7 +65,7 @@ func registerStoreGen(r *registry, args []string) { Run: func(ctx context.Context, t *test, c *cluster) { c.Put(ctx, cockroach, "./cockroach") c.Put(ctx, workload, "./workload") - c.Start(ctx) + c.Start(ctx, startArgs("--sequential")) { m := newMonitor(ctx, c) From 12b3ab78c62fb72a35b70b86aaeec361dff43711 Mon Sep 17 00:00:00 2001 From: Bob Vawter Date: Wed, 13 Jun 2018 10:02:46 -0400 Subject: [PATCH 2/2] sql: Fix panic adding unique, non-indexable column This change updates the `checkColumnsFor...Index` functions to use `allNonDropColumns()` to validate against any proposed mutations. Otherwise, a `ColumnMutation` that adds a non-indexable column followed by an `IndexMutation` creating an index on that column would would be incorrectly accepted, leading to a panic. Fixes #26483 Release note (sql change): Return an error to the user instead of panicing when trying to add a column with a unique constraint when that column's type is not indexable. --- .../logictest/testdata/logic_test/alter_table | 24 +++++++++++++++++++ pkg/sql/sqlbase/structured.go | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/alter_table b/pkg/sql/logictest/testdata/logic_test/alter_table index 1aac4d9da5bd..ac6570e114ce 100644 --- a/pkg/sql/logictest/testdata/logic_test/alter_table +++ b/pkg/sql/logictest/testdata/logic_test/alter_table @@ -694,6 +694,30 @@ decomputed_column CREATE TABLE decomputed_column ( FAMILY "primary" (a, b) ) +# Test for https://github.com/cockroachdb/cockroach/issues/26483 +# We try to create a unique column on an un-indexable type. +statement ok +CREATE TABLE b26483() + +statement error unimplemented: column c is of type ARRAY and thus is not indexable +ALTER TABLE b26483 ADD COLUMN c INT[] UNIQUE + +# As above, but performed in a transaction +statement ok +BEGIN + +statement ok +CREATE TABLE b26483_tx() + +statement ok +ALTER TABLE b26483_tx ADD COLUMN c INT[] + +statement error unimplemented: column c is of type ARRAY and thus is not indexable +CREATE INDEX on b26483_tx (c) + +statement ok +ROLLBACK + # Verify that auditing can be enabled by root, and cannot be disabled by non-root. statement ok diff --git a/pkg/sql/sqlbase/structured.go b/pkg/sql/sqlbase/structured.go index 706de777679b..831ba43dd2a7 100644 --- a/pkg/sql/sqlbase/structured.go +++ b/pkg/sql/sqlbase/structured.go @@ -1613,7 +1613,7 @@ func notIndexableError(cols []ColumnDescriptor, inverted bool) error { func checkColumnsValidForIndex(tableDesc *TableDescriptor, indexColNames []string) error { invalidColumns := make([]ColumnDescriptor, 0, len(indexColNames)) for _, indexCol := range indexColNames { - for _, col := range tableDesc.Columns { + for _, col := range tableDesc.allNonDropColumns() { if col.Name == indexCol { if !columnTypeIsIndexable(col.Type) { invalidColumns = append(invalidColumns, col) @@ -1633,7 +1633,7 @@ func checkColumnsValidForInvertedIndex(tableDesc *TableDescriptor, indexColNames } invalidColumns := make([]ColumnDescriptor, 0, len(indexColNames)) for _, indexCol := range indexColNames { - for _, col := range tableDesc.Columns { + for _, col := range tableDesc.allNonDropColumns() { if col.Name == indexCol { if !columnTypeIsInvertedIndexable(col.Type) { invalidColumns = append(invalidColumns, col)