Skip to content

Commit

Permalink
Merge pull request cockroachdb#100956 from Xiang-Gu/backport22.2-100750
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiang-Gu authored Apr 10, 2023
2 parents f4807c1 + 30e5601 commit 71a94e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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 @@ -2839,3 +2839,27 @@ INSERT INTO t_98269 VALUES (0);

statement error pgcode 0A000 .* cluster_logical_timestamp\(\): nil txn in cluster context
ALTER TABLE t_98269 ADD COLUMN j DECIMAL NOT NULL DEFAULT cluster_logical_timestamp();

subtest 99764

statement ok
CREATE TABLE t_99764 (i INT PRIMARY KEY, j INT, UNIQUE (j, CAST(j AS STRING)), FAMILY "primary" (i, j));
set sql_safe_updates = false;

# Dropping `j` should also drop the unique index as well as the expression column.
# Legacy schema change is incapable to do this.
skipif config local-legacy-schema-changer
skipif config local-mixed-22.1-22.2
statement ok
ALTER TABLE t_99764 DROP COLUMN j CASCADE;

skipif config local-legacy-schema-changer
skipif config local-mixed-22.1-22.2
query TT
show create table t_99764
----
t_99764 CREATE TABLE public.t_99764 (
i INT8 NOT NULL,
CONSTRAINT t_99764_pkey PRIMARY KEY (i ASC)
)

Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ func dropColumn(
})
case *scpb.SecondaryIndex:
indexElts := b.QueryByID(e.TableID).Filter(hasIndexIDAttrFilter(e.IndexID))
_, _, indexName := scpb.FindIndexName(indexElts.Filter(publicTargetFilter))
_, indexTargetStatus, indexName := scpb.FindIndexName(indexElts)
if indexTargetStatus == scpb.ToAbsent {
return
}
name := tree.TableIndexName{
Table: *tn,
Index: tree.UnrestrictedName(indexName.Name),
Expand Down

0 comments on commit 71a94e5

Please sign in to comment.