Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 cockroachdb#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 <[email protected]>
Co-authored-by: Peter Mattis <[email protected]>
  • Loading branch information
3 people committed Jun 14, 2018
3 parents 9466628 + 12b3ab7 + 8f4ecb6 commit f4faa15
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/store_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/alter_table
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/sqlbase/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit f4faa15

Please sign in to comment.