-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
MDEV-29919: Support INSERT ... AS alias ON DUPLICATE KEY UPDATE #4544
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # | ||
| # MDEV-29919: Support INSERT ... VALUES AS alias ON DUPLICATE KEY UPDATE | ||
| # | ||
| # | ||
| # Test setup | ||
| # | ||
| CREATE TABLE t1 ( | ||
| a INT PRIMARY KEY, | ||
| b INT, | ||
| c INT | ||
| ); | ||
| # | ||
| # Basic INSERT AS alias ON DUPLICATE KEY UPDATE | ||
| # | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = new.c; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 20 200 | ||
| # | ||
| # Multiple rows with AS alias | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200), (2, 30, 300) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b; | ||
| SELECT * FROM t1 ORDER BY a; | ||
| a b c | ||
| 1 20 100 | ||
| 2 30 300 | ||
| # | ||
| # Expression using alias columns | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 5, 50) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b + new.c, c = new.a * 10; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 55 10 | ||
| # | ||
| # Mix of alias and table column references | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = t1.c + new.c; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 20 300 | ||
| # | ||
| # INSERT without ON DUPLICATE KEY (alias should be ignored) | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100) AS new; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 10 100 | ||
| # | ||
| # Different alias names | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 99, 999) AS inserted_row | ||
| ON DUPLICATE KEY UPDATE b = inserted_row.b, c = inserted_row.c; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 99 999 | ||
| # | ||
| # Alias cannot be the same as the target table name | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 50, 500) AS t1 | ||
| ON DUPLICATE KEY UPDATE b = t1.b; | ||
| ERROR 42000: Not unique table/alias: 't1' | ||
| # | ||
| # Verify that AS alias is NOT allowed in REPLACE | ||
| # | ||
| REPLACE INTO t1 VALUES (1, 50, 500) AS new; | ||
| ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use | ||
| # | ||
| # Verify that AS alias is NOT allowed in CREATE ... VALUES | ||
| # | ||
| CREATE TABLE t2 AS VALUES (1, 10, 100) AS new; | ||
| ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use | ||
| # | ||
| # Cleanup | ||
| # | ||
| DROP TABLE t1; | ||
| DROP TABLE IF EXISTS t2; | ||
| # | ||
| # End of tests | ||
| # |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| --echo # | ||
| --echo # MDEV-29919: Support INSERT ... VALUES AS alias ON DUPLICATE KEY UPDATE | ||
| --echo # | ||
|
|
||
| # | ||
| # This test validates the row alias syntax for INSERT ON DUPLICATE KEY UPDATE | ||
| # which allows referencing inserted values using alias.column instead of VALUES(column) | ||
| # | ||
|
|
||
| --echo # | ||
| --echo # Test setup | ||
| --echo # | ||
| CREATE TABLE t1 ( | ||
| a INT PRIMARY KEY, | ||
| b INT, | ||
| c INT | ||
| ); | ||
|
|
||
| --echo # | ||
| --echo # Basic INSERT AS alias ON DUPLICATE KEY UPDATE | ||
| --echo # | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = new.c; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Multiple rows with AS alias | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200), (2, 30, 300) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b; | ||
| SELECT * FROM t1 ORDER BY a; | ||
|
|
||
| --echo # | ||
| --echo # Expression using alias columns | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 5, 50) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b + new.c, c = new.a * 10; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Mix of alias and table column references | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = t1.c + new.c; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # INSERT without ON DUPLICATE KEY (alias should be ignored) | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100) AS new; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Different alias names | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 99, 999) AS inserted_row | ||
| ON DUPLICATE KEY UPDATE b = inserted_row.b, c = inserted_row.c; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Alias cannot be the same as the target table name | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| --error ER_NONUNIQ_TABLE | ||
| INSERT INTO t1 VALUES (1, 50, 500) AS t1 | ||
| ON DUPLICATE KEY UPDATE b = t1.b; | ||
|
|
||
| --echo # | ||
| --echo # Verify that AS alias is NOT allowed in REPLACE | ||
| --echo # | ||
| --error ER_SYNTAX_ERROR | ||
| REPLACE INTO t1 VALUES (1, 50, 500) AS new; | ||
|
|
||
| --echo # | ||
| --echo # Verify that AS alias is NOT allowed in CREATE ... VALUES | ||
| --echo # | ||
| --error ER_SYNTAX_ERROR | ||
| CREATE TABLE t2 AS VALUES (1, 10, 100) AS new; | ||
|
|
||
| --echo # | ||
| --echo # Cleanup | ||
| --echo # | ||
| DROP TABLE t1; | ||
| --disable_warnings | ||
| DROP TABLE IF EXISTS t2; | ||
| --enable_warnings | ||
|
|
||
| --echo # | ||
| --echo # End of tests | ||
| --echo # | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3454,6 +3454,8 @@ struct LEX: public Query_tables_list | |
| const char *clause_that_disallows_subselect; | ||
|
|
||
| enum enum_duplicates duplicates; | ||
| /* Represents INSERT...VALUES as <alias> */ | ||
| Lex_ident_sys_st insert_values_alias; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you plase explain the reason to choose Lex_ident_sys_st
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this's what i understand from this comment when i searched i found this and i though it's the same as u mean |
||
| enum enum_tx_isolation tx_isolation; | ||
| enum enum_ha_read_modes ha_read_mode; | ||
| union { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.