[Commits] e80f4c63acc: MDEV-12819 order by ordering expression changed to empty string when creatin view with union

Oleksandr Byelkin sanja at mariadb.com
Fri Jun 16 17:24:36 EEST 2017


revision-id: e80f4c63acc58c0521ecd7de32050724fe2ec122 (mariadb-10.1.24-22-ge80f4c63acc)
parent(s): 58f87a41bd8de7370cc05c41977fadc685826c9e
committer: Oleksandr Byelkin
timestamp: 2017-06-16 16:24:36 +0200
message:

MDEV-12819 order by ordering expression changed to empty string when creatin view with union

prepare of "fake_select" for union made in JOIN::prepare only if
we do not execute it then before reset, i.e it was for PS prepare
and now required for CREATE VIEW to make global ORDER BY which
belongs to "fake_select" prepared.

---
 mysql-test/r/view.result | 18 ++++++++++++++++++
 mysql-test/t/view.test   | 21 +++++++++++++++++++++
 sql/sql_union.cc         |  4 +++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index d7cf89577eb..0ded1dd4cb3 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -6065,5 +6065,23 @@ three	COUNT(*)
 drop view v1;
 drop table t1;
 #
+# MDEV-12819: order by ordering expression changed to empty string
+# when creatin view with union
+#
+create table t1 (t1col1 int, t1col2 int,t1col3 int );
+create table t2 (t2col1 int, t2col2 int, t2col3 int);
+create view v1 as
+select t1col1,t1col2,t1col3 from t1
+union all
+select t2col1,t2col2,t2col3 from t2
+order by 2,3;
+show create view v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`t1col1` AS `t1col1`,`t1`.`t1col2` AS `t1col2`,`t1`.`t1col3` AS `t1col3` from `t1` union all select `t2`.`t2col1` AS `t2col1`,`t2`.`t2col2` AS `t2col2`,`t2`.`t2col3` AS `t2col3` from `t2` order by 2,3	latin1	latin1_swedish_ci
+select * from v1;
+t1col1	t1col2	t1col3
+drop view v1;
+drop table t1,t2;
+#
 # End of 10.1 tests
 #
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 7a935838216..3ad7b9483ac 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -5901,5 +5901,26 @@ drop view v1;
 drop table t1;
 
 --echo #
+--echo # MDEV-12819: order by ordering expression changed to empty string
+--echo # when creatin view with union
+--echo #
+
+create table t1 (t1col1 int, t1col2 int,t1col3 int );
+create table t2 (t2col1 int, t2col2 int, t2col3 int);
+
+create view v1 as
+select t1col1,t1col2,t1col3 from t1
+union all
+select t2col1,t2col2,t2col3 from t2
+order by 2,3;
+
+show create view v1;
+
+select * from v1;
+
+drop view v1;
+drop table t1,t2;
+
+--echo #
 --echo # End of 10.1 tests
 --echo #
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 2086d1d6c03..7ca0a9bb867 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -618,7 +618,9 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
       if (saved_error)
         goto err;
 
-      if (fake_select_lex != NULL && thd->stmt_arena->is_stmt_prepare())
+      if (fake_select_lex != NULL &&
+          (thd->stmt_arena->is_stmt_prepare() ||
+           (thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW)))
       {
         /* Validate the global parameters of this union */
 


More information about the commits mailing list