-
Notifications
You must be signed in to change notification settings - Fork 850
refactor(query): optimize alter table modify column default-only path #19424
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
Open
dantengsky
wants to merge
21
commits into
databendlabs:main
Choose a base branch
from
dantengsky:feat/main-branch-alter-col-type-no-write
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+478
−33
Open
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a0f6ea6
fix(query): avoid rewrite for default-only modify column
dantengsky 4d4dd55
fix(query): validate all defaults in modify-column loop
dantengsky 9ec44d6
test(fuse): add stream changes checks for modify default
dantengsky 6761518
test(stream): clarify changes comments and add stream case
dantengsky 9f826d3
test(fuse): remove flaky offset-based changes checks
dantengsky 04b1f9d
test(altertable): align modify-default expected row in 17_0005
dantengsky 2140560
test(altertable): clarify default-only checks in 17_0005
dantengsky 1af2b7d
test(altertable): simplify comments in 17_0005
dantengsky 13f622e
fix(altertable): rebuild for non-deterministic defaults
dantengsky 8f9e57c
fix(altertable): guard change-tracking tables against default-only sc…
dantengsky e98dd04
test(altertable): cover remove-default and empty change-tracking table
dantengsky 252c738
fix(test): nullable column without default fills NULL, not 0
dantengsky 5d67ea9
fix(altertable): allow parquet string-to-binary on change-tracking ta…
dantengsky a1278c6
fix(test): correct remove-default expectations for physically stored …
dantengsky 9356498
fix(altertable): treat AsyncFunctionCall (nextval) as non-determinist…
dantengsky 03eff92
chore: add TODO for ScalarExpr::is_deterministic (issue #19451)
dantengsky 0b91c87
style: cargo fmt
dantengsky b46c130
fix(altertable): skip no-op column specs before setting change-tracki…
dantengsky 6fa6e48
test(altertable): cover nextval default triggers rebuild
dantengsky 8908597
fix(test): remove quotes from nextval sequence name
dantengsky 88b6f29
fix(altertable): detect nextval inside CastExpr for rebuild decision
dantengsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
.../sqllogictests/suites/base/05_ddl/05_0040_ddl_alter_table_modify_column_type_pending.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| # Scenario A: type conversion on existing columns. | ||
| # Scenario B: expected errors for invalid cast / unknown column / invalid default. | ||
| # Scenario C: default evolution after modify/add operations. | ||
| # Scenario D: varchar default and not-null behavior after modify. | ||
|
|
||
| statement ok | ||
| DROP DATABASE IF EXISTS db_05_0040 | ||
|
|
||
| statement ok | ||
| CREATE DATABASE db_05_0040 | ||
|
|
||
| statement ok | ||
| USE db_05_0040 | ||
|
|
||
| # -------------------------- | ||
| # A. Basic type conversion | ||
| # -------------------------- | ||
| statement ok | ||
| CREATE TABLE a(a STRING NOT NULL, b INT NOT NULL, c INT NOT NULL) | ||
|
|
||
| statement ok | ||
| INSERT INTO a VALUES('1', 2, 3) | ||
|
|
||
| statement ok | ||
| ALTER TABLE a MODIFY COLUMN a FLOAT NOT NULL, COLUMN b STRING NOT NULL | ||
|
|
||
| query B | ||
| SELECT count(*) = 1 AND min(a) = 1 AND min(b) = '2' AND min(c) = 3 FROM a | ||
| ---- | ||
| 1 | ||
|
|
||
| query TT | ||
| SELECT name, data_type FROM system.columns WHERE database = 'db_05_0040' AND table = 'a' ORDER BY name | ||
| ---- | ||
| a FLOAT | ||
| b VARCHAR | ||
| c INT | ||
|
|
||
| # ---------------------------------------------- | ||
| # B. Invalid cast / unknown column / bad default | ||
| # ---------------------------------------------- | ||
| statement ok | ||
| CREATE TABLE b(a STRING NOT NULL) | ||
|
|
||
| statement ok | ||
| INSERT INTO b VALUES('a') | ||
|
|
||
| statement error 1006 | ||
| ALTER TABLE b MODIFY COLUMN a FLOAT NOT NULL | ||
|
|
||
| statement error 1058 | ||
| ALTER TABLE b MODIFY COLUMN b FLOAT NOT NULL | ||
|
|
||
| statement ok | ||
| CREATE TABLE c(a INT NOT NULL, b INT NOT NULL) | ||
|
|
||
| statement error 1006 | ||
| INSERT INTO c (b) VALUES(1) | ||
|
|
||
| statement ok | ||
| INSERT INTO c (a, b) VALUES(0, 1) | ||
|
|
||
| statement error 1006 | ||
| ALTER TABLE c MODIFY COLUMN a FLOAT NOT NULL DEFAULT 'a' | ||
|
|
||
| statement ok | ||
| ALTER TABLE c MODIFY COLUMN a FLOAT NOT NULL DEFAULT 1.2 | ||
|
|
||
| statement ok | ||
| CREATE TABLE c_multi(a INT NOT NULL, b INT NOT NULL) | ||
|
|
||
| statement ok | ||
| INSERT INTO c_multi VALUES(1, 1) | ||
|
|
||
| statement error 1006 | ||
| ALTER TABLE c_multi MODIFY COLUMN a FLOAT NOT NULL, COLUMN b FLOAT NOT NULL DEFAULT 'a' | ||
|
|
||
| query TT | ||
| SELECT name, data_type FROM system.columns WHERE database = 'db_05_0040' AND table = 'c_multi' ORDER BY name | ||
| ---- | ||
| a INT | ||
| b INT | ||
|
|
||
| query B | ||
| SELECT count(*) = 1 AND min(a) = 0 AND max(a) = 0 AND sum(b) = 1 FROM c | ||
| ---- | ||
| 1 | ||
|
|
||
| # ---------------------------------------------- | ||
| # C. Default evolution with modify/add operations | ||
| # ---------------------------------------------- | ||
| statement ok | ||
| CREATE TABLE d(a INT NOT NULL, b INT NOT NULL DEFAULT 10) | ||
|
|
||
| statement ok | ||
| INSERT INTO d (a) VALUES(1) | ||
|
|
||
| statement ok | ||
| ALTER TABLE d MODIFY COLUMN b INT NOT NULL DEFAULT 2 | ||
|
|
||
| statement ok | ||
| ALTER TABLE d ADD COLUMN c FLOAT NOT NULL DEFAULT 1.01 | ||
|
|
||
| statement ok | ||
| ALTER TABLE d MODIFY COLUMN c FLOAT NOT NULL DEFAULT 2.2 | ||
|
|
||
| statement ok | ||
| INSERT INTO d (a) VALUES(10) | ||
|
|
||
| query B | ||
| SELECT count(*) = 2 AND sum(b) = 12 AND min(c) > 2.1 AND max(c) < 2.3 FROM d | ||
| ---- | ||
| 1 | ||
|
|
||
| query I | ||
| SELECT count(*) FROM d WHERE a = 10 AND b = 2 AND c = 2.2 | ||
| ---- | ||
| 1 | ||
|
|
||
| # ---------------------------------------------- | ||
| # D. VARCHAR default + NOT NULL behavior | ||
| # ---------------------------------------------- | ||
| statement ok | ||
| CREATE TABLE e(a INT NOT NULL, b INT NOT NULL) | ||
|
|
||
| statement ok | ||
| INSERT INTO e VALUES(1, 1) | ||
|
|
||
| statement ok | ||
| ALTER TABLE e MODIFY COLUMN a VARCHAR(10) NOT NULL DEFAULT 'not' | ||
|
|
||
| # Default expression should be updated after MODIFY COLUMN. | ||
| query T | ||
| SELECT default_expression FROM system.columns WHERE database = 'db_05_0040' AND table = 'e' AND name = 'a' | ||
| ---- | ||
| 'not' | ||
|
|
||
| statement ok | ||
| INSERT INTO e (b) VALUES(2) | ||
|
|
||
| query TI | ||
| SELECT a, b FROM e ORDER BY b | ||
| ---- | ||
| 1 1 | ||
| not 2 | ||
|
|
||
| statement ok | ||
| CREATE TABLE f(a INT NOT NULL, b INT NOT NULL) | ||
|
|
||
| statement ok | ||
| INSERT INTO f VALUES(1, 1) | ||
|
|
||
| statement ok | ||
| ALTER TABLE f MODIFY COLUMN a VARCHAR(10) NOT NULL COMMENT 'new column' | ||
|
|
||
| statement error 1006 | ||
| INSERT INTO f (b) VALUES(2) | ||
|
|
||
| statement ok | ||
| INSERT INTO f (a, b) VALUES('', 2) | ||
|
|
||
| query T | ||
| SELECT comment FROM system.columns WHERE database = 'db_05_0040' AND table = 'f' AND name = 'a' | ||
| ---- | ||
| new column | ||
|
|
||
| statement ok | ||
| DROP DATABASE db_05_0040 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.