2016-11-21 16:16:52 +01:00
|
|
|
#
|
|
|
|
# Test how UPDATE detects what columns need to be read (or generated) in a row
|
|
|
|
#
|
|
|
|
# stored column depends on virtual column depends on updated column.
|
|
|
|
# this tests TABLE::mark_virtual_columns_for_write()
|
|
|
|
#
|
2024-05-28 07:08:51 +02:00
|
|
|
create table t1 (a int, b int as (a+1), c int as (b+1) stored) charset=latin1;
|
2016-11-21 16:16:52 +01:00
|
|
|
insert t1 set a=1;
|
|
|
|
select * from t1;
|
|
|
|
update t1 set a=2;
|
|
|
|
select * from t1;
|
|
|
|
drop table t1;
|
2016-11-16 14:04:37 +01:00
|
|
|
#
|
|
|
|
# one keypart is virtual, the other keypart is updated
|
|
|
|
# this tests TABLE::mark_columns_needed_for_update()
|
|
|
|
#
|
2024-05-28 07:08:51 +02:00
|
|
|
create table t1 (a int, c int as(a), p varchar(20) as(rtrim(y)), y char(20), index (p,c)) charset=latin1;
|
2018-05-26 13:27:23 +02:00
|
|
|
show create table t1;
|
2016-11-16 14:04:37 +01:00
|
|
|
insert into t1 (a,y) values(1, "yyy");
|
|
|
|
update t1 set a = 100 where a = 1;
|
2018-05-26 13:27:23 +02:00
|
|
|
check table t1;
|
2016-11-16 14:04:37 +01:00
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
#
|
|
|
|
# note: prefix keys below
|
|
|
|
#
|
|
|
|
create table t1 (
|
|
|
|
a varchar(10000),
|
|
|
|
b varchar(3000),
|
|
|
|
c varchar(14000) generated always as (concat(a,b)) virtual,
|
|
|
|
d varchar(5000) generated always as (b) virtual,
|
|
|
|
e int(11) generated always as (10) virtual,
|
|
|
|
h int(11) not null primary key,
|
2024-05-28 07:08:51 +02:00
|
|
|
index(c(100), d(20))) charset=latin1;
|
2016-11-16 14:04:37 +01:00
|
|
|
insert t1 (a,b,h) values (repeat('g', 10000), repeat('x', 2800), 1);
|
|
|
|
update t1 set a = repeat(cast(1 as char), 2000);
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
create table t1 (
|
|
|
|
a varchar(10000),
|
|
|
|
b varchar(3000),
|
|
|
|
c varchar(14000) generated always as (concat(a,b)) virtual,
|
|
|
|
i varchar(5000) generated always as (b) virtual,
|
|
|
|
d varchar(5000) generated always as (i) virtual,
|
|
|
|
e int(11) generated always as (10) virtual,
|
|
|
|
h int(11) not null primary key,
|
2024-05-28 07:08:51 +02:00
|
|
|
index(c(100), d(20))) charset=latin1;
|
2016-11-16 14:04:37 +01:00
|
|
|
insert t1 (a,b,h) values (repeat('g', 10000), repeat('x', 2800), 1);
|
|
|
|
update t1 set a = repeat(cast(1 as char), 2000);
|
|
|
|
drop table t1;
|
2016-11-16 19:26:55 +01:00
|
|
|
#
|
|
|
|
# UPDATE disguised as INSERT
|
|
|
|
#
|
|
|
|
create table t1(a blob not null, b int, c varbinary (10) generated always as (a) virtual, unique (c(9)));
|
|
|
|
insert t1 (a,b) values ('a', 1);
|
|
|
|
replace t1 set a = 'a',b =1;
|
|
|
|
insert t1 (a,b) values ('a', 1) on duplicate key update a='b', b=2;
|
|
|
|
select * from t1;
|
|
|
|
drop table t1;
|
2016-11-23 12:54:59 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# multi-UPDATE and const tables
|
|
|
|
#
|
|
|
|
create table t (a int primary key, b int, c int as (b), index (c));
|
|
|
|
insert t (a,b) values (9,0);
|
|
|
|
create table t2 select * from t;
|
|
|
|
update t, t2 set t.b=10 where t.a=t2.a;
|
|
|
|
check table t; select * from t;
|
|
|
|
drop table t, t2;
|
bugfix: UPDATE and virtual BLOBs
When updating a table with virtual BLOB columns, the following might happen:
- an old record is read from the table, it has no virtual blob values
- update_virtual_fields() is run, vcol blob gets its value into the
record. But only a pointer to the value is in the table->record[0],
the value is in Field_blob::value String (but it doesn't have to be!
it can be in the record, if the column is just a copy of another
columns: ... b VARCHAR, c BLOB AS (b) ...)
- store_record(table,record[1]), old record now is in record[1]
- fill_record() prepares new values in record[0], vcol blob is updated,
new value replaces the old one in the Field_blob::value
- now both record[1] and record[0] have a pointer that points to the
*new* vcol blob value. Or record[1] has a pointer to nowhere if
Field_blob::value had to realloc.
To resolve this we unlink vcol blobs from the pointer to the
data (in the record[1]). Because the value is not *always* in
the Field_blob::value String, we need to remember what blobs
were unlinked. The orphan memory must be freed manually.
To complicate the matter, ha_update_row() is also used in
multi-update, in REPLACE, in INSERT ... ON DUPLICATE KEY UPDATE,
also on REPLACE ... SELECT, REPLACE DELAYED, and LOAD DATA REPLACE, etc
2016-11-23 16:42:09 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# blobs
|
|
|
|
# This tests BLOB_VALUE_ORPHANAGE
|
|
|
|
#
|
|
|
|
create table t1 (a int, b int, c int, d int, e int);
|
|
|
|
insert t1 values (1,2,3,4,5), (1,2,3,4,5);
|
2017-02-08 21:28:00 +01:00
|
|
|
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
|
bugfix: UPDATE and virtual BLOBs
When updating a table with virtual BLOB columns, the following might happen:
- an old record is read from the table, it has no virtual blob values
- update_virtual_fields() is run, vcol blob gets its value into the
record. But only a pointer to the value is in the table->record[0],
the value is in Field_blob::value String (but it doesn't have to be!
it can be in the record, if the column is just a copy of another
columns: ... b VARCHAR, c BLOB AS (b) ...)
- store_record(table,record[1]), old record now is in record[1]
- fill_record() prepares new values in record[0], vcol blob is updated,
new value replaces the old one in the Field_blob::value
- now both record[1] and record[0] have a pointer that points to the
*new* vcol blob value. Or record[1] has a pointer to nowhere if
Field_blob::value had to realloc.
To resolve this we unlink vcol blobs from the pointer to the
data (in the record[1]). Because the value is not *always* in
the Field_blob::value String, we need to remember what blobs
were unlinked. The orphan memory must be freed manually.
To complicate the matter, ha_update_row() is also used in
multi-update, in REPLACE, in INSERT ... ON DUPLICATE KEY UPDATE,
also on REPLACE ... SELECT, REPLACE DELAYED, and LOAD DATA REPLACE, etc
2016-11-23 16:42:09 +01:00
|
|
|
create table t (a int primary key,
|
|
|
|
b int, c blob as (b), index (c(57)),
|
|
|
|
d blob, e blob as (d), index (e(57)))
|
|
|
|
replace select * from t1;
|
|
|
|
check table t; select * from t;
|
|
|
|
update t set a=10, b=1, d=1;
|
|
|
|
check table t; select * from t;
|
|
|
|
replace t (a,b,d) values (10,2,2);
|
|
|
|
check table t; select * from t;
|
|
|
|
--error ER_WRONG_VALUE_COUNT_ON_ROW
|
|
|
|
insert t(a,b,d) values (10) on duplicate key update b=3;
|
|
|
|
insert t(a,b,d) values (10,2,2) on duplicate key update b=3, d=3;
|
|
|
|
check table t; select * from t;
|
|
|
|
replace t (a,b,d) select 10,4,4;
|
|
|
|
check table t; select * from t;
|
|
|
|
insert t(a,b,d) select 10,4,4 on duplicate key update b=5, d=5;
|
|
|
|
check table t; select * from t;
|
|
|
|
replace delayed t (a,b,d) values (10,6,6);
|
2018-10-31 21:52:29 +01:00
|
|
|
flush tables t;
|
bugfix: UPDATE and virtual BLOBs
When updating a table with virtual BLOB columns, the following might happen:
- an old record is read from the table, it has no virtual blob values
- update_virtual_fields() is run, vcol blob gets its value into the
record. But only a pointer to the value is in the table->record[0],
the value is in Field_blob::value String (but it doesn't have to be!
it can be in the record, if the column is just a copy of another
columns: ... b VARCHAR, c BLOB AS (b) ...)
- store_record(table,record[1]), old record now is in record[1]
- fill_record() prepares new values in record[0], vcol blob is updated,
new value replaces the old one in the Field_blob::value
- now both record[1] and record[0] have a pointer that points to the
*new* vcol blob value. Or record[1] has a pointer to nowhere if
Field_blob::value had to realloc.
To resolve this we unlink vcol blobs from the pointer to the
data (in the record[1]). Because the value is not *always* in
the Field_blob::value String, we need to remember what blobs
were unlinked. The orphan memory must be freed manually.
To complicate the matter, ha_update_row() is also used in
multi-update, in REPLACE, in INSERT ... ON DUPLICATE KEY UPDATE,
also on REPLACE ... SELECT, REPLACE DELAYED, and LOAD DATA REPLACE, etc
2016-11-23 16:42:09 +01:00
|
|
|
check table t; select * from t;
|
|
|
|
insert delayed t(a,b,d) values (10,6,6) on duplicate key update b=7, d=7;
|
2018-10-31 21:52:29 +01:00
|
|
|
flush tables t;
|
bugfix: UPDATE and virtual BLOBs
When updating a table with virtual BLOB columns, the following might happen:
- an old record is read from the table, it has no virtual blob values
- update_virtual_fields() is run, vcol blob gets its value into the
record. But only a pointer to the value is in the table->record[0],
the value is in Field_blob::value String (but it doesn't have to be!
it can be in the record, if the column is just a copy of another
columns: ... b VARCHAR, c BLOB AS (b) ...)
- store_record(table,record[1]), old record now is in record[1]
- fill_record() prepares new values in record[0], vcol blob is updated,
new value replaces the old one in the Field_blob::value
- now both record[1] and record[0] have a pointer that points to the
*new* vcol blob value. Or record[1] has a pointer to nowhere if
Field_blob::value had to realloc.
To resolve this we unlink vcol blobs from the pointer to the
data (in the record[1]). Because the value is not *always* in
the Field_blob::value String, we need to remember what blobs
were unlinked. The orphan memory must be freed manually.
To complicate the matter, ha_update_row() is also used in
multi-update, in REPLACE, in INSERT ... ON DUPLICATE KEY UPDATE,
also on REPLACE ... SELECT, REPLACE DELAYED, and LOAD DATA REPLACE, etc
2016-11-23 16:42:09 +01:00
|
|
|
check table t; select * from t;
|
|
|
|
--write_file $MYSQLTEST_VARDIR/tmp/vblobs.txt
|
|
|
|
10 8 foo 8 foo
|
|
|
|
EOF
|
|
|
|
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
|
|
|
|
--eval load data infile '$MYSQLTEST_VARDIR/tmp/vblobs.txt' replace into table t
|
|
|
|
--remove_file $MYSQLTEST_VARDIR/tmp/vblobs.txt
|
|
|
|
check table t; select * from t;
|
|
|
|
update t set a=11, b=9, d=9 where a>5;
|
|
|
|
check table t; select * from t;
|
|
|
|
create table t2 select * from t;
|
|
|
|
update t, t2 set t.b=10, t.d=10 where t.a=t2.a;
|
|
|
|
check table t; select * from t;
|
|
|
|
update t, t tt set t.b=11, tt.d=11 where t.a=tt.a;
|
|
|
|
check table t; select * from t;
|
|
|
|
drop table t, t1, t2;
|
2017-09-14 19:31:04 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# MDEV-13623 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed in virtual longlong Field_long::val_int
|
|
|
|
#
|
|
|
|
create table t (f1 int, f2 int, f3 int as (f1*2) virtual, key(f3,f2));
|
|
|
|
insert into t (f1,f2) values (1,1),(2,2);
|
|
|
|
create view v as
|
|
|
|
select a2.f1, a2.f2, a1.f3
|
|
|
|
from t a1, t a2
|
|
|
|
where a2.f3 <> 0
|
|
|
|
with local check option;
|
|
|
|
update v set f3 = 52;
|
|
|
|
drop view v;
|
|
|
|
drop table t;
|