Skip to content

Commit

Permalink
MDEV-8642: WHERE Clause not applied on View - Empty result set returned
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sanja-byelkin committed Apr 5, 2017
1 parent 8e36216 commit 57a699b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
37 changes: 37 additions & 0 deletions mysql-test/r/view.result
Expand Up @@ -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.
# -----------------------------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions mysql-test/t/view.test
Expand Up @@ -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.
Expand Down
13 changes: 0 additions & 13 deletions sql/item.cc
Expand Up @@ -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);
/*
Expand Down

0 comments on commit 57a699b

Please sign in to comment.