Commit 3aa370bb authored by unknown's avatar unknown

MDEV-5515: 2nd execution of a prepared statement returns wrong results

update_used_tables() should be called after handling derived tables in any case.
parent 57400ee6
......@@ -4750,6 +4750,46 @@ a r1 = r2 r2 = r3
2 1 1
drop view v1;
drop table t1,t2;
#
# MDEV-5515: 2nd execution of a prepared statement returns wrong results
#
CREATE TABLE t1 (i1 INT, j1 INT NOT NULL, PRIMARY KEY (i1));
INSERT INTO t1 VALUES (30,300),(40,400);
CREATE TABLE t2 (i2 INT);
INSERT INTO t2 VALUES (50),(60);
CREATE TABLE t3 (c3 VARCHAR(20), i3 INT);
INSERT INTO t3 VALUES ('a',10),('b',2);
CREATE TABLE t4 (i4 INT);
INSERT INTO t4 VALUES (1),(2);
DROP VIEW IF EXISTS v1;
Warnings:
Note 1051 Unknown table 'test.v1'
CREATE VIEW v1 AS select coalesce(j1,i3) AS v1_field1 from t2 join t3 left join t1 on ( i1 = i2 );
CREATE VIEW v2 AS select v1_field1 from t4 join v1;
prepare my_stmt from "select v1_field1 from v2";
execute my_stmt;
v1_field1
10
10
10
10
2
2
2
2
execute my_stmt;
v1_field1
10
10
10
10
2
2
2
2
deallocate prepare my_stmt;
DROP VIEW v1,v2;
DROP TABLE t1,t2,t3,t4;
# -----------------------------------------------------------------
# -- End of 5.3 tests.
# -----------------------------------------------------------------
......
......@@ -4691,6 +4691,35 @@ select a, r1 = r2, r2 = r3 from t2;
drop view v1;
drop table t1,t2;
--echo #
--echo # MDEV-5515: 2nd execution of a prepared statement returns wrong results
--echo #
CREATE TABLE t1 (i1 INT, j1 INT NOT NULL, PRIMARY KEY (i1));
INSERT INTO t1 VALUES (30,300),(40,400);
CREATE TABLE t2 (i2 INT);
INSERT INTO t2 VALUES (50),(60);
CREATE TABLE t3 (c3 VARCHAR(20), i3 INT);
INSERT INTO t3 VALUES ('a',10),('b',2);
CREATE TABLE t4 (i4 INT);
INSERT INTO t4 VALUES (1),(2);
DROP VIEW IF EXISTS v1;
CREATE VIEW v1 AS select coalesce(j1,i3) AS v1_field1 from t2 join t3 left join t1 on ( i1 = i2 );
CREATE VIEW v2 AS select v1_field1 from t4 join v1;
prepare my_stmt from "select v1_field1 from v2";
execute my_stmt;
execute my_stmt;
deallocate prepare my_stmt;
DROP VIEW v1,v2;
DROP TABLE t1,t2,t3,t4;
--echo # -----------------------------------------------------------------
--echo # -- End of 5.3 tests.
--echo # -----------------------------------------------------------------
......
......@@ -939,8 +939,9 @@ JOIN::optimize()
if (select_lex->handle_derived(thd->lex, DT_MERGE))
DBUG_RETURN(TRUE);
table_count= select_lex->leaf_tables.elements;
select_lex->update_used_tables();
}
// Update used tables after all handling derived table procedures
select_lex->update_used_tables();
if (transform_max_min_subquery())
DBUG_RETURN(1); /* purecov: inspected */
......
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