Commit 3687edee authored by Sergei Golubchik's avatar Sergei Golubchik

clarify the order of evaluation for INSERT

parent f93a2a3b
...@@ -3068,3 +3068,11 @@ t1 CREATE TABLE `t1` ( ...@@ -3068,3 +3068,11 @@ t1 CREATE TABLE `t1` (
`a` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT concat('A') `a` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT concat('A')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1; DROP TABLE t1;
create table t1 (a int default 1, b int default (1+1), c int);
insert t1 (c) values (a);
insert t1 (c) values (b);
select * from t1;
a b c
1 2 1
1 2 NULL
drop table t1;
...@@ -1840,3 +1840,12 @@ CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT(' ...@@ -1840,3 +1840,12 @@ CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('
CREATE OR REPLACE TABLE t1 (a char(2) default concat('A') COLLATE utf8mb4_unicode_ci); CREATE OR REPLACE TABLE t1 (a char(2) default concat('A') COLLATE utf8mb4_unicode_ci);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
DROP TABLE t1; DROP TABLE t1;
#
# Order of evaluation:
#
create table t1 (a int default 1, b int default (1+1), c int);
insert t1 (c) values (a);
insert t1 (c) values (b);
select * from t1;
drop table t1;
...@@ -942,6 +942,7 @@ bool Item_field::register_field_in_write_map(void *arg) ...@@ -942,6 +942,7 @@ bool Item_field::register_field_in_write_map(void *arg)
Fields are initialized in this order: Fields are initialized in this order:
- All fields that have default value as a constant are initialized first. - All fields that have default value as a constant are initialized first.
- Then user-specified values from the INSERT list
- Then all fields that has a default expression, in field_index order. - Then all fields that has a default expression, in field_index order.
- Last all virtual fields, in field_index order. - Last all virtual fields, in field_index order.
...@@ -949,6 +950,8 @@ bool Item_field::register_field_in_write_map(void *arg) ...@@ -949,6 +950,8 @@ bool Item_field::register_field_in_write_map(void *arg)
- For default fields we can't access the same field or a field after - For default fields we can't access the same field or a field after
itself that doesn't have a non-constant default value. itself that doesn't have a non-constant default value.
- A virtual fields can't access itself or a virtual field after itself. - A virtual fields can't access itself or a virtual field after itself.
- user-specified values will not see virtual fields or default expressions,
as in INSERT t1 (a) VALUES (b);
This is used by fix_vcol_expr() when a table is opened This is used by fix_vcol_expr() when a table is opened
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment