Below is the list of changes that have just been committed into a local
5.0 repository of tomash. When tomash does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2006-10-17 17:08:00+04:00, kroki@stripped +4 -0
BUG#20327: incorrect results with views, server-side prepared stmts,
correlated subquery.
A query with sub-SELECT that references fields of a VIEW from outer
SELECT could return wrong result if used from prepared statement.
The bug happened because during statement preparation fields of a view
were merged, and on execution we marked such merged fields as dependent
on outer select, though only fields of a view itself should be marked so.
The solution is to not mark as dependent fields merged from a view.
mysql-test/r/ps.result@stripped, 2006-10-17 17:07:57+04:00, kroki@stripped +20 -0
Add result for bug#20327: incorrect results with views, server-side
prepared stmts, correlated subquery.
mysql-test/t/ps.test@stripped, 2006-10-17 17:07:57+04:00, kroki@stripped +28 -0
Add test case for bug#20327: incorrect results with views, server-side
prepared stmts, correlated subquery.
sql/item.cc@stripped, 2006-10-17 17:07:57+04:00, kroki@stripped +0 -4
Remove useless declaration.
sql/sql_base.cc@stripped, 2006-10-17 17:07:58+04:00, kroki@stripped +6 -0
During re-execution we should not mark fields that were merged from a
view as dependent on outer statement, even if original view field was
so dependent.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: kroki
# Host: moonlight.intranet
# Root: /home/tomash/src/mysql_ab/mysql-5.0-bug20327
--- 1.233/sql/item.cc 2006-10-17 17:08:06 +04:00
+++ 1.234/sql/item.cc 2006-10-17 17:08:06 +04:00
@@ -26,10 +26,6 @@
#include "sql_trigger.h"
#include "sql_select.h"
-static void mark_as_dependent(THD *thd,
- SELECT_LEX *last, SELECT_LEX *current,
- Item_ident *item);
-
const String my_null_string("NULL", 4, default_charset_info);
/****************************************************************************/
--- 1.350/sql/sql_base.cc 2006-10-17 17:08:06 +04:00
+++ 1.351/sql/sql_base.cc 2006-10-17 17:08:06 +04:00
@@ -3298,6 +3298,12 @@ find_field_in_tables(THD *thd, Item_iden
{
if (found == WRONG_GRANT)
return (Field*) 0;
+
+ /*
+ We should not call mark_select_range_as_dependent() for
+ expressions merged from a view.
+ */
+ if (!table_ref->belong_to_view)
{
SELECT_LEX *current_sel= thd->lex->current_select;
SELECT_LEX *last_select= table_ref->select_lex;
--- 1.72/mysql-test/r/ps.result 2006-10-17 17:08:06 +04:00
+++ 1.73/mysql-test/r/ps.result 2006-10-17 17:08:06 +04:00
@@ -1311,4 +1311,24 @@ EXECUTE stmt USING @a;
i j i i j
DEALLOCATE PREPARE stmt;
DROP TABLE IF EXISTS t1, t2, t3;
+DROP VIEW IF EXISTS v1;
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (i INT);
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES (1), (2);
+SELECT t1.i FROM t1 JOIN v1 ON t1.i = v1.i
+WHERE EXISTS (SELECT * FROM t1 WHERE v1.i = 1);
+i
+1
+PREPARE stmt FROM "SELECT t1.i FROM t1 JOIN v1 ON t1.i = v1.i
+WHERE EXISTS (SELECT * FROM t1 WHERE v1.i = 1)";
+EXECUTE stmt;
+i
+1
+EXECUTE stmt;
+i
+1
+DEALLOCATE PREPARE stmt;
+DROP VIEW v1;
+DROP TABLE t1;
End of 5.0 tests.
--- 1.69/mysql-test/t/ps.test 2006-10-17 17:08:06 +04:00
+++ 1.70/mysql-test/t/ps.test 2006-10-17 17:08:06 +04:00
@@ -1358,4 +1358,32 @@ DEALLOCATE PREPARE stmt;
DROP TABLE IF EXISTS t1, t2, t3;
+#
+# BUG#20327: incorrect results with views, server-side prepared stmts,
+# correlated subquery
+#
+--disable_warnings
+DROP VIEW IF EXISTS v1;
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (i INT);
+CREATE VIEW v1 AS SELECT * FROM t1;
+
+INSERT INTO t1 VALUES (1), (2);
+
+let $query = SELECT t1.i FROM t1 JOIN v1 ON t1.i = v1.i
+ WHERE EXISTS (SELECT * FROM t1 WHERE v1.i = 1);
+eval $query;
+eval PREPARE stmt FROM "$query";
+# Statement execution should return '1'.
+EXECUTE stmt;
+# Check re-execution.
+EXECUTE stmt;
+
+DEALLOCATE PREPARE stmt;
+DROP VIEW v1;
+DROP TABLE t1;
+
+
--echo End of 5.0 tests.
| Thread |
|---|
| • bk commit into 5.0 tree (kroki:1.2261) BUG#20327 | kroki | 17 Oct |