From 982db10f1092823a5a5749d0d16c38675dc61b4f Mon Sep 17 00:00:00 2001 From: Gagan Goel Date: Tue, 2 May 2023 15:10:41 -0400 Subject: [PATCH] MCOL-5357 Fix TPC-DS query error "MCS-3009: Unknown column '.'". For the following query: select item from ( select item from (select a as item from t1) tt union all select item from (select a as item from t1) tt ) ttt; There is an if predicate in buildSimpleColFromDerivedTable() that compares the outermost query field name (ttt.item) to the returned column list of the inner query (tt.item) when building the returned column list of the outer most query. In the above query example, the inner query field name is an alias set in the inner most query and is set to "`tt`.`item`", while the outermost query field name is set to "item". The use of backticks "`" in the inner query alias is causing the execution to not enter the if block which creates the SimpleColumn for the outermost query field name. As a fix, we strip off the backticks from the inner query alias. --- dbcon/mysql/ha_mcs_execplan.cpp | 14 +++++++++++ .../columnstore/bugfixes/mcol-5357.result | 18 ++++++++++++++ .../columnstore/bugfixes/mcol-5357.test | 24 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 mysql-test/columnstore/bugfixes/mcol-5357.result create mode 100644 mysql-test/columnstore/bugfixes/mcol-5357.test diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 595220ab2..78f0dedf3 100644 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -2454,6 +2454,20 @@ SimpleColumn* buildSimpleColFromDerivedTable(gp_walk_info& gwi, Item_field* ifp) SimpleColumn* col = dynamic_cast(cols[j].get()); string alias = cols[j]->alias(); + // MCOL-5357 For the following query: + + // select item from ( + // select item from (select a as item from t1) tt + // union all + // select item from (select a as item from t1) tt + // ) ttt; + + // When the execution reaches the outermost item (ttt.item), + // alias = "`tt`.`item`" and ifp->field_name.str = "item". + // To make the execution enter the if block below, we strip off + // the backticks from alias. + boost::erase_all(alias, "`"); + if (strcasecmp(ifp->field_name.str, alias.c_str()) == 0 || (col && alias.find(".") != string::npos && (strcasecmp(ifp->field_name.str, col->columnName().c_str()) == 0 || diff --git a/mysql-test/columnstore/bugfixes/mcol-5357.result b/mysql-test/columnstore/bugfixes/mcol-5357.result new file mode 100644 index 000000000..8456db28e --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-5357.result @@ -0,0 +1,18 @@ +DROP DATABASE IF EXISTS mcol_5357; +CREATE DATABASE mcol_5357; +USE mcol_5357; +CREATE TABLE t1 (a INT)engine=columnstore; +INSERT INTO t1 VALUES (1), (2), (3); +SELECT item FROM ( +SELECT item FROM (SELECT a AS item FROM t1) tt +UNION ALL +SELECT item FROM (SELECT a AS item FROM t1) tt +) ttt; +item +1 +2 +3 +1 +2 +3 +DROP DATABASE mcol_5357; diff --git a/mysql-test/columnstore/bugfixes/mcol-5357.test b/mysql-test/columnstore/bugfixes/mcol-5357.test new file mode 100644 index 000000000..1239eee29 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-5357.test @@ -0,0 +1,24 @@ +# +# MCOL-5357 Fix TPC-DS query error "MCS-3009: Unknown column '.'" +# + +--source ../include/have_columnstore.inc + +--disable_warnings +DROP DATABASE IF EXISTS mcol_5357; +--enable_warnings +CREATE DATABASE mcol_5357; +USE mcol_5357; + +CREATE TABLE t1 (a INT)engine=columnstore; +INSERT INTO t1 VALUES (1), (2), (3); + +SELECT item FROM ( +SELECT item FROM (SELECT a AS item FROM t1) tt +UNION ALL +SELECT item FROM (SELECT a AS item FROM t1) tt +) ttt; + +--disable_warnings +DROP DATABASE mcol_5357; +--enable_warnings