From 1b31fd3bdb5e7ca92cbad5b019e128d58b50703a Mon Sep 17 00:00:00 2001 From: Leonid Fedorov <79837786+mariadb-LeonidFedorov@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:20:23 +0400 Subject: [PATCH] fix(plugin) MCOL-5699: throw error for unimplemented INTERSECT and EXCEPT (#3219) --- dbcon/mysql/ha_mcs_execplan.cpp | 20 +++++++++ .../columnstore/bugfixes/MCOL-5699.result | 43 +++++++++++++++++++ .../columnstore/bugfixes/MCOL-5699.test | 40 +++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 mysql-test/columnstore/bugfixes/MCOL-5699.result create mode 100644 mysql-test/columnstore/bugfixes/MCOL-5699.test diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index a99d07a25..8b3e2ca94 100644 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -6830,6 +6830,26 @@ int processFrom(bool& isUnion, SELECT_LEX& select_lex, gp_walk_info& gwi, SCSEP& // Existed pushdown handlers won't get in this scope // MDEV-25080 Union pushdown would enter this scope // is_unit_op() give a segv for derived_handler's SELECT_LEX + + // check INTERSECT or EXCEPT, that are not implemented + if (select_lex.master_unit() && select_lex.master_unit()->first_select()) + { + for (auto nextSelect = select_lex.master_unit()->first_select()->next_select(); nextSelect; + nextSelect = nextSelect->next_select()) + { + if (nextSelect->get_linkage() == INTERSECT_TYPE) + { + setError(gwi.thd, ER_INTERNAL_ERROR, "INTERSECT is not supported by Columnstore engine", gwi); + return ER_INTERNAL_ERROR; + } + else if (nextSelect->get_linkage() == EXCEPT_TYPE) + { + setError(gwi.thd, ER_INTERNAL_ERROR, "EXCEPT is not supported by Columnstore engine", gwi); + return ER_INTERNAL_ERROR; + } + } + } + if (!isUnion && (!isSelectHandlerTop || isSelectLexUnit) && select_lex.master_unit()->is_unit_op()) { // MCOL-2178 isUnion member only assigned, never used diff --git a/mysql-test/columnstore/bugfixes/MCOL-5699.result b/mysql-test/columnstore/bugfixes/MCOL-5699.result new file mode 100644 index 000000000..a90b3560a --- /dev/null +++ b/mysql-test/columnstore/bugfixes/MCOL-5699.result @@ -0,0 +1,43 @@ +DROP DATABASE IF EXISTS mcol_5699 ; +CREATE DATABASE mcol_5699 ; +USE mcol_5699 ; +CREATE TABLE cs1(a text) ENGINE=columnstore; +INSERT INTO cs1 VALUES('a'),('b'),('c'),('x'); +CREATE TABLE cs2(a text) ENGINE=columnstore; +INSERT INTO cs2 VALUES('y'),('z'),('x'); +CREATE TABLE cs3(a text) ENGINE=columnstore; +INSERT INTO cs3 VALUES('r'),('t'),('z'); +SELECT a from cs1 UNION ALL select a from cs2; +a +a +b +c +x +x +y +z +SELECT a from cs1 UNION DISTINCT select a from cs2; +a +a +b +c +x +y +z +SELECT a from cs1 INTERSECT ALL select a from cs2; +ERROR HY000: Internal error: INTERSECT is not supported by Columnstore engine +SELECT a from cs1 INTERSECT DISTINCT select a from cs2; +ERROR HY000: Internal error: INTERSECT is not supported by Columnstore engine +SELECT a from cs1 EXCEPT ALL select a from cs2; +ERROR HY000: Internal error: EXCEPT is not supported by Columnstore engine +SELECT a from cs1 EXCEPT DISTINCT select a from cs2; +ERROR HY000: Internal error: EXCEPT is not supported by Columnstore engine +SELECT a from cs1 UNION select a from cs2 INTERSECT ALL select a from cs3; +ERROR HY000: Internal error: INTERSECT is not supported by Columnstore engine +SELECT a from cs1 UNION select a from cs2 INTERSECT DISTINCT select a from cs3; +ERROR HY000: Internal error: INTERSECT is not supported by Columnstore engine +SELECT a from cs1 UNION select a from cs2 EXCEPT ALL select a from cs3; +ERROR HY000: Internal error: EXCEPT is not supported by Columnstore engine +SELECT a from cs1 UNION select a from cs2 EXCEPT DISTINCT select a from cs3; +ERROR HY000: Internal error: EXCEPT is not supported by Columnstore engine +DROP DATABASE mcol_5699 ; diff --git a/mysql-test/columnstore/bugfixes/MCOL-5699.test b/mysql-test/columnstore/bugfixes/MCOL-5699.test new file mode 100644 index 000000000..c5614a2c2 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/MCOL-5699.test @@ -0,0 +1,40 @@ +--source ../include/have_columnstore.inc +--disable_warnings +DROP DATABASE IF EXISTS mcol_5699 ; +--enable_warnings +CREATE DATABASE mcol_5699 ; +USE mcol_5699 ; +CREATE TABLE cs1(a text) ENGINE=columnstore; +INSERT INTO cs1 VALUES('a'),('b'),('c'),('x'); + +CREATE TABLE cs2(a text) ENGINE=columnstore; +INSERT INTO cs2 VALUES('y'),('z'),('x'); + +CREATE TABLE cs3(a text) ENGINE=columnstore; +INSERT INTO cs3 VALUES('r'),('t'),('z'); + +--sorted_result +SELECT a from cs1 UNION ALL select a from cs2; +--sorted_result +SELECT a from cs1 UNION DISTINCT select a from cs2; + +--ERROR 1815 +SELECT a from cs1 INTERSECT ALL select a from cs2; +--ERROR 1815 +SELECT a from cs1 INTERSECT DISTINCT select a from cs2; +--ERROR 1815 +SELECT a from cs1 EXCEPT ALL select a from cs2; +--ERROR 1815 +SELECT a from cs1 EXCEPT DISTINCT select a from cs2; + +--ERROR 1815 +SELECT a from cs1 UNION select a from cs2 INTERSECT ALL select a from cs3; +--ERROR 1815 +SELECT a from cs1 UNION select a from cs2 INTERSECT DISTINCT select a from cs3; +--ERROR 1815 +SELECT a from cs1 UNION select a from cs2 EXCEPT ALL select a from cs3; +--ERROR 1815 +SELECT a from cs1 UNION select a from cs2 EXCEPT DISTINCT select a from cs3; + + +DROP DATABASE mcol_5699 ;