From 57a699b0a0f3300404948775356d31fb478e80c6 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 17 Jun 2016 16:51:11 +0200 Subject: [PATCH] MDEV-8642: WHERE Clause not applied on View - Empty result set returned An attempt to mark reference as dependent lead to transfering this property to original view field and through it to other references of this field which can't be dependent. --- mysql-test/r/view.result | 37 +++++++++++++++++++++++++++++++++++++ mysql-test/t/view.test | 38 ++++++++++++++++++++++++++++++++++++++ sql/item.cc | 13 ------------- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 3c6eb235a57..d6da2a03b46 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -5907,6 +5907,43 @@ a 2 DROP VIEW v1; DROP TABLE t1; +# +# MDEV-8642: WHERE Clause not applied on View - Empty result set returned +# +CREATE TABLE `t1` ( +`id` int(20) NOT NULL AUTO_INCREMENT, +`use_case` int(11) DEFAULT NULL, +`current_deadline` date DEFAULT NULL, +`ts_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (`id`), +UNIQUE KEY `id_UNIQUE` (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=13976 DEFAULT CHARSET=latin1; +INSERT INTO `t1` VALUES (1,10,'2015-12-18','2015-08-18 08:38:16'); +INSERT INTO `t1` VALUES (2,20,'2015-10-18','2015-08-18 08:43:30'); +CREATE VIEW v1 AS SELECT +use_case as use_case_id, +( +SELECT +deadline_sub.current_deadline +FROM +t1 deadline_sub +WHERE +deadline_sub.use_case = use_case_id +AND ts_create = (SELECT +MIN(ts_create) +FROM +t1 startdate_sub +WHERE +startdate_sub.use_case = use_case_id +) +) AS InitialDeadline +FROM +t1; +SELECT * FROM v1 where use_case_id = 10; +use_case_id InitialDeadline +10 2015-12-18 +drop view v1; +drop table t1; # ----------------------------------------------------------------- # -- End of 10.0 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 630c247e85b..89a8e0c9ffc 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -5775,6 +5775,44 @@ DROP VIEW v1; DROP TABLE t1; +--echo # +--echo # MDEV-8642: WHERE Clause not applied on View - Empty result set returned +--echo # + +CREATE TABLE `t1` ( + `id` int(20) NOT NULL AUTO_INCREMENT, + `use_case` int(11) DEFAULT NULL, + `current_deadline` date DEFAULT NULL, + `ts_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `id_UNIQUE` (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=13976 DEFAULT CHARSET=latin1; +INSERT INTO `t1` VALUES (1,10,'2015-12-18','2015-08-18 08:38:16'); +INSERT INTO `t1` VALUES (2,20,'2015-10-18','2015-08-18 08:43:30'); +CREATE VIEW v1 AS SELECT + use_case as use_case_id, + ( + SELECT + deadline_sub.current_deadline + FROM + t1 deadline_sub + WHERE + deadline_sub.use_case = use_case_id + AND ts_create = (SELECT + MIN(ts_create) + FROM + t1 startdate_sub + WHERE + startdate_sub.use_case = use_case_id + ) + ) AS InitialDeadline +FROM + t1; + +SELECT * FROM v1 where use_case_id = 10; + +drop view v1; +drop table t1; --echo # ----------------------------------------------------------------- --echo # -- End of 10.0 tests. diff --git a/sql/item.cc b/sql/item.cc index 86f1795a4da..dbec742e4a2 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7141,19 +7141,6 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) last_checked_context->select_lex->nest_level); } } - else if (ref_type() != VIEW_REF) - { - /* - It could be that we're referring to something that's in ancestor selects. - We must make an appropriate mark_as_dependent() call for each such - outside reference. - */ - Dependency_marker dep_marker; - dep_marker.current_select= current_sel; - dep_marker.thd= thd; - (*ref)->walk(&Item::enumerate_field_refs_processor, FALSE, - (uchar*)&dep_marker); - } DBUG_ASSERT(*ref); /*