Skip to content

Commit ba5cac7

Browse files
committed
sql/sem/tree: fix width handling for BIT column default values
Previously, when a column was being added or dropped and had NOT NULL with no default value, the parseComputedExpr logic would generate a placeholder value to avoid NULL violations (see #46285 for historical context). For columns of type BIT(n), this fallback value was incorrectly set as BIT(0), which has a width mismatch and caused errors during row insertions or deletions. This change ensures that the fallback value matches the column's specified BIT(n) width, allowing operations to proceed without errors during schema changes involving such columns. Fixes #152326 Release note (bug fix): Fixed a bug where INSERTs could fail with a type checking error while adding a BIT(n) column. Epic: None
1 parent a1fb735 commit ba5cac7

16 files changed

+1525
-2
lines changed

pkg/ccl/schemachangerccl/backup_base_generated_test.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/schemachanger/sctest_generated_test.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
setup
2+
CREATE TABLE bittab (c1 INT);
3+
----
4+
5+
# Insert is blocked prior to setting the NULL attribute on the column due to a
6+
# temporary constraint.
7+
stage-exec phase=PostCommitPhase stage=4
8+
INSERT INTO bittab(c1) VALUES (1);
9+
----
10+
pq: failed to satisfy CHECK constraint .*
11+
12+
# At this stage, the NULL attribute is now added to the column and temp
13+
# constraint is dropped. We allow the INSERT. A suitable value for the new
14+
# column is selected in tree.NewDefaultDatum.
15+
stage-exec phase=PostCommitPhase stage=5
16+
INSERT INTO bittab(c1) VALUES (1);
17+
----
18+
19+
stage-query phase=PostCommitPhase stage=6
20+
SELECT count(*) FROM bittab
21+
----
22+
1
23+
24+
# Confirm that we can delete the new column value.
25+
stage-exec phase=PostCommitPhase stage=7
26+
DELETE FROM bittab
27+
----
28+
29+
test
30+
ALTER TABLE bittab ADD COLUMN vb VARBIT(25) NOT NULL UNIQUE, ADD COLUMN fb BIT(25) NOT NULL
31+
----

0 commit comments

Comments
 (0)