Skip to content

Commit f4faa15

Browse files
craig[bot]bobvawterpetermattis
committed
Merge #26684 #26705
26684: sql: Fix panic adding unique, non-indexable column r=bobvawter a=bobvawter 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. 26705: roachtest: use --sequential when generating store dumps r=benesch a=petermattis This makes the mapping from cockroach node ID to roachprod node ID the identify function. Release note: None Co-authored-by: Bob Vawter <bob@cockroachlabs.com> Co-authored-by: Peter Mattis <petermattis@gmail.com>
3 parents 9466628 + 12b3ab7 + 8f4ecb6 commit f4faa15

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

pkg/cmd/roachtest/store_gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func registerStoreGen(r *registry, args []string) {
6565
Run: func(ctx context.Context, t *test, c *cluster) {
6666
c.Put(ctx, cockroach, "./cockroach")
6767
c.Put(ctx, workload, "./workload")
68-
c.Start(ctx)
68+
c.Start(ctx, startArgs("--sequential"))
6969

7070
{
7171
m := newMonitor(ctx, c)

pkg/sql/logictest/testdata/logic_test/alter_table

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,30 @@ decomputed_column CREATE TABLE decomputed_column (
694694
FAMILY "primary" (a, b)
695695
)
696696

697+
# Test for https://github.com/cockroachdb/cockroach/issues/26483
698+
# We try to create a unique column on an un-indexable type.
699+
statement ok
700+
CREATE TABLE b26483()
701+
702+
statement error unimplemented: column c is of type ARRAY and thus is not indexable
703+
ALTER TABLE b26483 ADD COLUMN c INT[] UNIQUE
704+
705+
# As above, but performed in a transaction
706+
statement ok
707+
BEGIN
708+
709+
statement ok
710+
CREATE TABLE b26483_tx()
711+
712+
statement ok
713+
ALTER TABLE b26483_tx ADD COLUMN c INT[]
714+
715+
statement error unimplemented: column c is of type ARRAY and thus is not indexable
716+
CREATE INDEX on b26483_tx (c)
717+
718+
statement ok
719+
ROLLBACK
720+
697721
# Verify that auditing can be enabled by root, and cannot be disabled by non-root.
698722

699723
statement ok

pkg/sql/sqlbase/structured.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ func notIndexableError(cols []ColumnDescriptor, inverted bool) error {
16131613
func checkColumnsValidForIndex(tableDesc *TableDescriptor, indexColNames []string) error {
16141614
invalidColumns := make([]ColumnDescriptor, 0, len(indexColNames))
16151615
for _, indexCol := range indexColNames {
1616-
for _, col := range tableDesc.Columns {
1616+
for _, col := range tableDesc.allNonDropColumns() {
16171617
if col.Name == indexCol {
16181618
if !columnTypeIsIndexable(col.Type) {
16191619
invalidColumns = append(invalidColumns, col)
@@ -1633,7 +1633,7 @@ func checkColumnsValidForInvertedIndex(tableDesc *TableDescriptor, indexColNames
16331633
}
16341634
invalidColumns := make([]ColumnDescriptor, 0, len(indexColNames))
16351635
for _, indexCol := range indexColNames {
1636-
for _, col := range tableDesc.Columns {
1636+
for _, col := range tableDesc.allNonDropColumns() {
16371637
if col.Name == indexCol {
16381638
if !columnTypeIsInvertedIndexable(col.Type) {
16391639
invalidColumns = append(invalidColumns, col)

0 commit comments

Comments
 (0)