Skip to content

Commit

Permalink
fix(core): Double prepare on lex unit for cts with union(stoneatom#226)…
Browse files Browse the repository at this point in the history
… (stoneatom#365)

fix(core): MTR + Double prepare on lex unit for ctas with union(stoneatom#226)
  • Loading branch information
xiaoguangye authored Aug 7, 2022
1 parent 5e23c20 commit f755d2e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
13 changes: 13 additions & 0 deletions mysql-test/suite/tianmu/r/issue226.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use test;
CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8) ENGINE=TIANMU;
CREATE TABLE t2 AS SELECT LEFT(f1,171) AS f2 FROM t1 UNION SELECT LEFT(f1,171) AS f2 FROM t1;
INSERT INTO t2 VALUES ('a');
INSERT INTO t2 VALUES ('b');
INSERT INTO t2 VALUES ('c');
SELECT * FROM t2;
f2
a
b
c
DROP TABLE t1;
DROP TABLE t2;
9 changes: 9 additions & 0 deletions mysql-test/suite/tianmu/t/issue226.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use test;
CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8) ENGINE=TIANMU;
CREATE TABLE t2 AS SELECT LEFT(f1,171) AS f2 FROM t1 UNION SELECT LEFT(f1,171) AS f2 FROM t1;
INSERT INTO t2 VALUES ('a');
INSERT INTO t2 VALUES ('b');
INSERT INTO t2 VALUES ('c');
SELECT * FROM t2;
DROP TABLE t1;
DROP TABLE t2;
17 changes: 11 additions & 6 deletions storage/tianmu/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ int Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SELECT_LEX_
std::string table_path = Engine::GetTablePath(((Query_tables_list *)lex)->query_tables->table);
rct = current_tx->GetTableByPathIfExists(table_path);
}
if (unit_for_union != NULL) {
if (unit_for_union != NULL && !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");
Expand Down Expand Up @@ -583,8 +583,10 @@ int st_select_lex_unit::optimize_for_tianmu() {
if (fake_select_lex != NULL)
{
thd->lex->set_current_select(fake_select_lex);
if (prepare_fake_select_lex(thd))
return saved_error;
if(!is_prepared()) {
if (prepare_fake_select_lex(thd))
return saved_error;
}
JOIN *join;
if (fake_select_lex->join)
join = fake_select_lex->join;
Expand All @@ -596,10 +598,13 @@ int st_select_lex_unit::optimize_for_tianmu() {

if (!join->is_optimized()) {
// saved_error = join->prepare(fake_select_lex->table_list.first, 0, 0,
// global_parameters->order_list.elements,
// global_parameters->order_list.elements,
// global_parameters->order_list.first, NULL, NULL, fake_select_lex,
// this); //TIANMU UPGRADE
fake_select_lex->prepare(thd);
// this); //STONEDB UPGRADE
if(!is_prepared()) {
if (fake_select_lex->prepare(thd))
return saved_error;
}
} else {
join->examined_rows = 0;
join->reset();
Expand Down

0 comments on commit f755d2e

Please sign in to comment.