1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-31 22:22:30 +03:00

Fixed the bug mdev-12558.

In the current code temporary tables we identified and opened before
other tables. CTE tables are identified in the same procedure as
regular tables. When a temporary table and a CTE table have the same
name T any reference to T that is in the scope of the CTE declaration
must be associated with this CTE. Yet it was not done properly.
When a reference to T was found in the scope of the declaration
of CTE T a pointer to this CTE was set in the reference. No check
that the reference had been already associated with a temporary table
was done. As a result, if the temporary table T  had been created then
the reference to T was considered simultaneously as reference to the CTE
named T and as a reference to the temporary table named T. This
confused the code that were executed later and caused a crash of
the server.
Now when a table reference is associated with a CTE any previous
association with a temporary table is dropped.

This problem could be easily avoided if the temporary tables were
not identified prematurely.
as reference to CTE named T and
This commit is contained in:
Igor Babaev
2017-04-25 19:34:39 -07:00
parent d7d8c23654
commit a287bfa09a
3 changed files with 45 additions and 3 deletions

View File

@@ -644,7 +644,7 @@ show create view v1;
drop view v1;
--echo #
--echo # MDEV-12440: the same CTE table is used in twice
--echo # MDEV-12440: the same CTE table is used twice
--echo #
create table t1 (a int, b varchar(32));
@@ -665,4 +665,19 @@ cte2 as (select * from cte1 where b > 'c'),
cte3 as (select * from cte2 where a > 1 union select * from cte2 where a > 1)
select * from cte3;
drop table t1;
drop table t1;
--echo #
--echo # MDEV-12558: CTE with the same name as temporary table
--echo #
CREATE TABLE t ENGINE=MyISAM AS SELECT 1 AS i;
CREATE TEMPORARY TABLE cte ENGINE=MyISAM AS SELECT 2 AS f;
WITH cte AS ( SELECT i FROM t ) SELECT * FROM cte;
WITH cte AS ( SELECT i FROM t GROUP BY i) SELECT * FROM cte;
SELECT * FROM cte;
DROP TABLE cte;
DROP TABLE t;