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

sql/schemachanger: dropping a column after add in the same transaction fails #136403

Open
spilchen opened this issue Nov 29, 2024 · 1 comment
Open
Assignees
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@spilchen
Copy link
Contributor

spilchen commented Nov 29, 2024

Describe the problem

The declarative schema changer fails to build a proper plan when adding and dropping columns in separate statements within the same transaction.

To Reproduce

CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY, c2 TEXT NOT NULL, drop DATE, FAMILY F1 (c1, c2, drop));
set use_declarative_schema_changer = 'unsafe_always';
begin;
ALTER TABLE t1 ADD COLUMN c3 TEXT DEFAULT '<default>';
ALTER TABLE t1 DROP COLUMN drop;
commit;

The drop column statement fails with this error:

ERROR: error executing StatementPhase stage 1 of 1 with 3 MutationType ops: relation "t1" (112): index "crdb_internal_index_2_name_placeholder" contains stored column "" with unknown ID 0
DETAIL: • Schema change plan for ALTER TABLE ‹movr›.public.‹t1› DROP COLUMN ‹drop›; following ALTER TABLE ‹movr›.public.‹t1› ADD COLUMN ‹c3› STRING DEFAULT ‹'<default>'›;

Observations:

  • Reversing the order (DROP first, then ADD) or combining both actions in a single statement avoids the issue.

Environment:

  • CockroachDB version: master branch 5d084bd

Jira issue: CRDB-45021

@spilchen spilchen added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-schema-changes T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Nov 29, 2024
@spilchen spilchen self-assigned this Nov 29, 2024
Copy link

blathers-crl bot commented Nov 29, 2024

Hi @spilchen, please add branch-* labels to identify which branch(es) this C-bug affects.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

No branches or pull requests

1 participant