Skip to content

Commit

Permalink
Merge pull request #49088 from rohany/backport20.1-49081
Browse files Browse the repository at this point in the history
release-20.1: sql: fix bug where columns couldn't be dropped after a pk change
  • Loading branch information
rohany authored May 14, 2020
2 parents 396101b + b9e7ff5 commit 249fb32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/alter_primary_key
Original file line number Diff line number Diff line change
Expand Up @@ -1130,3 +1130,11 @@ SELECT index_id, index_name FROM crdb_internal.table_indexes WHERE descriptor_na
6 i1
7 i2
8 i3

# Regression for #49079.
statement ok
DROP TABLE t;
CREATE TABLE t (x INT, y INT, z INT, PRIMARY KEY (x, y));
ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (y);
SET sql_safe_updates=false;
ALTER TABLE t DROP COLUMN z
3 changes: 3 additions & 0 deletions pkg/sql/sqlbase/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -3076,6 +3076,9 @@ func (desc *MutableTableDescriptor) MakeMutationComplete(m DescriptorMutation) e
}
newIndex.Name = "primary"
desc.PrimaryIndex = *protoutil.Clone(newIndex).(*IndexDescriptor)
// The primary index "implicitly" stores all columns in the table.
// Explicitly including them in the stored columns list is incorrect.
desc.PrimaryIndex.StoreColumnNames, desc.PrimaryIndex.StoreColumnIDs = nil, nil
idx, err := getIndexIdxByID(newIndex.ID)
if err != nil {
return err
Expand Down

0 comments on commit 249fb32

Please sign in to comment.