summaryrefslogtreecommitdiff
path: root/mysql-test/main/derived_view.test
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2018-06-14 15:48:57 -0700
committerIgor Babaev <igor@askmonty.org>2018-06-18 23:04:17 -0700
commit956b296248acbe35aa87f056ccf99dbb999eea02 (patch)
tree2cc4b47a3a3b008bfd7df08fb8bf52417803b390 /mysql-test/main/derived_view.test
parentb27ec709350e13c5cdc08dcdcaeb31b1cc0f803e (diff)
downloadmariadb-git-956b296248acbe35aa87f056ccf99dbb999eea02.tar.gz
MDEV-16420 View stop working after upgrade from 10.1.15 to 10.3.7
This bug happened for queries that used a materialized view that renamed columns of the specifying query in an inner table of an outer join. For such a query name resolution for a column belonging the view could fail if the underlying column was non-nullable. When creating the defintion of the the temporary table for the materialized view used in the inner part of an outer join the definition of the non-nullable columns are created by the function create_tmp_field_from_item() that names the columns according to the names of the underlying columns. So these names should be changed for the view column names. This bug cannot be reproduced in 10.2 because there setup_fields() called when preparing joins in the view specification effectively renames the underlying columns in the function find_field_in_view(). In 10.3 this renaming was removed as improper (see Monty's commit b478276b04d4dd122e2ed4d4e2cd7eb69c0fb2d2).
Diffstat (limited to 'mysql-test/main/derived_view.test')
-rw-r--r--mysql-test/main/derived_view.test24
1 files changed, 24 insertions, 0 deletions
diff --git a/mysql-test/main/derived_view.test b/mysql-test/main/derived_view.test
index 9b0cf9dca7d..68f334e1ac4 100644
--- a/mysql-test/main/derived_view.test
+++ b/mysql-test/main/derived_view.test
@@ -1949,6 +1949,30 @@ eval EXPLAIN EXTENDED $q;
DROP TABLE t1, t2;
+--echo #
+--echo # Bug mdev-16420: materialized view that renames columns
+--echo # in inner part of outer join
+--echo #
+
+CREATE TABLE t1 (id int, PRIMARY KEY (id));
+INSERT INTO t1 VALUES (2), (3), (7), (1);
+
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE VIEW v2 AS SELECT v1.id AS order_pk FROM v1 GROUP BY v1.id;
+CREATE VIEW v3 AS
+SELECT t.id AS order_pk FROM (SELECT * FROM t1) AS t GROUP BY t.id;
+
+SELECT * FROM t1 LEFT JOIN v2 ON t1.id=v2.order_pk;
+EXPLAIN EXTENDED
+SELECT * FROM t1 LEFT JOIN v2 ON t1.id=v2.order_pk;
+
+SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk;
+EXPLAIN EXTENDED
+SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk;
+
+DROP VIEW v1,v2,v3;
+DROP TABLE t1;
+
# The following command must be the last one the file
set optimizer_switch=@exit_optimizer_switch;
set join_cache_level=@exit_join_cache_level;