Skip to content

Commit

Permalink
fix(tianmu):query with UNION ALL return result set error.(#854)
Browse files Browse the repository at this point in the history
Modify the query logic executed by the union to make the result: go through the prepare() process
  • Loading branch information
DandreChen committed Nov 15, 2022
1 parent 08ac72f commit a7993e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
16 changes: 16 additions & 0 deletions mysql-test/suite/tianmu/r/union.result
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,20 @@ a
2147483647
9223372036854775807
DROP TABLE t1,t2;
CREATE TABLE t1 (a MEDIUMINT);
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFF800000 AS SIGNED)+2),(-1),(0),(1),(0x7FFFFF);
CREATE TABLE t2 (a BIGINT);
INSERT INTO t2 VALUES (CAST(0x8000000000000000 AS SIGNED)+2),(-1),(0),(1),(0x7FFFFFFFFFFFFFFF);
SELECT a FROM t1 UNION ALL SELECT a FROM t2;
a
-8388606
-1
0
1
8388607
-9223372036854775806
-1
0
1
9223372036854775807
DROP DATABASE union_test;
6 changes: 6 additions & 0 deletions mysql-test/suite/tianmu/t/union.test
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT a FROM t2) tttt ORDER BY a;
SELECT * FROM (SELECT a FROM t2 UNION ALL SELECT a FROM t1) tttt ORDER BY a;
DROP TABLE t1,t2;

CREATE TABLE t1 (a MEDIUMINT);
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFF800000 AS SIGNED)+2),(-1),(0),(1),(0x7FFFFF);
CREATE TABLE t2 (a BIGINT);
INSERT INTO t2 VALUES (CAST(0x8000000000000000 AS SIGNED)+2),(-1),(0),(1),(0x7FFFFFFFFFFFFFFF);
SELECT a FROM t1 UNION ALL SELECT a FROM t2;

DROP DATABASE union_test;
14 changes: 8 additions & 6 deletions storage/tianmu/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,14 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE
std::string table_path = Engine::GetTablePath(((Query_tables_list *)lex)->query_tables->table);
rct = current_txn_->GetTableByPathIfExists(table_path);
}
if (unit_for_union != nullptr && !unit_for_union->is_prepared()) {
int res = result_output->prepare(unit_for_union->item_list, unit_for_union);
if (res) {
TIANMU_LOG(LogCtl_Level::ERROR, "Error: Unsupported UNION");
my_message(ER_UNKNOWN_ERROR, "Tianmu: unsupported UNION", MYF(0));
throw ReturnMeToMySQLWithError();
if (unit_for_union != nullptr) {
if (lex->sql_command != SQLCOM_CREATE_TABLE) { // for exclude CTAS
int res = result_output->prepare(unit_for_union->item_list, unit_for_union);
if (res) {
TIANMU_LOG(LogCtl_Level::ERROR, "Error: Unsupported UNION");
my_message(ER_UNKNOWN_ERROR, "Tianmu: unsupported UNION", MYF(0));
throw ReturnMeToMySQLWithError();
}
}
if (export_file_name)
sender.reset(new ResultExportSender(unit_for_union->thd, result_output, unit_for_union->item_list));
Expand Down

0 comments on commit a7993e6

Please sign in to comment.