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