Commit 0b7d1748 authored by Anel Husakovic's avatar Anel Husakovic Committed by Sergei Golubchik

MDEV-12459 Get temporary tables visible to the IS.tables for current connection

Additionally fixes the bugs uncovered in:
  - `MDEV-28332: Alter on temporary table causes ER_TABLE_EXISTS_ERROR note`
    Since there is no `warning` issued by shadowing of base table, this MDEV
    is irrelevant. Keeping for review purposes and for future development
    in case shadowing is going to be implemented
  - `MDEV-28334: SHOW TABLE STATUS shows all temporary tables ignoring database and conditions`
  - `MDEV-28453: SHOW commands are inconsistent for temporary tables`

Reviewed by: <monty@mariadb.org>,
             <vicentiu@mariadb.org>
parent 1c052e90
......@@ -991,10 +991,14 @@ CREATE TEMPORARY TABLE `#sql1` (c1 INT);
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
SHOW TABLES;
Tables_in_test
@0023sql2
#sql1
ALTER TABLE `#sql1` RENAME `@0023sql1`;
ALTER TABLE `@0023sql2` RENAME `#sql2`;
SHOW TABLES;
Tables_in_test
#sql2
@0023sql1
INSERT INTO `#sql2` VALUES (1);
INSERT INTO `@0023sql1` VALUES (2);
SHOW CREATE TABLE `#sql2`;
......
......@@ -9,6 +9,7 @@ CREATE OR REPLACE TABLE t1 LIKE tmp;
SET debug_dbug=@old_debug;
SHOW TABLES;
Tables_in_test
tmp
t1
show create table t1;
Table Create Table
......
......@@ -260,10 +260,13 @@ connect con1,localhost,foo,,db;
create temporary table tmp (a int, key(a));
show tables;
Tables_in_db
tmp
show full tables;
Tables_in_db Table_type
tmp TEMPORARY TABLE
show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
tmp MyISAM 10 Fixed 0 0 X X X X X X X X latin1_swedish_ci NULL X Y
show index in tmp;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
tmp 1 a 1 a A NULL NULL NULL YES BTREE NO
......
......@@ -225,6 +225,7 @@ grant create temporary tables on db.* to bar@localhost;
create temporary table tmp (a int, key(a));
show tables;
show full tables;
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X 19 X
show table status;
show index in tmp;
show columns in tmp;
......
#
# MDEV-12459: The information_schema tables for getting temporary tables
# info is missing, at least for innodb, there is no
# INNODB_TEMP_TABLE_INFO
#
# -------------------------------
# Test shadowing of a base table
# -------------------------------
create database some_db;
use some_db;
# Creating temporary table with the same name shadows the base table
# in `show create` and by design, should not raise any warning
create table t(t int);
create temporary table t(t int);
show create table t;
Table Create Table
t CREATE TEMPORARY TABLE `t` (
`t` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
select table_schema, table_name, temporary from information_schema.tables where table_name='t';
table_schema table_name temporary
some_db t Y
some_db t N
drop table t;
drop table t;
use test;
# ------------------------
# IS.tables tests
# ------------------------
# Create first temporary table
create temporary table test.t_temp(t int);
insert into t_temp values (1),(2), (3);
# Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary';
table_schema table_name temporary
test t_temp Y
# Create the base table with the same name (both should be visible)
create table test.t_temp(t int);
insert into t_temp values (-1),(-2);
# Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary';
table_schema table_name temporary
test t_temp Y
create database my_db;
# Create the temporary table with the same name in new DB
create temporary table my_db.t_temp (t int);
insert into my_db.t_temp values (-2),(-1);
# Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
table_schema table_name temporary
test t_temp Y
my_db t_temp Y
connect con1,localhost,root,,my_db,,;
# Create the temporary table with the same name in new connection
create temporary table t_temp(t int);
insert into t_temp values (4),(5),(6), (7);
# Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
table_schema table_name temporary
my_db t_temp Y
connection default;
# Show results in default connection
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
table_schema table_name temporary
test t_temp Y
my_db t_temp Y
# Check shadowing and (no)warning with explicit referencing database
create table some_db.my_t (t int);
show warnings;
Level Code Message
create temporary table some_db.my_t (t int);
show warnings;
Level Code Message
# Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
table_schema table_name temporary
test t_temp Y
some_db my_t Y
my_db t_temp Y
use test;
create table t1 (a int);
create sequence s1;
create temporary table t1 (b int);
create temporary sequence s1;
create temporary sequence s2;
select table_schema, table_name, table_type, temporary from information_schema.tables where table_schema = 'test'
order by table_schema desc, table_name desc, table_type desc;
table_schema table_name table_type temporary
test t_temp TEMPORARY Y
test t_temp BASE TABLE N
test t1 TEMPORARY Y
test t1 BASE TABLE N
test s2 TEMPORARY SEQUENCE Y
test s1 TEMPORARY SEQUENCE Y
test s1 SEQUENCE N
drop table t1;
drop table t1;
drop table s1;
drop table s1;
drop table s2;
drop table some_db.my_t;
drop table some_db.my_t;
disconnect con1;
drop table test.t_temp;
drop table test.t_temp;
drop database my_db;
drop database some_db;
#
# MDEV-28332: Alter on temporary table causes ER_TABLE_EXISTS_ERROR note
#
create table t (a int);
create temporary table t (b int);
alter table t add c int;
drop temporary table t;
drop table t;
#
# MDEV-28334: SHOW TABLE STATUS shows all temporary tables
# ignoring database and conditions
#
create temporary table test.tmp_in_test (a int);
create table test.base_in_test (t int);
create table test.tmp_in_test (t int);
create temporary table test.tmp_innodb_in_test (a int) engine=InnoDB;
create database mysqltest;
use mysqltest;
show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
show table status in mysqltest;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
show table status in test;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
tmp_innodb_in_test InnoDB 10 Dynamic 0 0 16384 0 0 6291456 NULL # # # latin1_swedish_ci NULL 0 Y
tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 Y
base_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N
tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N
show table status from test;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
tmp_innodb_in_test InnoDB 10 Dynamic 0 0 16384 0 0 6291456 NULL # # # latin1_swedish_ci NULL 0 Y
tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 Y
base_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N
tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N
# check that InnoDB temporary table
# has a NULL value for `Create time` column (MDEV-28333)
select create_time from information_schema.tables where table_name='tmp_innodb_in_test';
create_time
NULL
show table status like 'nonexisting';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
drop database mysqltest;
drop table test.base_in_test;
drop table test.tmp_in_test;
drop table test.tmp_in_test;
#
# MDEV-28453: SHOW commands are inconsistent for temporary tables
#
create database mysqltest;
use mysqltest;
create table t (a int, key(a)) engine=Aria;
create temporary table t (b int, key(b)) engine=MyISAM;
create table base_table(t int);
create temporary table tmp_table (b int, key(b));
create sequence s1;
create temporary sequence s1;
create temporary sequence s2;
show tables;
Tables_in_mysqltest
s2
s1
tmp_table
t
base_table
s1
t
show full tables;
Tables_in_mysqltest Table_type
s2 TEMPORARY SEQUENCE
s1 TEMPORARY SEQUENCE
tmp_table TEMPORARY TABLE
t TEMPORARY TABLE
base_table BASE TABLE
s1 SEQUENCE
t BASE TABLE
show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary
s2 MyISAM 10 Fixed 1 58 58 16325548649218047 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 Y
s1 MyISAM 10 Fixed 1 58 58 16325548649218047 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 Y
tmp_table MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 288230376151710720 Y
t MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 288230376151710720 Y
base_table MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N
s1 MyISAM 10 Fixed 1 58 58 16325548649218047 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N
t Aria 10 Page 0 0 8192 17592186011648 8192 0 NULL # # # latin1_swedish_ci NULL transactional=1 9007199254732800 N
show columns in t;
Field Type Null Key Default Extra
b int(11) YES MUL NULL
show index in t;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
t 1 b 1 b A NULL NULL NULL YES BTREE NO
drop database mysqltest;
--echo #
--echo # MDEV-12459: The information_schema tables for getting temporary tables
--echo # info is missing, at least for innodb, there is no
--echo # INNODB_TEMP_TABLE_INFO
--echo #
# Save the initial number of concurrent sessions
--source include/count_sessions.inc
--source include/have_innodb.inc
--echo # -------------------------------
--echo # Test shadowing of a base table
--echo # -------------------------------
create database some_db;
use some_db;
--echo # Creating temporary table with the same name shadows the base table
--echo # in `show create` and by design, should not raise any warning
create table t(t int);
create temporary table t(t int);
show create table t;
select table_schema, table_name, temporary from information_schema.tables where table_name='t';
drop table t;
drop table t;
use test;
--echo # ------------------------
--echo # IS.tables tests
--echo # ------------------------
--echo # Create first temporary table
create temporary table test.t_temp(t int);
insert into t_temp values (1),(2), (3);
--echo # Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary';
--echo # Create the base table with the same name (both should be visible)
# Create the base table with the same name as temporary table.
create table test.t_temp(t int);
insert into t_temp values (-1),(-2);
--echo # Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary';
create database my_db;
--echo # Create the temporary table with the same name in new DB
create temporary table my_db.t_temp (t int);
insert into my_db.t_temp values (-2),(-1);
--echo # Show results
--horizontal_results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
connect (con1,localhost,root,,my_db,,);
--echo # Create the temporary table with the same name in new connection
create temporary table t_temp(t int);
insert into t_temp values (4),(5),(6), (7);
--echo # Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
connection default;
--echo # Show results in default connection
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
--echo # Check shadowing and (no)warning with explicit referencing database
create table some_db.my_t (t int);
show warnings;
create temporary table some_db.my_t (t int);
show warnings;
--echo # Show results
select table_schema, table_name, temporary from information_schema.tables where table_type='temporary'
order by table_schema desc, table_name desc, table_type desc;
# Check with sequences
use test;
create table t1 (a int);
create sequence s1;
create temporary table t1 (b int);
create temporary sequence s1;
create temporary sequence s2;
select table_schema, table_name, table_type, temporary from information_schema.tables where table_schema = 'test'
order by table_schema desc, table_name desc, table_type desc;
drop table t1;
drop table t1;
drop table s1;
drop table s1;
drop table s2;
# First we are removing temporary table and after base table
drop table some_db.my_t;
drop table some_db.my_t;
disconnect con1;
# Drop both temporary and "real" table from test.
drop table test.t_temp;
drop table test.t_temp;
drop database my_db;
drop database some_db;
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
--echo #
--echo # MDEV-28332: Alter on temporary table causes ER_TABLE_EXISTS_ERROR note
--echo #
create table t (a int);
create temporary table t (b int);
alter table t add c int;
# Cleanup
drop temporary table t;
drop table t;
--echo #
--echo # MDEV-28334: SHOW TABLE STATUS shows all temporary tables
--echo # ignoring database and conditions
--echo #
create temporary table test.tmp_in_test (a int);
create table test.base_in_test (t int);
# The base table with the same name as temporary table
create table test.tmp_in_test (t int);
# The temporary InnoDB table - CREATE TIME should be NULL, MDEV-28333
create temporary table test.tmp_innodb_in_test (a int) engine=InnoDB;
create database mysqltest;
use mysqltest;
# This should show tables from currently used DB
# no temporary tables created and empty result set should be returned
show table status;
# The same as before
show table status in mysqltest;
# The should show all ables from `test` DB
--replace_column 12 # 13 # 14 #
--horizontal_results
show table status in test;
# The same as before
--replace_column 12 # 13 # 14 #
--horizontal_results
show table status from test;
--echo # check that InnoDB temporary table
--echo # has a NULL value for `Create time` column (MDEV-28333)
select create_time from information_schema.tables where table_name='tmp_innodb_in_test';
# This shouldn't give any results
show table status like 'nonexisting';
# Cleanup
drop database mysqltest;
drop table test.base_in_test;
# We need first to drop temporary table that shadows the base table
drop table test.tmp_in_test;
drop table test.tmp_in_test;
--echo #
--echo # MDEV-28453: SHOW commands are inconsistent for temporary tables
--echo #
create database mysqltest;
use mysqltest;
create table t (a int, key(a)) engine=Aria;
create temporary table t (b int, key(b)) engine=MyISAM;
create table base_table(t int);
create temporary table tmp_table (b int, key(b));
create sequence s1;
create temporary sequence s1;
create temporary sequence s2;
# This should show all tables
show tables;
# This should show all tables with additional table_type
show full tables;
# This is already showing all tables (not related to bug)
--replace_column 12 # 13 # 14 #
show table status;
# This is showing temporary table as expected since it is shadowing base table
show columns in t;
# This is showing temporary table as expected since it is shadowing base table
show index in t;
# Cleanup
drop database mysqltest;
......@@ -5482,6 +5482,8 @@ Warnings:
Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
SHOW TABLES FROM bug25717383;
Tables_in_bug25717383
temp
one
tab
one
view
......@@ -5503,6 +5505,8 @@ proc
one
SHOW TABLES FROM bug25717383;
Tables_in_bug25717383
temp
one
tab
one
view
......
......@@ -106,6 +106,8 @@ rename table t2 to tmp, tmp to t2;
rename table t1_tmp to tmp, tmp to t1_tmp;
show tables;
Tables_in_test
t2
t1_tmp
t1_tmp
t2
SHOW CREATE TABLE t1_tmp;
......
......@@ -329,6 +329,7 @@ i
1
SHOW TABLES;
Tables_in_temp_db
temp_t1
DROP TABLE temp_t1;
#
# Create and drop a temporary table.
......
......@@ -2,6 +2,7 @@ DROP TABLE IF EXISTS t5;
CREATE TEMPORARY TABLE t5(c1 BIT(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -13,6 +14,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 TINYINT(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -24,6 +26,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 SMALLINT(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -35,6 +38,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 MEDIUMINT(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -46,6 +50,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 INT(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -57,6 +62,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 INTEGER(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -68,6 +74,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 BIGINT(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -79,6 +86,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 CHAR(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -90,6 +98,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 VARCHAR(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -101,6 +110,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 BINARY(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -112,6 +122,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 VARBINARY(10) NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -123,6 +134,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 BIT(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -134,6 +146,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 TINYINT(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -145,6 +158,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 SMALLINT(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -156,6 +170,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 MEDIUMINT(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -167,6 +182,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 INT(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -178,6 +194,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 INTEGER(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -189,6 +206,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 BIGINT(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -200,6 +218,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 CHAR(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -211,6 +230,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 VARCHAR(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -222,6 +242,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 BINARY(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......@@ -233,6 +254,7 @@ Tables_in_test
CREATE TEMPORARY TABLE t5(c1 VARBINARY(10) NOT NULL);
SHOW TABLES;
Tables_in_test
t5
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TEMPORARY TABLE `t5` (
......
......@@ -387,6 +387,8 @@ ENGINE = <other_engine_type>
AS SELECT 1;
SELECT table_name, table_type FROM information_schema.tables
WHERE table_name = 't1_my_tablex';
table_name t1_my_tablex
table_type TEMPORARY
DROP TEMPORARY TABLE test.t1_my_tablex;
CREATE TABLE db_datadict.t1_my_tablex
ENGINE = <engine_type> AS
......
......@@ -395,6 +395,8 @@ ENGINE = <other_engine_type>
AS SELECT 1;
SELECT table_name, table_type FROM information_schema.tables
WHERE table_name = 't1_my_tablex';
table_name t1_my_tablex
table_type TEMPORARY
DROP TEMPORARY TABLE test.t1_my_tablex;
CREATE TABLE db_datadict.t1_my_tablex
ENGINE = <engine_type> AS
......
......@@ -343,6 +343,7 @@ TEST-INFO: SLAVE: The INSERT is committed (Succeeded)
connection master;
SHOW TABLES LIKE 't2';
Tables_in_mysqltest1 (t2)
t23
connection slave;
SHOW TABLES LIKE 't2';
Tables_in_mysqltest1 (t2)
......
......@@ -243,6 +243,11 @@ Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
SHOW TABLES;
Tables_in_test
tt7
tt6
tt5
tt4
tt3
t1
t2
t3
......
......@@ -6,6 +6,7 @@ CREATE TABLE t2 (a int);
CREATE TEMPORARY TABLE t2 (a int, b int);
SHOW TABLES;
Tables_in_test
t2
t1
t2
connection slave;
......@@ -28,6 +29,7 @@ connection master;
CREATE TEMPORARY TABLE t2 (a int, b int);
SHOW TABLES;
Tables_in_test
t2
t1
t2
connection slave;
......
......@@ -70,6 +70,7 @@
#include "lex_symbol.h"
#define KEYWORD_SIZE 64
#define IS_USER_TEMP_TABLE(A) (A->tmp_table != NO_TMP_TABLE)
extern SYMBOL symbols[];
extern size_t symbols_length;
......@@ -161,6 +162,7 @@ static const LEX_CSTRING *view_algorithm(TABLE_LIST *table);
bool get_lookup_field_values(THD *, COND *, bool, TABLE_LIST *,
LOOKUP_FIELD_VALUES *);
void process_i_s_table_temporary_tables(THD *thd, TABLE * table, TABLE *tmp_tbl);
/**
Try to lock a mutex, but give up after a short while to not cause deadlocks
......@@ -5189,6 +5191,7 @@ class Warnings_only_error_handler : public Internal_error_handler
}
};
/**
@brief Fill I_S tables whose data are retrieved
from frm files and storage engine
......@@ -5329,6 +5332,49 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
#endif
{
Dynamic_array<LEX_CSTRING*> table_names(PSI_INSTRUMENT_MEM);
/* Separate handling for session temporary tables from the backup state
for table IS.tables and SHOW TABLES commands.
*/
if ((schema_table_idx == SCH_TABLES || schema_table_idx == SCH_TABLE_NAMES) &&
open_tables_state_backup.temporary_tables)
{
All_tmp_tables_list::Iterator it(*open_tables_state_backup.temporary_tables);
TMP_TABLE_SHARE *share_temp;
while ((share_temp= it++))
{
DBUG_ASSERT(IS_USER_TEMP_TABLE(share_temp));
if (my_strcasecmp(system_charset_info, db_name->str,
share_temp->db.str))
continue;
All_share_tables_list::Iterator it2(share_temp->all_tmp_tables);
while (TABLE *tmp_tbl= it2++)
{
if (schema_table_idx == SCH_TABLE_NAMES)
{
LEX_CSTRING *table_name= &tmp_tbl->s->table_name;
restore_record(table, s->default_values);
table->field[schema_table->idx_field1]->
store(db_name->str, db_name->length, system_charset_info);
table->field[schema_table->idx_field2]->
store(table_name->str, table_name->length,
system_charset_info);
if (tmp_tbl->s->table_type == TABLE_TYPE_SEQUENCE)
table->field[3]->store(STRING_WITH_LEN("TEMPORARY SEQUENCE"),
system_charset_info);
else
table->field[3]->store(STRING_WITH_LEN("TEMPORARY TABLE"),
system_charset_info);
schema_table_store_record(thd, table);
}
else /* SCH_TABLE */
{
process_i_s_table_temporary_tables(thd, table, tmp_tbl);
}
}
}
}
int res= make_table_name_list(thd, &table_names, lex,
&plan->lookup_field_vals, db_name);
if (unlikely(res == 2)) /* Not fatal error, continue */
......@@ -5336,9 +5382,9 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
if (unlikely(res))
goto err;
for (size_t i=0; i < table_names.elements(); i++)
for (size_t j=0; j < table_names.elements(); j++)
{
LEX_CSTRING *table_name= table_names.at(i);
LEX_CSTRING *table_name= table_names.at(j);
DBUG_ASSERT(table_name->length <= NAME_LEN);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
......@@ -5593,8 +5639,12 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
if (share->tmp_table == SYSTEM_TMP_TABLE)
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
else if (IS_USER_TEMP_TABLE(share) && share->table_type == TABLE_TYPE_SEQUENCE)
table->field[3]->store(STRING_WITH_LEN("TEMPORARY SEQUENCE"), cs);
else if (share->table_type == TABLE_TYPE_SEQUENCE)
table->field[3]->store(STRING_WITH_LEN("SEQUENCE"), cs);
else if (IS_USER_TEMP_TABLE(share))
table->field[3]->store(STRING_WITH_LEN("TEMPORARY"), cs);
else
{
DBUG_ASSERT(share->tmp_table == NO_TMP_TABLE);
......@@ -5871,6 +5921,25 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
}
/**
@brief Fill IS.table with temporary tables
@param[in] thd thread handler
@param[in] table I_S table (TABLE)
@param[in] tmp_tbl temporary table to be represetned by IS.table
@return Operation status
@retval 0 - success
@retval 1 - failure
*/
void process_i_s_table_temporary_tables(THD *thd, TABLE * table, TABLE *tmp_tbl)
{
TABLE_LIST table_list;
bzero((char*) &table_list, sizeof(TABLE_LIST));
table_list.table= tmp_tbl;
get_schema_tables_record(thd, &table_list, table,
0, &tmp_tbl->s->db, &tmp_tbl->s->table_name);
}
/**
@brief Store field characteristics into appropriate I_S table columns
......
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