mariadb/mysql-test/t/information_schema_inno.test
Jon Olav Hauglid bbaae9a2dc Bug #55973 Assertion `thd->transaction.stmt.is_empty()'
on CREATE TABLE .. SELECT I_S.PART

This assert was triggered if an InnoDB table was created using
CREATE TABLE ... AS SELECT where the query used an I_S table, and
a view existed in the database. It would also be triggered for
any statement changing an InnoDB table (e.g. INSERT, UPDATE, DELETE)
which had a subquery referencing an I_S table.

The assert was triggered if open_normal_and_derived_tables() failed
and a statement transaction had been started. This will usually not
happen as tables are opened before a statement transaction is started.
However, e.g. CREATE TABLE ... AS SELECT starts a transaction in order
to insert tuples into the new table. And if the subquery references
an I_S table, all current tables and views can be opened in order to
fill the I_S table on the fly. If a view is discovered, open will fail
as it is instructed to open tables only (OPEN_TABLE_ONLY). This would
cause the assert to be triggered.

The assert was added in the patch for Bug#52044 and was therefore
not in any released versions of the server.

This patch fixes the problem by adjusting the assert to take into
consideration the possibility of tables being opened as part of
an I_S query. This is similar to what is already done for 
close_tables_for_reopen().

Test case added to information_schema_inno.test.
2010-08-20 09:16:26 +02:00

111 lines
3.6 KiB
Text

-- source include/testdb_only.inc
-- source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
--enable_warnings
#
# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables
#
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id, id),
FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE,
FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB;
CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id),
FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id) ON DELETE CASCADE) ENGINE=INNODB;
select * from information_schema.TABLE_CONSTRAINTS where
TABLE_SCHEMA= "test";
select * from information_schema.KEY_COLUMN_USAGE where
TABLE_SCHEMA= "test";
drop table t3, t2, t1;
#
# Test for REFERENTIAL_CONSTRAINTS table
#
CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
PRIMARY KEY(a1, a2)) ENGINE=INNODB;
CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
CONSTRAINT A1
FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
CREATE TABLE t3(b1 INT, b2 INT, INDEX t3_indx (b1, b2),
CONSTRAINT A2
FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
CREATE TABLE t4(b1 INT, b2 INT, UNIQUE KEY t4_ukey (b1, b2),
CONSTRAINT A3
FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
CONSTRAINT A4
FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
MATCH_OPTION, UPDATE_RULE, DELETE_RULE, b.REFERENCED_TABLE_NAME
from information_schema.TABLE_CONSTRAINTS a,
information_schema.REFERENTIAL_CONSTRAINTS b
where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
drop tables t5, t4, t3, t2, t1;
#
# Bug#25026 `information_schema.KEY_COLUMN_USAGE`.`REFERENCED_TABLE_NAME` returns garbage
#
create database `db-1`;
use `db-1`;
create table `t-2` (
id int(10) unsigned not null auto_increment,
primary key (id)
) engine=innodb;
create table `t-1` (
id int(10) unsigned not null auto_increment,
idtype int(10) unsigned not null,
primary key (id),
key fk_t1_1 (idtype),
constraint fk_t1_1 foreign key (idtype) references `t-2` (id)
) engine=innodb;
use test;
select referenced_table_schema, referenced_table_name
from information_schema.key_column_usage
where constraint_schema = 'db-1';
drop database `db-1`;
#
# Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes
#
create table t1(id int primary key) engine = Innodb;
create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb;
set foreign_key_checks = 0;
drop table t1;
select UNIQUE_CONSTRAINT_NAME
from information_schema.referential_constraints
where constraint_schema = schema();
drop table t2;
set foreign_key_checks = 1;
--echo #
--echo # Bug#55973 Assertion `thd->transaction.stmt.is_empty()'
--echo # on CREATE TABLE .. SELECT I_S.PART
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP VIEW IF EXISTS v1;
--enable_warnings
CREATE VIEW v1 AS SELECT 1;
# This used to case an assert.
CREATE TABLE t1 engine = InnoDB AS
SELECT * FROM information_schema.partitions
WHERE table_schema= 'test' AND table_name= 'v1';
DROP TABLE t1;
DROP VIEW v1;