[MDEV-12166] PROCEDURE using a SELECT from a temporary table does not work well Created: 2017-03-03  Updated: 2020-12-01

Status: Open
Project: MariaDB Server
Component/s: Data Definition - Temporary, Stored routines
Affects Version/s: 5.5, 10.0, 10.1, 10.2
Fix Version/s: 10.2

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-774 LP:948583 - Stored procedure doesn't ... Confirmed
relates to MDEV-5816 MySQL WL#4179 - Stored programs: vali... Closed

 Description   

I create a table t1 and a temporary table t1.

SET sql_mode=DEFAULT;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT, b VARCHAR(10));
INSERT INTO t1 VALUES (10,20);
CREATE TEMPORARY TABLE t1 (x INT);
INSERT INTO t1 VALUES (10);

Now I create and call a procedure that queries t1:

DROP PROCEDURE IF EXISTS p1;
DELIMITER $$
CREATE PROCEDURE p1()
BEGIN
  SELECT * FROM t1;
END;
$$
DELIMITER ;
CALL p1();

It uses the temporary table t1 (rather than the permanent table) and returns this result:

+------+
| x    |
+------+
|   10 |
+------+

So far so good.

Now I drop the temporary table and call the procedure again.

DROP TEMPORARY TABLE t1;
CALL p1();

It returns an error:

ERROR 1054 (42S22): Unknown column 'test.t1.x' in 'field list'

Notice, it still tries to use the column x which belonged to the temporary table and which does not exist in the permanent table. This looks wrong.

Note, if I now run a stand-alone SELECT query outside of a routine, it works fine:

SELECT * FROM t1;

+------+------+
| a    | b    |
+------+------+
|   10 | 20   |
+------+------+

The second CALL is expected to return the same result.



 Comments   
Comment by Elena Stepanova [ 2017-03-06 ]

bar, I see that you linked it with MDEV-774, but is it not actually the same problem? Probably there will be lots of affected DDL variations?

Generated at Thu Feb 08 07:55:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.