[v1.5] Quickfix `ALTER TABLE ADD COLUMN IF NOT EXISTS ... DEFAULT` regression by yan-alex · Pull Request #23507 · duckdb/duckdb · GitHub
Skip to content

[v1.5] Quickfix ALTER TABLE ADD COLUMN IF NOT EXISTS ... DEFAULT regression - #23507

Merged
lnkuiper merged 2 commits into
duckdb:v1.5-variegatafrom
yan-alex:avoid-rewrite-regression
Jul 3, 2026
Merged

lnkuiper merged 2 commits into
duckdb:v1.5-variegatafrom
yan-alex:avoid-rewrite-regression

Conversation

@yan-alex

Copy link
Copy Markdown
Contributor

https://github.com/duckdblabs/duckdb-internal/issues/9721

The problem

When ADD COLUMN IF NOT EXISTS targets a column that already exists and the clause carries a DEFAULT, DuckDB 1.5.x does not treat the statement as a no-op: it re-applies the default expression to every existing row, silently destroying the column's current data.

The fix

Don't do the 3 multi-statement rewrite workaround from #20224 when there is a IF NOT EXISTS
This is just a v1.5-variegata quickfix. We can tackle this properly later on for v2.0.

@yan-alex
yan-alex force-pushed the avoid-rewrite-regression branch from 4d550ae to 4c67acf Compare June 29, 2026 11:23
@lnkuiper
lnkuiper marked this pull request as draft June 30, 2026 11:46
@lnkuiper
lnkuiper marked this pull request as ready for review June 30, 2026 11:46

@lnkuiper lnkuiper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The materializing multi-statement rewrite is now skipped, which fixes the linked issue, but regresses a WAL replay consistency. Repro:

# name: test/temp.test
# group: [temp]

statement ok
ATTACH '__TEST_DIR__/wal_replay_if_not_exists.db';

statement ok
USE wal_replay_if_not_exists;

statement ok
PRAGMA disable_checkpoint_on_shutdown;

statement ok
SET wal_autocheckpoint='1TB'

statement ok
CREATE TABLE t AS SELECT range::INT AS id FROM range(10);

statement ok
ALTER TABLE t ADD COLUMN IF NOT EXISTS r DOUBLE DEFAULT RANDOM();

statement ok
CREATE TABLE original AS SELECT id, r FROM t;

statement ok
USE memory;

statement ok
DETACH wal_replay_if_not_exists;

statement ok
ATTACH '__TEST_DIR__/wal_replay_if_not_exists.db';

statement ok
USE wal_replay_if_not_exists;

query I
SELECT COUNT(r) != 0 FROM t;
----
true

query I sort r1
SELECT r FROM t;
----

query I sort r1
SELECT r FROM original;
----

@lnkuiper

Copy link
Copy Markdown
Member

@yan-alex

yan-alex commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Is this PR #23522 related?

Yes it addresses the same problem. That one targets main though, which we want to tackle differently I believe.

@yan-alex

Copy link
Copy Markdown
Contributor Author

@lnkuiper lnkuiper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue that this fixes is more important than the issue it creates so we should merge it as-is, and come up with a proper solution for v2.0.0

@lnkuiper
lnkuiper merged commit 2707468 into duckdb:v1.5-variegata Jul 3, 2026
114 checks passed
kaka11chen pushed a commit to kaka11chen/astrovela_vane that referenced this pull request Aug 14, 2026
…gression (duckdb/duckdb#23507)

https://github.com/duckdblabs/duckdb-internal/issues/9721
## The problem
When ADD COLUMN IF NOT EXISTS targets a column that already exists and
the clause carries a DEFAULT, DuckDB 1.5.x does not treat the statement
as a no-op: it re-applies the default expression to every existing row,
silently destroying the column's current data.
## The fix
Don't do the 3 multi-statement rewrite workaround from
duckdb/duckdb#20224 when there is a `IF NOT
EXISTS`
This is just a v1.5-variegata quickfix. We can tackle this properly
later on for v2.0.

Upstream-Commit: duckdb/duckdb@2707468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants