Skip to content

Commit

Permalink
Merge branch 'stonedb-5.7-dev' into dev_lhj_1699
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored May 9, 2023
2 parents 08b3ab5 + 2daac7c commit 1f63818
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
34 changes: 34 additions & 0 deletions mysql-test/suite/tianmu/r/issue1707.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE DATABASE IF NOT EXISTS test_db_1707;
USE test_db_1707;
CREATE TABLE tianmu_table (
id INT NOT NULL,
name VARCHAR(50) NOT NULL,
age INT NOT NULL,
gender VARCHAR(10) NOT NULL,
salary INT NOT NULL,
address VARCHAR(100) NOT NULL
) ENGINE=tianmu;
INSERT INTO tianmu_table
(id, name, age, gender, salary, address)
VALUES
(1, 'John', 25, 'Male', 50000, '123 Main St'),
(2, 'Jane', 30, 'Female', 60000, '456 Elm St'),
(3, 'Bob', 35, 'Male', 70000, '789 Maple St');
select @age_cutoff := age
from (
SELECT name, age, gender, salary
FROM (
SELECT name, age, gender, salary
FROM tianmu_table
WHERE age < 30
UNION ALL
SELECT name, age, gender, salary
FROM tianmu_table
WHERE age >= 30
) AS derived_table
WHERE salary > 30 ) H;
@age_cutoff := age
25
30
35
drop database test_db_1707;
41 changes: 41 additions & 0 deletions mysql-test/suite/tianmu/t/issue1707.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--source include/have_tianmu.inc

--disable_warnings

CREATE DATABASE IF NOT EXISTS test_db_1707;

USE test_db_1707;

CREATE TABLE tianmu_table (
id INT NOT NULL,
name VARCHAR(50) NOT NULL,
age INT NOT NULL,
gender VARCHAR(10) NOT NULL,
salary INT NOT NULL,
address VARCHAR(100) NOT NULL
) ENGINE=tianmu;

INSERT INTO tianmu_table
(id, name, age, gender, salary, address)
VALUES
(1, 'John', 25, 'Male', 50000, '123 Main St'),
(2, 'Jane', 30, 'Female', 60000, '456 Elm St'),
(3, 'Bob', 35, 'Male', 70000, '789 Maple St');


select @age_cutoff := age
from (
SELECT name, age, gender, salary
FROM (
SELECT name, age, gender, salary
FROM tianmu_table
WHERE age < 30
UNION ALL
SELECT name, age, gender, salary
FROM tianmu_table
WHERE age >= 30
) AS derived_table
WHERE salary > 30 ) H;


drop database test_db_1707;
2 changes: 1 addition & 1 deletion sql/sql_union.cc
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ bool st_select_lex_unit::cleanup(bool full)
#ifndef NDEBUG
void st_select_lex_unit::assert_not_fully_clean()
{
assert(cleaned < UC_CLEAN);
assert(cleaned <= UC_CLEAN);
SELECT_LEX *sl= first_select();
for (;;)
{
Expand Down
14 changes: 8 additions & 6 deletions storage/tianmu/core/query_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,18 +1148,20 @@ QueryRouteTo Query::Compile(CompiledQuery *compiled_query, SELECT_LEX *selects_l
}
}

// partial optimization of LOJ conditions, JOIN::optimize(part=3)
// necessary due to already done basic transformation of conditions
// see comments in sql_select.cc:JOIN::optimize()
if (IsLOJ(join_list) &&
((!sl->join->where_cond) || (sl->join->where_cond && (uint64_t)sl->join->where_cond != 0x01))) {
sl->join->optimize(OptimizePhase::Finish_LOJ_Transform);
}

Item *field_for_subselect;
Item *cond_to_reinsert = nullptr;
List<Item> *list_to_reinsert = nullptr;

TabID tmp_table;
try {
// partial optimization of LOJ conditions, JOIN::optimize(part=3)
// necessary due to already done basic transformation of conditions
// see comments in sql_select.cc:JOIN::optimize()
if (IsLOJ(join_list))
sl->join->optimize(OptimizePhase::Finish_LOJ_Transform);

if (left_expr_for_subselect)
if (!ClearSubselectTransformation(*oper_for_subselect, field_for_subselect, conds, having, cond_to_reinsert,
list_to_reinsert, left_expr_for_subselect))
Expand Down

0 comments on commit 1f63818

Please sign in to comment.