Commit 1cae1af6 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-5800 InnoDB support for indexed vcols

  * remove old 5.2+ InnoDB support for virtual columns
  * enable corresponding parts of the innodb-5.7 sources
  * copy corresponding test cases from 5.7
  * copy detailed Alter_inplace_info::HA_ALTER_FLAGS flags from 5.7
     - and more detailed detection of changes in fill_alter_inplace_info()
  * more "innodb compatibility hooks" in sql_class.cc to
     - create/destroy/reset a THD (used by background purge threads)
     - find a prelocked table by name
     - open a table (from a background purge thread)

  * different from 5.7:
    - new service thread "thd_destructor_proxy" to make sure all THDs are
      destroyed at the correct point in time during the server shutdown
    - proper opening/closing of tables for vcol evaluations in
       + FK checks (use already opened prelocked tables)
       + purge threads (open the table, MDLock it, add it to tdc, close
         when not needed)
    - cache open tables in vc_templ
    - avoid unnecessary allocations, reuse table->record[0] and table->s->default_values
    - not needed in 5.7, because it overcalculates:
      + tell the server to calculate vcols for an on-going inline ADD INDEX
      + calculate vcols for correct error messages

  * update other engines (mroonga/tokudb) accordingly
parent 7fca91f2
......@@ -9,9 +9,13 @@ innodb-locks
innodb-buffer-pool-stats
innodb-buffer-page
innodb-buffer-page-lru
innodb-sys-columns
innodb-sys-fields
innodb-sys-foreign
innodb-sys-foreign-cols
innodb-sys-indexes
innodb-sys-tables
innodb-sys-virtual
innodb-metrics
[xtradb_plugin]
......@@ -54,6 +58,10 @@ innodb-metrics
innodb-buffer-pool-stats
innodb-buffer-page
innodb-buffer-page-lru
innodb-sys-columns
innodb-sys-fields
innodb-sys-foreign
innodb-sys-foreign-cols
innodb-sys-indexes
innodb-sys-tables
innodb-sys-virtual
......@@ -395,7 +395,7 @@ ALTER TABLE t CHANGE c c varchar(10) as ('a');
ALTER TABLE t CHANGE dd d varchar(10);
if ($support_virtual_index)
{
# no RENAME INDEX yet
#ALTER TABLE t ADD INDEX idx(a), ADD INDEX idx1(c);
#ALTER TABLE t RENAME INDEX idx TO idx2, RENAME INDEX idx1 TO idx3;
#ALTER TABLE t DROP INDEX idx2, DROP INDEX idx3;
......
--source include/have_innodb.inc
eval CREATE TABLE `t` (
`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 (`h`) ) ROW_FORMAT=$row_format ENGINE=InnoDB;
SHOW CREATE TABLE t;
INSERT INTO t VALUES (REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
INSERT INTO t VALUES (REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
INSERT INTO t VALUES (REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
CREATE INDEX idx ON t(c(100), d(20));
UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
delimiter |;
CREATE PROCEDURE UPDATE_t()
begin
DECLARE i INT DEFAULT 1;
WHILE (i <= 100) DO
UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
SET i = i + 1;
END WHILE;
END|
CREATE PROCEDURE DELETE_insert_t()
begin
DECLARE i INT DEFAULT 1;
WHILE (i <= 100) DO
DELETE FROM t WHERE h = 1;
INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
SET i = i + 1;
END WHILE;
END|
delimiter ;|
CALL UPDATE_t();
CALL DELETE_insert_t();
UPDATE t SET a = NULL WHERE h=1;
START TRANSACTION;
CALL UPDATE_t();
ROLLBACK;
DROP PROCEDURE DELETE_insert_t;
DROP PROCEDURE UPDATE_t;
DROP TABLE t;
......@@ -550,6 +550,10 @@ b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL,
KEY (a(183),b)
);
INSERT INTO t VALUES(), (), ();
Warnings:
Warning 1265 Data truncated for column 'b' at row 1
Warning 1265 Data truncated for column 'b' at row 2
Warning 1265 Data truncated for column 'b' at row 3
DELETE IGNORE FROM t;
DROP TABLE t;
#
......
......@@ -18,7 +18,6 @@ a b
9 9
BEGIN;
INSERT INTO t (a) VALUES (10);
# Kill and restart
SELECT * FROM t;
a b
9 9
......@@ -32,8 +31,11 @@ INSERT INTO t (a,c) VALUES (9, 10);
SELECT * FROM t;
a b c
9 9 10
connect con1,localhost,root,,;
connection con1;
SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
ALTER TABLE t ADD KEY(b(57)), ALGORITHM=INPLACE;
connection default;
SET DEBUG_SYNC = 'now WAIT_FOR created';
BEGIN;
INSERT INTO t (a,c) VALUES (10, 12);
......@@ -43,6 +45,9 @@ a b c
10 10 12
ROLLBACK;
SET DEBUG_SYNC = 'now SIGNAL dml_done';
connection con1;
disconnect con1;
connection default;
SELECT * FROM t;
a b c
9 9 10
......@@ -58,8 +63,11 @@ INSERT INTO t (a,b) VALUES (9, 10);
SELECT * FROM t;
a b c d
9 10 19 29
connect con1,localhost,root,,;
connection con1;
SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
connection default;
SET DEBUG_SYNC = 'now WAIT_FOR created';
BEGIN;
INSERT INTO t (a,b) VALUES (10, 12);
......@@ -69,7 +77,11 @@ a b c d
10 12 22 34
ROLLBACK;
SET DEBUG_SYNC = 'now SIGNAL dml_done';
connection con1;
disconnect con1;
connection default;
SELECT * FROM t;
a b d
9 10 29
DROP TABLE t;
SET DEBUG_SYNC = 'RESET';
......@@ -563,6 +563,8 @@ id select_type table type possible_keys key key_len ref rows Extra
SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c
WHERE b.b>c.a;
c
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'cccc'
DROP TABLE t;
set @optimizer_switch_save = @@optimizer_switch;
set optimizer_switch='mrr_cost_based=off';
......
#
# Bug#22444530 - GCOLS + PARTITIONED TABLE, CRASH IN
#
set sql_mode='';
create table t (
a int not null,
b int generated always as (1) virtual,
c int generated always as (1) virtual,
key (c)
) engine=innodb partition by key (a) partitions 2;
insert into t(a) values(1);
select b from t group by c;
b
1
drop table t;
create table t (
a int not null,
b blob generated always as ("a") virtual,
c int generated always as (1) virtual,
key (c)
) engine=innodb partition by key (a) partitions 2;
insert into t(a) values(1);
select b from t group by c;
b
a
drop table t;
#Bug #22445211 GCOLS: SIMPLE DML, FAILING ASSERTION:
#!CURSOR->INDEX->IS_COMMITTED()
#Create and alter table examples for virtual column for full
#column index followed by prefix index.
CREATE TABLE t1(
f1 INT DEFAULT NULL,
f2 CHAR(2) GENERATED ALWAYS AS ('11') VIRTUAL,
f3 INT,
UNIQUE KEY(f1),
UNIQUE KEY(f3,f1),
KEY(f2,f1),
key(f1,f2(1))
)ENGINE=INNODB;
REPLACE INTO t1(f3) VALUES (1),(1);
DROP TABLE t1;
This diff is collapsed.
#
# Bug#22046353 ALTER: ASSERT PAGE_SIZE.EQUALS_TO(SPACE_PAGE_SIZE),
# BTR_COPY_BLOB_PREFIX
#
CREATE TABLE t1
( f1 int primary key, f2 blob,
f3 blob generated always as (f2))
row_format=compressed, engine=innodb;
insert into t1 (f1, f2) values (1, repeat('&', 50000));
alter table t1 add index i1 (f3(200)) ;
alter table t1 row_format=compact;
drop table t1;
set default_storage_engine=innodb;
CREATE TABLE `t` (
`a` VARCHAR(100),
`b` VARCHAR(100),
`c` VARCHAR(200) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
`h` VARCHAR(10) DEFAULT NULL,
`i` int
) ENGINE=InnoDB;
INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 10), DEFAULT, "kk", 1);
INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
CREATE INDEX idx ON t(c(100));
SET session debug_dbug="+d,ib_alter_add_virtual_fail";
ALTER TABLE t ADD COLUMN x VARCHAR(200) GENERATED ALWAYS AS (a) VIRTUAL,
ALGORITHM = INPLACE;
ERROR 42000: The storage engine InnoDB can't index column `x`
ALTER TABLE t DROP COLUMN c, ALGORITHM = INPLACE;
ERROR 42000: The storage engine InnoDB can't index column `c`
SET session debug_dbug="";
DROP TABLE t;
CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (null, null, DEFAULT, "mx");
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
CREATE INDEX idx ON t(c);
connect con1,localhost,root,,;
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
update t set a=0 where a = 11;
start transaction;
update t set a=1 where a = 0;
ROLLBACK;
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
SELECT c FROM t;
c
NULL
3
19
29
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) AS ((`a` + `b`)) VIRTUAL,
`h` varchar(10) DEFAULT NULL,
KEY `idx` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT * FROM t;
a b c h
0 3 3 mm
18 1 19 mm
28 1 29 mm
NULL NULL NULL mx
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
ALTER TABLE t ADD COLUMN x INT;
connection con1;
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
start transaction;
update t set a=1 where a = 0;
rollback;
start transaction;
delete from t;
insert into t values(1,null,default,null);
rollback;
start transaction;
update t set b=b+1;
rollback;
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
check table t;
Table Op Msg_type Msg_text
test.t check status OK
SELECT c FROM t;
c
NULL
3
19
29
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
ALTER TABLE t ADD COLUMN x2 INT;
connection con1;
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
start transaction;
DELETE FROM t WHERE a = 0;
ROLLBACK;
DELETE FROM t WHERE a = 0;
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
SELECT c FROM t;
c
NULL
19
29
disconnect con1;
DROP TABLE t;
SET DEBUG_SYNC = 'RESET';
CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
CREATE INDEX idx_1 on t(c);
SET SESSION debug_dbug="+d,create_index_fail";
ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (x);
ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
SET SESSION debug_dbug="";
affected rows: 0
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) AS ((`a` + `b`)) VIRTUAL,
`h` varchar(10) DEFAULT NULL,
KEY `idx_1` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT c FROM t;
c
NULL
14
19
29
DROP TABLE t;
#
# Bug#22018532 ASSERTION WHEN ONLINE REAPPLY REBUILD LOG ON
# MULTIPLE INDEXED VIRTUAL COLUMNS
#
create table t (
a int as (1) virtual,
b int,
c int as (1) virtual,
unique(b),
unique(c),
key(a)
) engine=innodb;
insert ignore into t values();
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
optimize table t;
connect con1,localhost,root,,;
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
insert ignore into t values();
Warnings:
Warning 1062 Duplicate entry '1' for key 'c'
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
/* connection default */ optimize table t;
Table Op Msg_type Msg_text
test.t optimize note Table does not support optimize, doing recreate + analyze instead
test.t optimize error Duplicate entry '1' for key 'a'
test.t optimize status Operation failed
Warnings:
Error 1062 Duplicate entry '1' for key 'a'
SELECT c FROM t;
c
1
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) AS (1) VIRTUAL,
`b` int(11) DEFAULT NULL,
`c` int(11) AS (1) VIRTUAL,
UNIQUE KEY `b` (`b`),
UNIQUE KEY `c` (`c`),
KEY `a` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT * FROM t;
a b c
1 NULL 1
DROP TABLE t;
CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
CREATE INDEX idx ON t(c);
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_rebuild WAIT_FOR go_ahead';
optimize table t;
connection con1;
SET DEBUG_SYNC = 'now WAIT_FOR start_rebuild';
INSERT INTO t VALUES (48, 2, DEFAULT, 'xx');
INSERT INTO t VALUES (68, 3, DEFAULT, 'sx');
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
/* connection default */ optimize table t;
Table Op Msg_type Msg_text
test.t optimize note Table does not support optimize, doing recreate + analyze instead
test.t optimize status OK
SELECT c FROM t;
c
NULL
14
19
29
50
71
disconnect con1;
DROP TABLE t;
#
# Bug#22951879 - ASSERTS RELATED TO ONLINE DDL AND GCOL
#
create table ibstd_14 (a int not null, d int not null, b varchar(198) not null, c char(181), vadcol int as (a+length(d)) stored, vbcol char(2) as (substr(b,2,2)) virtual, vbidxcol char(3) as (substr(b,1,3)) virtual , index(d), index(a), index(vbidxcol), index(a,vbidxcol), index(vbidxcol,d), unique key (b(10), a, d), index(c(99), b(31)), index(b(5), c(10), a) , index(a,d)) engine=InnoDB stats_persistent=1 row_format=dynamic;
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
alter table ibstd_14 row_format=compressed key_block_size=4,add key kn3 (d,c,vbcol,b);
connect con1,localhost,root;
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
insert into ibstd_14 (a,d,b,c, vbidxcol, vbcol) values ('118','6',repeat('oacolaarlruoacuroauurloraarucoooarcooauoolacalllaulrruarrrucruuooclacuoouccarrcoocloccorrrrarourcooalloocooccouruolaorlcaocualolc','1'),repeat('lolrrlalcocroraaulauclaaucolcorcuooaolruaooooluooooouaoorlarucorullalcrrloccououaooaorluorraclrcooouuolocoaolcocaaculruoocucoocoooauuolarcoraraocaoolulolarru','1'),default,default);
insert into ibstd_14 (a,d,b,c, vbidxcol, vbcol) values ('118','6', 'aaaa', 'lll', default, default);
update ibstd_14 set b='11111' where b='aaaa';
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
select * from ibstd_14;
a d b c vadcol vbcol vbidxcol
118 6 oacolaarlruoacuroauurloraarucoooarcooauoolacalllaulrruarrrucruuooclacuoouccarrcoocloccorrrrarourcooalloocooccouruolaorlcaocualolc lolrrlalcocroraaulauclaaucolcorcuooaolruaooooluooooouaoorlarucorullalcrrloccououaooaorluorraclrcooouuolocoaolcocaaculruoocucoocoooauuolarcoraraocaoolulolarru 119 ac oac
118 6 11111 lll 119 11 111
select d,c,vbcol,b from ibstd_14;
d c vbcol b
6 lll 11 11111
6 lolrrlalcocroraaulauclaaucolcorcuooaolruaooooluooooouaoorlarucorullalcrrloccououaooaorluorraclrcooouuolocoaolcocaaculruoocucoocoooauuolarcoraraocaoolulolarru ac oacolaarlruoacuroauurloraarucoooarcooauoolacalllaulrruarrrucruuooclacuoouccarrcoocloccorrrrarourcooalloocooccouruolaorlcaocualolc
select vbcol from ibstd_14;
vbcol
11
ac
drop table ibstd_14;
disconnect con1;
SET DEBUG_SYNC = 'RESET';
set default_storage_engine=innodb;
set @old_dbug=@@global.debug_dbug;
CREATE TABLE `t` (
`a` BLOB,
`b` BLOB,
`c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
`h` VARCHAR(10) DEFAULT NULL,
`i` int
) ENGINE=InnoDB;
INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, "kk", 1);
INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, "mm", 2);
CREATE INDEX idx ON t(c(100));
SET global debug_dbug="+d,ib_purge_virtual_index_callback";
UPDATE t SET a = REPEAT('m', 16000) WHERE a like "aaa%";
select sleep(3);
sleep(3)
0
SET global debug_dbug=@old_dbug;
DROP TABLE t;
CREATE TABLE t (
a TINYBLOB,
b TINYBLOB,
c TINYBLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
h VARCHAR(10) DEFAULT NULL,
i INT
) ROW_FORMAT=COMPACT ENGINE=InnoDB;
INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 100), DEFAULT, "kk", 1);
INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
CREATE INDEX idx ON t(c(100));
SET global debug_dbug="+d,ib_purge_virtual_index_callback";
UPDATE t SET a = REPEAT('m', 100) WHERE a like "aaa%";
select sleep(3);
sleep(3)
0
SET global debug_dbug=@old_dbug;
DROP TABLE t;
CREATE TABLE t1 (
id INT NOT NULL,
store_id INT NOT NULL,
x INT GENERATED ALWAYS AS (id + store_id)
)
PARTITION BY RANGE (store_id) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11),
PARTITION p2 VALUES LESS THAN (16),
PARTITION p3 VALUES LESS THAN (21)
);
insert into t1 values(1, 2, default);
insert into t1 values(3, 4, default);
insert into t1 values(3, 12, default);
insert into t1 values(4, 18, default);
CREATE INDEX idx ON t1(x);
SET global debug_dbug="+d,ib_purge_virtual_index_callback";
UPDATE t1 SET id = 10 WHERE id = 1;
select sleep(3);
sleep(3)
0
SET global debug_dbug=@old_dbug;
DROP TABLE t1;
connect con1,localhost,root,,;
connection default;
CREATE TABLE t1 (a INT, b INT);
INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3);
connection con1;
# disable purge
CREATE TABLE t0 (a INT) ENGINE=InnoDB;
BEGIN;
SELECT * FROM t0;
a
connection default;
DELETE FROM t1 WHERE a = 1;
UPDATE t1 SET a = 4, b = 4 WHERE a = 3;
INSERT INTO t1(a, b) VALUES (5, 5);
SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
ERROR 0A000: LOCK=NONE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try LOCK=SHARED
ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
connection con1;
SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
# enable purge
COMMIT;
# wait for purge to process the deleted records.
Timeout in wait_innodb_all_purged.inc for INNODB_PURGE_TRX_ID_AGE = 3
SET DEBUG_SYNC= 'now SIGNAL purged';
connection default;
/* connection default */ ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) AS ((`a` + `b`)) VIRTUAL,
KEY `idx` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT * FROM t1;
a b c
2 2 4
4 4 8
5 5 10
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b));
INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3), (4, 4);
connection con1;
# disable purge
BEGIN;
SELECT * FROM t0;
a
connection default;
DELETE FROM t1 WHERE a = 1;
UPDATE t1 SET a = 2, b = 2 WHERE a = 5;
INSERT INTO t1(a, b) VALUES (6, 6);
SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
connection con1;
SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
DELETE FROM t1 WHERE a = 3;
UPDATE t1 SET a = 7, b = 7 WHERE a = 4;
INSERT INTO t1(a, b) VALUES (8, 8);
# enable purge
COMMIT;
# wait for purge to process the deleted/updated records.
SET DEBUG_SYNC= 'now SIGNAL purged';
disconnect con1;
connection default;
/* connection default */ ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) AS ((`a` + `b`)) VIRTUAL,
KEY `idx` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT * FROM t1;
a b c
2 2 4
7 7 14
6 6 12
8 8 16
DROP TABLE t0, t1;
set debug_sync=reset;
This diff is collapsed.
#
# Bug#22469130: FOREIGN KEY ON DELETE CASCADE NOT ALLOWED
# WHEN A VIRTUAL INDEX EXISTS.
# Add the VIRTUAL INDEX contains fk constraINT column
# using INPLACE alter operatiON
CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
fld3 INT AS (fld2) VIRTUAL, KEY(fld1),
FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE) engine=innodb;
INSERT INTO t1(fld1) VALUES(1);
INSERT INTO t2(fld1, fld2) VALUES(1, 2);
UPDATE t1 SET fld1= 2;
SELECT fld3, fld1 FROM t2;
fld3 fld1
2 2
alter TABLE t2 ADD INDEX vk(fld3, fld1), ALGORITHM=INPLACE;
UPDATE t1 SET fld1=3;
SELECT fld3, fld1 FROM t2;
fld3 fld1
2 3
DROP TABLE t2, t1;
# TEMPORARY TABLE NAME and CHILD TABLE NAME are same
CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
CREATE TABLE t2(fld1 INT NOT NULL,
fld2 INT AS (fld1) VIRTUAL,
KEY(fld2),
FOREIGN KEY(fld1) REFERENCES t1(fld1)
ON UPDATE CASCADE) engine=innodb;
INSERT INTO t1 VALUES(1), (2);
INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
CREATE TEMPORARY TABLE t2 (fld1 INT NOT NULL)ENGINE=INNODB;
UPDATE t1 SET fld1= 3 WHERE fld1= 2;
connect con1,localhost,root,,test;
SELECT fld2 FROM t2;
fld2
1
3
CHECK TABLE t2;
Table Op Msg_type Msg_text
test.t2 check status OK
connection default;
disconnect con1;
DROP TABLE t2;
DROP TABLE t2, t1;
#
# Bug 21922176 - PREBUILT->SEARCH_TUPLE CREATED WITHOUT INCLUDING
# THE NUMBER OF VIRTUAL COLUMNS
#
CREATE TABLE t1 (a INT, a1 INT GENERATED ALWAYS AS (a) VIRTUAL, a2 INT
GENERATED ALWAYS AS (a) VIRTUAL, a3 INT GENERATED ALWAYS AS (a) VIRTUAL, a4
INT GENERATED ALWAYS AS (a) VIRTUAL, a5 INT GENERATED ALWAYS AS (a) VIRTUAL,
a6 INT GENERATED ALWAYS AS (a) VIRTUAL, a7 INT GENERATED ALWAYS AS (a)
VIRTUAL, a8 INT GENERATED ALWAYS AS (a) VIRTUAL, a9 INT GENERATED ALWAYS AS
(a) VIRTUAL, INDEX(a1, a2, a3, a4, a5, a6, a7, a8, a9)) ;
INSERT INTO t1(a) VALUES(10);
SELECT * FROM t1 WHERE a1=10 AND a2 = 10 AND a3 =10 AND a4 = 10 AND a5=10 AND
a6=10 AND a7=10 AND a8=10 AND a9=10;
a a1 a2 a3 a4 a5 a6 a7 a8 a9
10 10 10 10 10 10 10 10 10 10
DROP TABLE t1;
#
# Bug 22572997 - GCOL:INNODB: FAILING ASSERTION: N < REC_OFFS_N_FIELDS(
# OFFSETS)
#
SET @@SESSION.sql_mode=0;
CREATE TABLE t1(
c1 int(1)AUTO_INCREMENT,
c2 int(1),
c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
c5 date,
c6 date GENERATED ALWAYS AS((c5 + interval 30 day)) VIRTUAL,
c7 DATE,
c8 time,
c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
c10 time GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
c12 CHAR(1),
c13 CHAR(1)GENERATED ALWAYS AS (concat(c12,c12)) VIRTUAL,
c14 CHAR(2)GENERATED ALWAYS AS (concat(c13,'x')) VIRTUAL,
PRIMARY KEY(c1),
KEY c4_6(c4,c11)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE t2(
c1 int(1)AUTO_INCREMENT,
c2 int(1),
c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
c5 date,
c6 date GENERATED ALWAYS AS((c5 + interval 30 day)) VIRTUAL,
c6a date GENERATED ALWAYS AS((c6 + interval 30 day)) VIRTUAL,
c7 DATE,
c8 time,
c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
c10 time GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
c11a time GENERATED ALWAYS AS(addtime(c7,c10)) VIRTUAL,
c12 CHAR(1),
c13 CHAR(2)GENERATED ALWAYS AS (concat(c12,c12)) VIRTUAL,
c14 CHAR(4)GENERATED ALWAYS AS (concat(c13,'x')) VIRTUAL,
PRIMARY KEY(c1),
KEY c13(c13),
KEY c4_6(c4,c11)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO t2(c1,c2,c5,c7,c8,c12)VALUES (0,0,0,0,0,'v');
CREATE TABLE t3(
c1 int(1)AUTO_INCREMENT,
c2 int(1),
c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
c5 date,
c7 DATE,
c8 time,
c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
c12 CHAR(1),
PRIMARY KEY(c1),
KEY c4_6(c4,c11)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO t3(c1,c2,c5,c7,c8,c12)VALUES
(0,0,0,0,0,'q'),(0,0,0,0,0,'g'),(0,0,0,0,0,'l'),(0,0,0,0,0,1),(0,0,0,0,0,'v'),
(0,1,0,0,0,'c'),(0,0,0,0,0,'x');
UPDATE
t2 AS O1,t3 AS O2
SET O1.c12=1
WHERE O1.c14 NOT IN
(
SELECT
DISTINCT I1.c14 AS y
FROM t1 AS I1
ORDER BY I1.c14);
SET @@SESSION.sql_mode=default;
DROP TABLE t1, t2, t3;
#
# Bug 22650296 - ASSERTION IN INNOBASE_BUILD_COL_MAP, ALTER
#
CREATE TABLE `ibstd_08` (
`nc00577` tinyint(4) DEFAULT NULL,
`nc07844` varchar(41) DEFAULT NULL,
`gc01908` point NOT NULL,
`nc04156` char(17) DEFAULT NULL,
`nc09536` longblob NOT NULL,
`nc09231` decimal(10,0) NOT NULL,
`a` int(11) NOT NULL,
`b` varchar(198) NOT NULL,
`nc04560` mediumtext,
`c` char(187) DEFAULT NULL,
`vbidxcol` char(3) GENERATED ALWAYS AS (substr(`b`,1,3)) VIRTUAL,
`gc00881` polygon NOT NULL,
`nc05121` int(11) NOT NULL DEFAULT '85941481',
KEY `a` (`a`),
KEY `b` (`b`(3),`a`),
KEY `c` (`c`(99),`b`(25)),
KEY `b_2` (`b`(5),`c`(10),`a`),
KEY `vbidxcol` (`vbidxcol`),
KEY `a_2` (`a`,`vbidxcol`),
KEY `vbidxcol_2` (`vbidxcol`),
FULLTEXT KEY `ftsic` (`c`,`b`)
) ENGINE=InnoDB;
Warnings:
Note 1831 Duplicate index 'vbidxcol_2' defined on the table 'test.ibstd_08'. This is deprecated and will be disallowed in a future release
ALTER TABLE ibstd_08 ADD COLUMN nc07006 BIGINT AUTO_INCREMENT NOT NULL , ADD KEY auto_nc07006(nc07006);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
DROP TABLE ibstd_08;
#
# Bug 22899305 - GCOLS: FAILING ASSERTION: !(COL->PRTYPE & 256)
# AND SEGFAULT
#
set sql_mode="";
create table t (a int) engine=innodb;
create table s (
b int generated always as (1) virtual,
c int,
d int generated always as (1) virtual,
key (d)
) engine=innodb;
insert into t(a) values ((select d from s for update));
insert into s(c) values ('');
Warnings:
Warning 1366 Incorrect integer value: '' for column 'c' at row 1
SET sql_mode = default;
drop table if exists t,s;
#
# Bug 23014521 - GCOL:INNODB: FAILING ASSERTION: !IS_V
#
CREATE TABLE t1 (
col1 int(11) NOT NULL,
col2 int(11) DEFAULT NULL,
col3 int(11) NOT NULL,
col4 int(11) DEFAULT NULL,
col5 int(11) GENERATED ALWAYS AS ((col1 % col4)) VIRTUAL,
col6 int(11) GENERATED ALWAYS AS ((col2 - col4)) VIRTUAL,
col5x int(11) GENERATED ALWAYS AS ((col3 / col2)) VIRTUAL,
col6b varchar(20) GENERATED ALWAYS AS (col2) VIRTUAL,
col6x int(11) GENERATED ALWAYS AS ((col2 % col1)) VIRTUAL,
col7 int(11) GENERATED ALWAYS AS ((col6x + col5x)) VIRTUAL,
col8 int(11) GENERATED ALWAYS AS ((col5x / col5)) VIRTUAL,
col7x int(11) GENERATED ALWAYS AS ((col5x + col5)) VIRTUAL,
col8x int(11) GENERATED ALWAYS AS ((col5 / col5x)) VIRTUAL,
col9 text,
col2b varchar(20) GENERATED ALWAYS AS (col4) VIRTUAL,
col8a int(11) GENERATED ALWAYS AS (col2) VIRTUAL,
col4b varchar(20) GENERATED ALWAYS AS (col4) VIRTUAL,
col1c int(11) GENERATED ALWAYS AS ((col2 * col1)) VIRTUAL,
extra int(11) DEFAULT NULL,
col5c int(11) GENERATED ALWAYS AS ((col1 / col1)) VIRTUAL,
col6a bigint(20) GENERATED ALWAYS AS ((col3 / col1)) VIRTUAL,
col1a varchar(20) GENERATED ALWAYS AS (col6) VIRTUAL,
col6c int(11) GENERATED ALWAYS AS ((col2 % col2)) VIRTUAL,
col7c bigint(20) GENERATED ALWAYS AS ((col2 / col1)) VIRTUAL,
col2c int(11) GENERATED ALWAYS AS ((col5 % col5)) VIRTUAL,
col1b int(11) GENERATED ALWAYS AS ((col1 / col2)) VIRTUAL,
col3b bigint(20) GENERATED ALWAYS AS ((col6x % col6)) VIRTUAL,
UNIQUE KEY idx7 (col1,col3,col2),
UNIQUE KEY uidx (col9(10)),
KEY idx15 (col9(10) DESC,col2 DESC),
KEY idx10 (col9(10) DESC,col1 DESC),
KEY idx11 (col6x DESC),
KEY idx6 (col9(10) DESC,col7 DESC),
KEY idx14 (col6 DESC)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col5x % col6x)
VIRTUAL, ADD FULLTEXT KEY ftidx ( col9 ), algorithm=inplace;
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
CREATE FULLTEXT INDEX idx ON t1(col9);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col5x % col6x)
VIRTUAL, ADD FULLTEXT KEY ftidx ( col9 ), algorithm=inplace;
DROP TABLE t1;
CREATE TABLE t1 (
col1 int(11) NOT NULL,
col2 int(11) DEFAULT NULL,
col3 int(11) NOT NULL,
col4 int(11) DEFAULT NULL) engine=innodb;
ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col1 % col2)
VIRTUAL, ADD UNIQUE index idx (col1), algorithm=inplace;
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
DROP TABLE t1;
#
# Bug#21869656 UNDO LOG DOES NOT CONTAIN ENOUGH INFORMATION
# ON INDEXED VIRTUAL COLUMNS
#
CREATE TABLE t1 (a INT, b INT,
a1 INT GENERATED ALWAYS AS (a) VIRTUAL, INDEX(a1)
) ENGINE=InnoDB;
INSERT INTO t1 (a,b) VALUES(1,1);
connect con1,localhost,root,,;
CREATE TABLE t0 (a INT) ENGINE=InnoDB;
BEGIN;
SELECT * FROM t0;
a
connection default;
UPDATE t1 SET a=0;
ALTER TABLE t1 DROP COLUMN a1, ALGORITHM=INPLACE;
ALTER TABLE t1 ADD COLUMN b1 INT GENERATED ALWAYS AS (b) VIRTUAL, ADD
INDEX(b1),
ALGORITHM=INPLACE;
connection con1;
COMMIT;
UPDATE t1 SET a=1;
connection default;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT b1 FROM t1;
b1
1
ALTER TABLE t1
ADD COLUMN a1 INT GENERATED ALWAYS AS (a) VIRTUAL,
ADD COLUMN a2 INT GENERATED ALWAYS AS (a + b) VIRTUAL,
ADD COLUMN a3 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
ADD COLUMN a4 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
ADD INDEX(a1), ADD INDEX(a2), ADD INDEX(a3), ALGORITHM=INPLACE;
CREATE TABLE t2 (
a BLOB,
b BLOB,
c BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
h VARCHAR(10) DEFAULT NULL
) ENGINE=InnoDB;
INSERT INTO t2 VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, 'kk');
INSERT INTO t2 VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
CREATE INDEX idx ON t2(c(100));
INSERT INTO t1 (a, b) VALUES(1,1);
connection con1;
BEGIN;
SELECT * FROM t0;
a
connection default;
UPDATE t1 SET a=0;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
UPDATE t1 SET b=0;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 DROP COLUMN a3, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 DROP COLUMN a2, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET b=3;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 ADD COLUMN b2 INT GENERATED ALWAYS AS (b) VIRTUAL,
ADD INDEX(b2), ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET b=9;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t1 ADD COLUMN b3 INT GENERATED ALWAYS AS (a) VIRTUAL,
ADD INDEX(b3), ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET b=10;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t2 DROP COLUMN c;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t2 SET a = REPEAT('s', 6000) WHERE a like 'aaa%';
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
ALTER TABLE t2 ADD COLUMN x1 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
ADD COLUMN x2 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
ADD INDEX(x1(100), x2(120)), ADD INDEX (x1(20));
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=5;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
UPDATE t2 SET a = REPEAT('m', 16000) WHERE a like 'sss%';
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
ALTER TABLE t1 DROP COLUMN b2, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=6;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
ALTER TABLE t2 DROP COLUMN x1, DROP COLUMN x2, ALGORITHM=INPLACE;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t2 SET a = REPEAT('x', 1000) WHERE a like 'mmm%';
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
ALTER TABLE t1 DROP INDEX b3;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=100;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
connection con1;
COMMIT;
disconnect con1;
connection default;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT b1 FROM t1;
b1
10
10
SELECT * FROM t1;
a b b1 a1 a4 b3
100 10 10 100 90 100
100 10 10 100 90 100
CHECK TABLE t2;
Table Op Msg_type Msg_text
test.t2 check status OK
DROP TABLE t2, t1, t0;
CREATE TABLE t1 (a VARCHAR(30), b INT, a2 VARCHAR(30) GENERATED ALWAYS AS (a) VIRTUAL);
CREATE INDEX idx ON t1(a2(10), b, a2(20));
ERROR 42S21: Duplicate column name 'a2'
DROP TABLE t1;
CREATE TABLE t_8114 (a int) ENGINE = INNODB;
ALTER TABLE t_8114 ADD b INT GENERATED ALWAYS AS (a) VIRTUAL;
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
NAME
test/t_8114
SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
NAME POS MTYPE PRTYPE LEN
a 0 6 1027 4
b 65537 6 9219 4
INSERT INTO t_8114 VALUES (9, default);
INSERT INTO t_8114 VALUES (3, default);
INSERT INTO t_8114 VALUES (1, default);
INSERT INTO t_8114 VALUES (5, default);
SELECT * FROM t_8114;
a b
9 9
3 3
1 1
5 5
DROP TABLE t_8114;
CREATE TABLE t_8114 (Column_1 CHAR(5) GENERATED ALWAYS AS (PI()+5), Column_2 CHAR(5)) engine=innodb;
SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
NAME FLAG N_COLS
test/t_8114 33 4
SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
NAME POS MTYPE PRTYPE LEN
Column_2 0 2 524542 5
Column_1 65536 2 532734 5
INSERT INTO t_8114 VALUES (default, "aa");
INSERT INTO t_8114 VALUES (default, "bb");
INSERT INTO t_8114 VALUES (default, "ee");
INSERT INTO t_8114 VALUES (default, "pp");
SELECT * FROM t_8114;
Column_1 Column_2
8.142 aa
8.142 bb
8.142 ee
8.142 pp
ALTER TABLE t_8114 DROP Column_1;
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
NAME
test/t_8114
SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
NAME POS MTYPE PRTYPE LEN
Column_2 0 2 524542 5
SELECT * FROM t_8114;
Column_2
aa
bb
ee
pp
DROP TABLE t_8114;
#
# Bug#22017616: ASSERTION FAILED: TABLE_SHARE->IS_MISSING_PRIMARY_KEY()
# == M_PREBUILT->CLUST_IND
#
# Ensure that adding indexes with virtual columns are not promoted to
# primary keys
#
# Base line with normal column - should be promoted
CREATE TABLE t0(a INT NOT NULL) ENGINE=INNODB;
ALTER TABLE t0 ADD UNIQUE INDEX (a);
# Case a: Create table with virtual unique not null column
CREATE TABLE t1(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL UNIQUE) ENGINE=INNODB;
SELECT * FROM t1;
a
# Case b: Create table with index on virtual point column
CREATE TABLE t2(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL, UNIQUE INDEX no_pk(a(1))) ENGINE=INNODB;
SELECT * FROM t2;
a
# Case c: Add unique index on virtual point column
CREATE TABLE t3(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL)
ENGINE=INNODB;
ALTER TABLE t3 ADD UNIQUE INDEX (a(1));
SELECT * FROM t3;
a
# Case d: Add unique index on virtual blob column
CREATE TABLE t4 (a BLOB, b BLOB GENERATED ALWAYS AS (a) VIRTUAL) ENGINE=INNODB;
ALTER TABLE t4 ADD UNIQUE INDEX (b(1));
SELECT * FROM t4;
a b
# Query I_S to verify that 'a' is promoted to pk only when it
# isn't virtual
SELECT T.NAME AS TABLE_NAME, I.NAME AS INDEX_NAME,
CASE (I.TYPE & 3)
WHEN 3 THEN "yes"
ELSE "no" END AS IS_PRIMARY_KEY,
F.NAME AS FIELD_NAME, F.POS AS FIELD_POS FROM
INFORMATION_SCHEMA.INNODB_SYS_TABLES AS T JOIN
INFORMATION_SCHEMA.INNODB_SYS_INDEXES AS I JOIN
INFORMATION_SCHEMA.INNODB_SYS_FIELDS AS F
ON I.INDEX_ID = F.INDEX_ID AND I.TABLE_ID = T.TABLE_ID
WHERE T.NAME LIKE 'test/%';
TABLE_NAME INDEX_NAME IS_PRIMARY_KEY FIELD_NAME FIELD_POS
test/t0 a yes a 0
test/t1 a no a 0
test/t2 no_pk no a 0
test/t3 a no a 0
test/t4 b no b 0
DROP TABLE t0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
CREATE DATABASE dump_generated;
USE dump_generated;
CREATE TABLE t1 (pk INTEGER, a INTEGER, b INTEGER, c VARCHAR(16),
sum INTEGER GENERATED ALWAYS AS (a+b),
sub VARCHAR(4) GENERATED ALWAYS AS (SUBSTRING(c, 1, 4)),
key k1(sum),
key k2(sub)
) engine=innodb;
INSERT INTO t1(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
SELECT * FROM t1;
pk a b c sum sub
1 11 12 oneone 23 oneo
2 21 22 twotwo 43 twot
DELETE FROM t1;
SELECT * FROM t1;
pk a b c sum sub
1 11 12 oneone 23 oneo
2 21 22 twotwo 43 twot
DELETE FROM t1;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t1;
SELECT * FROM t1;
pk a b c sum sub
1 11 12 oneone 23 oneo
2 21 22 twotwo 43 twot
DROP TABLE t1;
# A table with regular columns after generated
CREATE TABLE t2 (pk INTEGER, a INTEGER, b INTEGER,
sum INTEGER GENERATED ALWAYS AS (a+b),
c VARCHAR(16),
key k1(sum)
) engine=innodb;
INSERT INTO t2(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
SELECT * FROM t2;
pk a b sum c
1 11 12 23 oneone
2 21 22 43 twotwo
DELETE FROM t2;
SELECT * FROM t2;
pk a b sum c
1 11 12 23 oneone
2 21 22 43 twotwo
DELETE FROM t2;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t2.txt' INTO TABLE t2;
SELECT * FROM t2;
pk a b sum c
1 11 12 23 oneone
2 21 22 43 twotwo
DROP TABLE t2;
DROP DATABASE dump_generated;
This diff is collapsed.
......@@ -36,7 +36,7 @@ eval SET @@session.default_storage_engine = 'InnoDB';
#------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines
let $support_virtual_index= 0;
let $support_virtual_index= 1;
--source suite/gcol/inc/gcol_column_def_options.inc
#------------------------------------------------------------------------------#
......
......@@ -26,7 +26,8 @@ SELECT * FROM t;
BEGIN;
INSERT INTO t (a) VALUES (10);
--source include/kill_and_restart_mysqld.inc
--let $shutdown_timeout= 0
--source include/restart_mysqld.inc
SELECT * FROM t;
DROP TABLE t;
......@@ -103,6 +104,7 @@ connection default;
SELECT * FROM t;
DROP TABLE t;
SET DEBUG_SYNC = 'RESET';
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
--source include/have_innodb.inc
--source include/have_partition.inc
--echo #
--echo # Bug#22444530 - GCOLS + PARTITIONED TABLE, CRASH IN
--echo #
set sql_mode='';
create table t (
a int not null,
b int generated always as (1) virtual,
c int generated always as (1) virtual,
key (c)
) engine=innodb partition by key (a) partitions 2;
insert into t(a) values(1);
select b from t group by c;
drop table t;
# Make column b a BLOB
create table t (
a int not null,
b blob generated always as ("a") virtual,
c int generated always as (1) virtual,
key (c)
) engine=innodb partition by key (a) partitions 2;
insert into t(a) values(1);
select b from t group by c;
drop table t;
--source include/have_innodb.inc
--echo #Bug #22445211 GCOLS: SIMPLE DML, FAILING ASSERTION:
--echo #!CURSOR->INDEX->IS_COMMITTED()
--echo #Create and alter table examples for virtual column for full
--echo #column index followed by prefix index.
CREATE TABLE t1(
f1 INT DEFAULT NULL,
f2 CHAR(2) GENERATED ALWAYS AS ('11') VIRTUAL,
f3 INT,
UNIQUE KEY(f1),
UNIQUE KEY(f3,f1),
KEY(f2,f1),
key(f1,f2(1))
)ENGINE=INNODB;
REPLACE INTO t1(f3) VALUES (1),(1);
DROP TABLE t1;
This diff is collapsed.
--source include/have_innodb.inc
--echo #
--echo # Bug#22046353 ALTER: ASSERT PAGE_SIZE.EQUALS_TO(SPACE_PAGE_SIZE),
--echo # BTR_COPY_BLOB_PREFIX
--echo #
CREATE TABLE t1
( f1 int primary key, f2 blob,
f3 blob generated always as (f2))
row_format=compressed, engine=innodb;
insert into t1 (f1, f2) values (1, repeat('&', 50000));
alter table t1 add index i1 (f3(200)) ;
alter table t1 row_format=compact;
drop table t1;
--source include/have_innodb.inc
--source include/have_debug_sync.inc
--source include/have_debug.inc
--source include/count_sessions.inc
set default_storage_engine=innodb;
CREATE TABLE `t` (
`a` VARCHAR(100),
`b` VARCHAR(100),
`c` VARCHAR(200) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
`h` VARCHAR(10) DEFAULT NULL,
`i` int
) ENGINE=InnoDB;
INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 10), DEFAULT, "kk", 1);
INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
CREATE INDEX idx ON t(c(100));
SET session debug_dbug="+d,ib_alter_add_virtual_fail";
--error ER_WRONG_KEY_COLUMN
ALTER TABLE t ADD COLUMN x VARCHAR(200) GENERATED ALWAYS AS (a) VIRTUAL,
ALGORITHM = INPLACE;
--error ER_WRONG_KEY_COLUMN
ALTER TABLE t DROP COLUMN c, ALGORITHM = INPLACE;
SET session debug_dbug="";
DROP TABLE t;
#online test
CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (null, null, DEFAULT, "mx");
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
--send CREATE INDEX idx ON t(c)
connect (con1,localhost,root,,);
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
update t set a=0 where a = 11;
start transaction;
update t set a=1 where a = 0;
ROLLBACK;
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
reap;
SELECT c FROM t;
SHOW CREATE TABLE t;
SELECT * FROM t;
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
--send ALTER TABLE t ADD COLUMN x INT
connection con1;
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
start transaction;
update t set a=1 where a = 0;
rollback;
start transaction;
delete from t;
insert into t values(1,null,default,null);
rollback;
start transaction;
update t set b=b+1;
rollback;
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
reap;
check table t;
SELECT c FROM t;
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
--send ALTER TABLE t ADD COLUMN x2 INT
connection con1;
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
start transaction;
DELETE FROM t WHERE a = 0;
ROLLBACK;
DELETE FROM t WHERE a = 0;
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
reap;
SELECT c FROM t;
disconnect con1;
DROP TABLE t;
SET DEBUG_SYNC = 'RESET';
# Test add virtual column and add index at the same time
# introduce some error
CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
CREATE INDEX idx_1 on t(c);
SET SESSION debug_dbug="+d,create_index_fail";
--enable_info
--error ER_DUP_ENTRY
ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (x);
SET SESSION debug_dbug="";
--disable_info
SHOW CREATE TABLE t;
SELECT c FROM t;
DROP TABLE t;
--echo #
--echo # Bug#22018532 ASSERTION WHEN ONLINE REAPPLY REBUILD LOG ON
--echo # MULTIPLE INDEXED VIRTUAL COLUMNS
--echo #
create table t (
a int as (1) virtual,
b int,
c int as (1) virtual,
unique(b),
unique(c),
key(a)
) engine=innodb;
insert ignore into t values();
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
--send optimize table t
connect (con1,localhost,root,,);
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
insert ignore into t values();
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
--echo /* connection default */ optimize table t;
reap;
SELECT c FROM t;
SHOW CREATE TABLE t;
SELECT * FROM t;
DROP TABLE t;
# Do another test without duplicate error
CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
CREATE INDEX idx ON t(c);
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_rebuild WAIT_FOR go_ahead';
--send optimize table t
connection con1;
SET DEBUG_SYNC = 'now WAIT_FOR start_rebuild';
INSERT INTO t VALUES (48, 2, DEFAULT, 'xx');
INSERT INTO t VALUES (68, 3, DEFAULT, 'sx');
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
--echo /* connection default */ optimize table t;
reap;
SELECT c FROM t;
disconnect con1;
DROP TABLE t;
--echo #
--echo # Bug#22951879 - ASSERTS RELATED TO ONLINE DDL AND GCOL
--echo #
# Create a table with 2 virtual column, one (vbidxcol) is indexed and
# the other one (vbcol) is not
create table ibstd_14 (a int not null, d int not null, b varchar(198) not null, c char(181), vadcol int as (a+length(d)) stored, vbcol char(2) as (substr(b,2,2)) virtual, vbidxcol char(3) as (substr(b,1,3)) virtual , index(d), index(a), index(vbidxcol), index(a,vbidxcol), index(vbidxcol,d), unique key (b(10), a, d), index(c(99), b(31)), index(b(5), c(10), a) , index(a,d)) engine=InnoDB stats_persistent=1 row_format=dynamic;
# Do an alter table rebuild table and also create a new index on this
# non-indexed virtual column
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
--send alter table ibstd_14 row_format=compressed key_block_size=4,add key kn3 (d,c,vbcol,b)
# Do a concurrent insert, and make sure this newly indexed virtual column
# is also logged
connect (con1,localhost,root);
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
insert into ibstd_14 (a,d,b,c, vbidxcol, vbcol) values ('118','6',repeat('oacolaarlruoacuroauurloraarucoooarcooauoolacalllaulrruarrrucruuooclacuoouccarrcoocloccorrrrarourcooalloocooccouruolaorlcaocualolc','1'),repeat('lolrrlalcocroraaulauclaaucolcorcuooaolruaooooluooooouaoorlarucorullalcrrloccououaooaorluorraclrcooouuolocoaolcocaaculruoocucoocoooauuolarcoraraocaoolulolarru','1'),default,default);
insert into ibstd_14 (a,d,b,c, vbidxcol, vbcol) values ('118','6', 'aaaa', 'lll', default, default);
# Also do an concurrent update, make sure this is performed
update ibstd_14 set b='11111' where b='aaaa';
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
connection default;
reap;
select * from ibstd_14;
# This will use the newly added "kn3" index, to check materialized vbcol
# after log reapply
select d,c,vbcol,b from ibstd_14;
# check the value is inserted into the index
select vbcol from ibstd_14;
drop table ibstd_14;
disconnect con1;
SET DEBUG_SYNC = 'RESET';
--source include/wait_until_count_sessions.inc
--source include/have_innodb.inc
--source include/have_debug_sync.inc
--source include/have_debug.inc
--source include/have_partition.inc
set default_storage_engine=innodb;
set @old_dbug=@@global.debug_dbug;
CREATE TABLE `t` (
`a` BLOB,
`b` BLOB,
`c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
`h` VARCHAR(10) DEFAULT NULL,
`i` int
) ENGINE=InnoDB;
INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, "kk", 1);
INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, "mm", 2);
CREATE INDEX idx ON t(c(100));
SET global debug_dbug="+d,ib_purge_virtual_index_callback";
UPDATE t SET a = REPEAT('m', 16000) WHERE a like "aaa%";
select sleep(3);
SET global debug_dbug=@old_dbug;
DROP TABLE t;
CREATE TABLE t (
a TINYBLOB,
b TINYBLOB,
c TINYBLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
h VARCHAR(10) DEFAULT NULL,
i INT
) ROW_FORMAT=COMPACT ENGINE=InnoDB;
INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 100), DEFAULT, "kk", 1);
INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
CREATE INDEX idx ON t(c(100));
SET global debug_dbug="+d,ib_purge_virtual_index_callback";
UPDATE t SET a = REPEAT('m', 100) WHERE a like "aaa%";
select sleep(3);
SET global debug_dbug=@old_dbug;
DROP TABLE t;
CREATE TABLE t1 (
id INT NOT NULL,
store_id INT NOT NULL,
x INT GENERATED ALWAYS AS (id + store_id)
)
PARTITION BY RANGE (store_id) (
PARTITION p0 VALUES LESS THAN (6),
PARTITION p1 VALUES LESS THAN (11),
PARTITION p2 VALUES LESS THAN (16),
PARTITION p3 VALUES LESS THAN (21)
);
insert into t1 values(1, 2, default);
insert into t1 values(3, 4, default);
insert into t1 values(3, 12, default);
insert into t1 values(4, 18, default);
CREATE INDEX idx ON t1(x);
SET global debug_dbug="+d,ib_purge_virtual_index_callback";
UPDATE t1 SET id = 10 WHERE id = 1;
select sleep(3);
SET global debug_dbug=@old_dbug;
DROP TABLE t1;
#
# BUG#22082762 RE-ENABLE SUPPORT FOR ADDING VIRTUAL INDEX WHILE DROPPING VIRTUAL COLUMN
#
--source include/count_sessions.inc
connect (con1,localhost,root,,);
connection default;
# Test adding virtual index on newly added virtual column
CREATE TABLE t1 (a INT, b INT);
INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3);
connection con1;
--echo # disable purge
CREATE TABLE t0 (a INT) ENGINE=InnoDB;
BEGIN; SELECT * FROM t0;
connection default;
DELETE FROM t1 WHERE a = 1;
UPDATE t1 SET a = 4, b = 4 WHERE a = 3;
INSERT INTO t1(a, b) VALUES (5, 5);
SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
send ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
connection con1;
SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
--echo # enable purge
COMMIT;
--echo # wait for purge to process the deleted records.
--source include/wait_innodb_all_purged.inc
SET DEBUG_SYNC= 'now SIGNAL purged';
connection default;
--echo /* connection default */ ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
--reap
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
# Test adding virutal index on existing virtual column
CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b));
INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3), (4, 4);
connection con1;
--echo # disable purge
BEGIN; SELECT * FROM t0;
connection default;
DELETE FROM t1 WHERE a = 1;
UPDATE t1 SET a = 2, b = 2 WHERE a = 5;
INSERT INTO t1(a, b) VALUES (6, 6);
SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
send ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
connection con1;
SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
DELETE FROM t1 WHERE a = 3;
UPDATE t1 SET a = 7, b = 7 WHERE a = 4;
INSERT INTO t1(a, b) VALUES (8, 8);
--echo # enable purge
COMMIT;
--echo # wait for purge to process the deleted/updated records.
--source include/wait_innodb_all_purged.inc
SET DEBUG_SYNC= 'now SIGNAL purged';
disconnect con1;
connection default;
--echo /* connection default */ ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
--reap
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t0, t1;
--source include/wait_until_count_sessions.inc
set debug_sync=reset;
This diff is collapsed.
-- source include/have_innodb.inc
-- source include/not_embedded.inc
--echo #
--echo # Bug#22469130: FOREIGN KEY ON DELETE CASCADE NOT ALLOWED
--echo # WHEN A VIRTUAL INDEX EXISTS.
--echo # Add the VIRTUAL INDEX contains fk constraINT column
--echo # using INPLACE alter operatiON
CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
fld3 INT AS (fld2) VIRTUAL, KEY(fld1),
FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE) engine=innodb;
INSERT INTO t1(fld1) VALUES(1);
INSERT INTO t2(fld1, fld2) VALUES(1, 2);
--source include/restart_mysqld.inc
UPDATE t1 SET fld1= 2;
SELECT fld3, fld1 FROM t2;
alter TABLE t2 ADD INDEX vk(fld3, fld1), ALGORITHM=INPLACE;
UPDATE t1 SET fld1=3;
SELECT fld3, fld1 FROM t2;
DROP TABLE t2, t1;
--echo # TEMPORARY TABLE NAME and CHILD TABLE NAME are same
CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
CREATE TABLE t2(fld1 INT NOT NULL,
fld2 INT AS (fld1) VIRTUAL,
KEY(fld2),
FOREIGN KEY(fld1) REFERENCES t1(fld1)
ON UPDATE CASCADE) engine=innodb;
INSERT INTO t1 VALUES(1), (2);
INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
--source include/restart_mysqld.inc
CREATE TEMPORARY TABLE t2 (fld1 INT NOT NULL)ENGINE=INNODB;
UPDATE t1 SET fld1= 3 WHERE fld1= 2;
--connect(con1,localhost,root,,test)
SELECT fld2 FROM t2;
CHECK TABLE t2;
connection default;
disconnect con1;
DROP TABLE t2;
DROP TABLE t2, t1;
This diff is collapsed.
This diff is collapsed.
--source include/have_innodb.inc
# Test alter table add column
CREATE TABLE t_8114 (a int) ENGINE = INNODB;
ALTER TABLE t_8114 ADD b INT GENERATED ALWAYS AS (a) VIRTUAL;
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
INSERT INTO t_8114 VALUES (9, default);
INSERT INTO t_8114 VALUES (3, default);
INSERT INTO t_8114 VALUES (1, default);
INSERT INTO t_8114 VALUES (5, default);
SELECT * FROM t_8114;
DROP TABLE t_8114;
CREATE TABLE t_8114 (Column_1 CHAR(5) GENERATED ALWAYS AS (PI()+5), Column_2 CHAR(5)) engine=innodb;
SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
INSERT INTO t_8114 VALUES (default, "aa");
INSERT INTO t_8114 VALUES (default, "bb");
INSERT INTO t_8114 VALUES (default, "ee");
INSERT INTO t_8114 VALUES (default, "pp");
SELECT * FROM t_8114;
ALTER TABLE t_8114 DROP Column_1;
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
SELECT * FROM t_8114;
DROP TABLE t_8114;
--source include/have_innodb.inc
--echo #
--echo # Bug#22017616: ASSERTION FAILED: TABLE_SHARE->IS_MISSING_PRIMARY_KEY()
--echo # == M_PREBUILT->CLUST_IND
--echo #
--echo # Ensure that adding indexes with virtual columns are not promoted to
--echo # primary keys
--echo #
--echo # Base line with normal column - should be promoted
CREATE TABLE t0(a INT NOT NULL) ENGINE=INNODB;
ALTER TABLE t0 ADD UNIQUE INDEX (a);
--echo # Case a: Create table with virtual unique not null column
CREATE TABLE t1(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL UNIQUE) ENGINE=INNODB;
SELECT * FROM t1;
--echo # Case b: Create table with index on virtual point column
CREATE TABLE t2(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL, UNIQUE INDEX no_pk(a(1))) ENGINE=INNODB;
SELECT * FROM t2;
--echo # Case c: Add unique index on virtual point column
CREATE TABLE t3(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL)
ENGINE=INNODB;
ALTER TABLE t3 ADD UNIQUE INDEX (a(1));
SELECT * FROM t3;
--echo # Case d: Add unique index on virtual blob column
CREATE TABLE t4 (a BLOB, b BLOB GENERATED ALWAYS AS (a) VIRTUAL) ENGINE=INNODB;
ALTER TABLE t4 ADD UNIQUE INDEX (b(1));
SELECT * FROM t4;
--echo # Query I_S to verify that 'a' is promoted to pk only when it
--echo # isn't virtual
SELECT T.NAME AS TABLE_NAME, I.NAME AS INDEX_NAME,
CASE (I.TYPE & 3)
WHEN 3 THEN "yes"
ELSE "no" END AS IS_PRIMARY_KEY,
F.NAME AS FIELD_NAME, F.POS AS FIELD_POS FROM
INFORMATION_SCHEMA.INNODB_SYS_TABLES AS T JOIN
INFORMATION_SCHEMA.INNODB_SYS_INDEXES AS I JOIN
INFORMATION_SCHEMA.INNODB_SYS_FIELDS AS F
ON I.INDEX_ID = F.INDEX_ID AND I.TABLE_ID = T.TABLE_ID
WHERE T.NAME LIKE 'test/%';
DROP TABLE t0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
This diff is collapsed.
......@@ -15,3 +15,4 @@ thread/innodb/srv_lock_timeout_thread BACKGROUND NULL NULL NULL NULL NULL NULL N
thread/innodb/srv_master_thread BACKGROUND NULL NULL NULL NULL NULL NULL NULL NULL NULL YES
thread/innodb/srv_monitor_thread BACKGROUND NULL NULL NULL NULL NULL NULL NULL NULL NULL YES
thread/innodb/srv_purge_thread BACKGROUND NULL NULL NULL NULL NULL NULL NULL NULL NULL YES
thread/innodb/thd_destructor_thread BACKGROUND NULL NULL NULL NULL NULL NULL NULL 1 NULL YES
......@@ -41,6 +41,7 @@ SET @@session.storage_engine = 'InnoDB';
#------------------------------------------------------------------------------#
# Execute the tests to be applied to all storage engines
let $with_foreign_keys = 1;
--source suite/vcol/inc/vcol_keys.inc
#------------------------------------------------------------------------------#
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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