Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport 2.0: sql: Fix panic adding unique, non-indexable column #26728

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -704,6 +704,30 @@ bar
baz
foo

# 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