summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkroki/tomash@moonlight.home <>2007-03-08 15:16:21 +0300
committerkroki/tomash@moonlight.home <>2007-03-08 15:16:21 +0300
commit17929083813cd84f4005acf775fe2e78e9cfc62e (patch)
tree04a1fbc0ff2506a6a4f02970c53fe2e612a93a9e
parenta52a1f8d565774c0379567da3cb32c145c01931d (diff)
parent7abe938dfa77911e55bb54f076994a780db0a2f5 (diff)
downloadmariadb-git-17929083813cd84f4005acf775fe2e78e9cfc62e.tar.gz
Merge moonlight.home:/home/tomash/src/mysql_ab/mysql-5.0
into moonlight.home:/home/tomash/src/mysql_ab/mysql-5.0-bug20492
-rw-r--r--mysql-test/r/sp.result26
-rw-r--r--mysql-test/t/sp.test41
-rw-r--r--sql/sql_select.cc11
3 files changed, 75 insertions, 3 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 2f9f4fbdad2..afc3b95eb5f 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -5647,6 +5647,32 @@ call proc_bug19733()|
call proc_bug19733()|
drop procedure proc_bug19733|
drop table t3|
+DROP PROCEDURE IF EXISTS p1|
+DROP VIEW IF EXISTS v1, v2|
+DROP TABLE IF EXISTS t3, t4|
+CREATE TABLE t3 (t3_id INT)|
+INSERT INTO t3 VALUES (0)|
+INSERT INTO t3 VALUES (1)|
+CREATE TABLE t4 (t4_id INT)|
+INSERT INTO t4 VALUES (2)|
+CREATE VIEW v1 AS
+SELECT t3.t3_id, t4.t4_id
+FROM t3 JOIN t4 ON t3.t3_id = 0|
+CREATE VIEW v2 AS
+SELECT t3.t3_id AS t3_id_1, v1.t3_id AS t3_id_2, v1.t4_id
+FROM t3 LEFT JOIN v1 ON t3.t3_id = 0|
+CREATE PROCEDURE p1() SELECT * FROM v2|
+CALL p1()|
+t3_id_1 t3_id_2 t4_id
+0 0 2
+1 NULL NULL
+CALL p1()|
+t3_id_1 t3_id_2 t4_id
+0 0 2
+1 NULL NULL
+DROP PROCEDURE p1|
+DROP VIEW v1, v2|
+DROP TABLE t3, t4|
End of 5.0 tests
DROP TABLE IF EXISTS bug23760|
DROP TABLE IF EXISTS bug23760_log|
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 157d0b7c118..80fb1354b16 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -6613,6 +6613,47 @@ call proc_bug19733()|
drop procedure proc_bug19733|
drop table t3|
+
+#
+# BUG#20492: Subsequent calls to stored procedure yeild incorrect
+# result if join is used
+#
+# Optimized ON expression in join wasn't properly saved for reuse.
+#
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1|
+DROP VIEW IF EXISTS v1, v2|
+DROP TABLE IF EXISTS t3, t4|
+--enable_warnings
+
+CREATE TABLE t3 (t3_id INT)|
+
+INSERT INTO t3 VALUES (0)|
+INSERT INTO t3 VALUES (1)|
+
+CREATE TABLE t4 (t4_id INT)|
+
+INSERT INTO t4 VALUES (2)|
+
+CREATE VIEW v1 AS
+SELECT t3.t3_id, t4.t4_id
+FROM t3 JOIN t4 ON t3.t3_id = 0|
+
+CREATE VIEW v2 AS
+SELECT t3.t3_id AS t3_id_1, v1.t3_id AS t3_id_2, v1.t4_id
+FROM t3 LEFT JOIN v1 ON t3.t3_id = 0|
+
+CREATE PROCEDURE p1() SELECT * FROM v2|
+
+# Results should not differ.
+CALL p1()|
+CALL p1()|
+
+DROP PROCEDURE p1|
+DROP VIEW v1, v2|
+DROP TABLE t3, t4|
+
+
--echo End of 5.0 tests
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 5202f35f4de..346b8c13940 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -7983,9 +7983,14 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
*/
expr= simplify_joins(join, &nested_join->join_list,
expr, FALSE);
- table->on_expr= expr;
- if (!table->prep_on_expr)
+
+ if (!table->prep_on_expr || expr != table->on_expr)
+ {
+ DBUG_ASSERT(expr);
+
+ table->on_expr= expr;
table->prep_on_expr= expr->copy_andor_structure(join->thd);
+ }
}
nested_join->used_tables= (table_map) 0;
nested_join->not_null_tables=(table_map) 0;
@@ -7995,7 +8000,7 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
}
else
{
- if (!(table->prep_on_expr))
+ if (!table->prep_on_expr)
table->prep_on_expr= table->on_expr;
used_tables= table->table->map;
if (conds)