summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Shulga <dmitry.shulga@mariadb.com>2021-07-14 22:12:15 +0700
committerDmitry Shulga <dmitry.shulga@mariadb.com>2021-07-14 22:12:15 +0700
commit655496a8d483366ed62e2a116402d42a169901c2 (patch)
treea8102e1946470c6b644415e781de6bf955745758
parent04369f9cee4e2ce7562d42344cd59683b5fbb8ae (diff)
downloadmariadb-git-bb-10.6-MDEV-26145.tar.gz
MDEV-26145: Incorrect metadata is sent on running query with union in PS modebb-10.6-MDEV-26145
Test cases like the following one produce different result sets if it's run with and without th option --ps-protocol. CREATE TABLE t1(a INT); --enable_metadata (SELECT MAX(a) FROM t1) UNION (SELECT MAX(a) FROM t1); --disable_metadata DROP TABLE t1; Result sets differ in metadata for the query (SELECT MAX(a) FROM t1) UNION (SELECT MAX(a) FROM t1); The reason for different content of query metadata is that for queries with union the items being created on JOIN preparing phase is placed into item_list from SELECT_LEX_UNIT whereas for queries without union item_list from SELECT_LEX is used instead.
-rw-r--r--mysql-test/main/ps.result13
-rw-r--r--mysql-test/main/ps.test13
-rw-r--r--sql/sql_prepare.cc8
3 files changed, 33 insertions, 1 deletions
diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result
index eb17def9a4b..c0080cb55d2 100644
--- a/mysql-test/main/ps.result
+++ b/mysql-test/main/ps.result
@@ -5615,3 +5615,16 @@ DROP USER user1@localhost;
#
# End of 10.4 tests
#
+#
+# MDEV-26145: Incorrect metadata is sent on running query with union in PS mode
+#
+CREATE TABLE t1(a INT);
+(SELECT MAX(a) FROM t1) UNION (SELECT MAX(a) FROM t1);
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def MAX(a) MAX(a) 3 11 0 Y 32768 0 63
+MAX(a)
+NULL
+DROP TABLE t1;
+#
+# End of 10.6 tests
+#
diff --git a/mysql-test/main/ps.test b/mysql-test/main/ps.test
index e5285022efd..6cdc8de2415 100644
--- a/mysql-test/main/ps.test
+++ b/mysql-test/main/ps.test
@@ -5054,3 +5054,16 @@ DROP USER user1@localhost;
--echo #
--echo # End of 10.4 tests
--echo #
+
+--echo #
+--echo # MDEV-26145: Incorrect metadata is sent on running query with union in PS mode
+--echo #
+CREATE TABLE t1(a INT);
+--enable_metadata
+(SELECT MAX(a) FROM t1) UNION (SELECT MAX(a) FROM t1);
+--disable_metadata
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.6 tests
+--echo #
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 2f5470db123..5b4e0698de4 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1609,7 +1609,13 @@ static int mysql_test_select(Prepared_statement *stmt,
if (!lex->describe && !thd->lex->analyze_stmt && !stmt->is_sql_prepare())
{
/* Make copy of item list, as change_columns may change it */
- List<Item> fields(lex->first_select_lex()->item_list);
+
+ SELECT_LEX_UNIT* master_unit= lex->first_select_lex()->master_unit();
+ bool is_union_op=
+ master_unit->is_unit_op() || master_unit->fake_select_lex;
+
+ List<Item> fields(is_union_op ? unit->item_list :
+ lex->first_select_lex()->item_list);
/* Change columns if a procedure like analyse() */
if (unit->last_procedure && unit->last_procedure->change_columns(thd, fields))