From 2a3858d9d0bd0cccc6609388ff89096441193d5c Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 27 Oct 2011 08:32:24 -0700 Subject: [PATCH] Fixed LP bug #874035. The function Item_direct_view_ref::fix_fields erroneously did not correct the value of the flag maybe_null when the view for which the item was being fixed happened to be an inner table of an outer join. --- mysql-test/r/derived_view.result | 23 +++++++++++++++++++++++ mysql-test/t/derived_view.test | 24 ++++++++++++++++++++++++ sql/item.cc | 6 +++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index cfd98a78601..25683f9c16c 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -1764,4 +1764,27 @@ x set optimizer_switch= @save_optimizer_switch; DROP VIEW v3; DROP TABLE t1,t2,t3; +# +# Bug #874035: view as an inner table of a materialized derived +# +CREATE TABLE t2 (a int NOT NULL); +INSERT INTO t2 VALUES (7), (4); +CREATE TABLE t1 (b int NOT NULL); +INSERT INTO t1 VALUES (5), (7); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; +SET SESSION optimizer_switch='derived_merge=off'; +PREPARE st1 FROM +'SELECT * FROM (SELECT * FROM t2 LEFT JOIN v1 ON t2.a = v1.b) AS t'; +EXECUTE st1; +a b +7 7 +4 NULL +EXECUTE st1; +a b +7 7 +4 NULL +DEALLOCATE PREPARE st1; +DROP VIEW v1; +DROP TABLE t1,t2; +SET SESSION optimizer_switch='derived_merge=on'; set optimizer_switch=@exit_optimizer_switch; diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test index 5ff945c094f..34b01210e1d 100644 --- a/mysql-test/t/derived_view.test +++ b/mysql-test/t/derived_view.test @@ -1166,5 +1166,29 @@ set optimizer_switch= @save_optimizer_switch; DROP VIEW v3; DROP TABLE t1,t2,t3; +--echo # +--echo # Bug #874035: view as an inner table of a materialized derived +--echo # + +CREATE TABLE t2 (a int NOT NULL); +INSERT INTO t2 VALUES (7), (4); + +CREATE TABLE t1 (b int NOT NULL); +INSERT INTO t1 VALUES (5), (7); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; + +SET SESSION optimizer_switch='derived_merge=off'; + +PREPARE st1 FROM +'SELECT * FROM (SELECT * FROM t2 LEFT JOIN v1 ON t2.a = v1.b) AS t'; +EXECUTE st1; +EXECUTE st1; +DEALLOCATE PREPARE st1; + +DROP VIEW v1; +DROP TABLE t1,t2; + +SET SESSION optimizer_switch='derived_merge=on'; + # The following command must be the last one the file set optimizer_switch=@exit_optimizer_switch; diff --git a/sql/item.cc b/sql/item.cc index f5ce0fbc7a7..2407de1bf30 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7321,7 +7321,11 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference) ((*ref)->fix_fields(thd, ref))) return TRUE; - return Item_direct_ref::fix_fields(thd, reference); + if (Item_direct_ref::fix_fields(thd, reference)) + return TRUE; + if (view->table && view->table->maybe_null) + maybe_null= TRUE; + return FALSE; } /*