From 4b712acea066de246f579d632159e15c440a6b1e Mon Sep 17 00:00:00 2001 From: Double Date: Thu, 13 Jul 2023 10:04:14 +0800 Subject: [PATCH] fix(tianmu): The outermost query returned wrong result #1931 (#1936) Cause: Query execute by join->exec(). Solution: Solve limit=0 in tianmu, and fix crash in compile which refer to issue#1394. Then execute this query in tianmu. --- mysql-test/suite/tianmu/r/issue1931.result | 74 ++++++++++++++++++++ mysql-test/suite/tianmu/t/issue1931.test | 81 ++++++++++++++++++++++ storage/tianmu/core/engine_execute.cpp | 9 --- storage/tianmu/core/query_compile.cpp | 2 +- 4 files changed, 156 insertions(+), 10 deletions(-) create mode 100644 mysql-test/suite/tianmu/r/issue1931.result create mode 100644 mysql-test/suite/tianmu/t/issue1931.test diff --git a/mysql-test/suite/tianmu/r/issue1931.result b/mysql-test/suite/tianmu/r/issue1931.result new file mode 100644 index 000000000..72f4c2f61 --- /dev/null +++ b/mysql-test/suite/tianmu/r/issue1931.result @@ -0,0 +1,74 @@ +DROP DATABASE IF EXISTS issue1931_test_db; +CREATE DATABASE issue1931_test_db; +USE issue1931_test_db; +CREATE TABLE `c1am_acct_day` ( +`ACCOUNT_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '账户ID', +`FISCAL_DATE` date DEFAULT NULL COMMENT '记账日期', +`BALANCE` decimal(16,2) NOT NULL DEFAULT '0.00' COMMENT '余额', +`DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除' +) ENGINE=TIANMU; +CREATE TABLE `c1md_bank_acct` ( +`ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID', +`CURRENCY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '币种ID', +`COMPANY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '单位ID', +`DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除' +) ENGINE=TIANMU; +CREATE TABLE `c1md_company` ( +`ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID', +`SYS_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '系统ID' +) ENGINE=TIANMU; +INSERT INTO `c1am_acct_day` +VALUES +(3000000000028804, '2023-04-16', 7628617.08, '0'), +(3000000000028804, '2023-04-17', 7626656.73, '0'), +(3000000000028804, '2023-04-18', 7626471.23, '0'), +(3000000000028806, '2023-04-15', 605253889.19, '0'), +(3000000000028806, '2023-04-16', 611274357.27, '0'), +(3000000000028806, '2023-04-17', 605257716.01, '0'), +(3000000000028808, '2023-04-18', 79322521.29, '0'), +(3000000000028808, '2023-04-19', 79322521.29, '0'), +(3000000000028808, '2023-04-20', 79322521.29, '0'), +(3000000000028809, '2023-04-18', 79322521.29, '0'), +(3000000000028809, '2023-04-19', 79322521.29, '0'), +(3000000000028809, '2023-04-20', 79322521.29, '0'); +INSERT INTO `c1md_bank_acct` + VALUES +(3000000000028804, 1, 3000000000027247, '0'), +(3000000000028806, 3, 3000000000027248, '0'), +(3000000000028808, 15, 3000000000027249, '0'), +(3000000000028809, 6, 3000000000027250, '0'); +INSERT INTO `c1md_company` + VALUES +(3000000000027247, 2), +(3000000000027248, 2), +(3000000000027249, 2), +(3000000000027250, 2); +SELECT a.* +FROM (SELECT +'合计' total, +a.CURRENCY_ID, +'aaaa' inner_code +FROM (SELECT +b.CURRENCY_ID, +a.account_id, +a.fiscal_date, +a.balance +FROM +c1am_acct_day a, +c1md_bank_acct b +WHERE a.account_id = b.ROW_ID) a +JOIN c1md_bank_acct b +ON b.row_id = a.account_id +JOIN c1md_company c +ON c.row_id = b.company_id +WHERE 1 = 1 +AND c.row_id IN (SELECT t1.row_id +FROM c1md_company t1, c1md_company t2 +WHERE t1.sys_id = t2.sys_id) +GROUP BY a.CURRENCY_ID) a; +total CURRENCY_ID inner_code +合计 1 aaaa +合计 3 aaaa +合计 15 aaaa +合计 6 aaaa +DROP DATABASE issue1931_test_db; diff --git a/mysql-test/suite/tianmu/t/issue1931.test b/mysql-test/suite/tianmu/t/issue1931.test new file mode 100644 index 000000000..a73948bb0 --- /dev/null +++ b/mysql-test/suite/tianmu/t/issue1931.test @@ -0,0 +1,81 @@ +--source include/have_tianmu.inc + +--disable_warnings +DROP DATABASE IF EXISTS issue1931_test_db; +--enable_warnings +CREATE DATABASE issue1931_test_db; +USE issue1931_test_db; + +CREATE TABLE `c1am_acct_day` ( + `ACCOUNT_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '账户ID', + `FISCAL_DATE` date DEFAULT NULL COMMENT '记账日期', + `BALANCE` decimal(16,2) NOT NULL DEFAULT '0.00' COMMENT '余额', + `DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除' +) ENGINE=TIANMU; + +CREATE TABLE `c1md_bank_acct` ( + `ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID', + `CURRENCY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '币种ID', + `COMPANY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '单位ID', + `DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除' +) ENGINE=TIANMU; + +CREATE TABLE `c1md_company` ( + `ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID', + `SYS_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '系统ID' +) ENGINE=TIANMU; + +INSERT INTO `c1am_acct_day` + VALUES + (3000000000028804, '2023-04-16', 7628617.08, '0'), + (3000000000028804, '2023-04-17', 7626656.73, '0'), + (3000000000028804, '2023-04-18', 7626471.23, '0'), + (3000000000028806, '2023-04-15', 605253889.19, '0'), + (3000000000028806, '2023-04-16', 611274357.27, '0'), + (3000000000028806, '2023-04-17', 605257716.01, '0'), + (3000000000028808, '2023-04-18', 79322521.29, '0'), + (3000000000028808, '2023-04-19', 79322521.29, '0'), + (3000000000028808, '2023-04-20', 79322521.29, '0'), + (3000000000028809, '2023-04-18', 79322521.29, '0'), + (3000000000028809, '2023-04-19', 79322521.29, '0'), + (3000000000028809, '2023-04-20', 79322521.29, '0'); + +INSERT INTO `c1md_bank_acct` + VALUES + (3000000000028804, 1, 3000000000027247, '0'), + (3000000000028806, 3, 3000000000027248, '0'), + (3000000000028808, 15, 3000000000027249, '0'), + (3000000000028809, 6, 3000000000027250, '0'); + +INSERT INTO `c1md_company` + VALUES + (3000000000027247, 2), + (3000000000027248, 2), + (3000000000027249, 2), + (3000000000027250, 2); + +SELECT a.* + FROM (SELECT + '合计' total, + a.CURRENCY_ID, + 'aaaa' inner_code + FROM (SELECT + b.CURRENCY_ID, + a.account_id, + a.fiscal_date, + a.balance + FROM + c1am_acct_day a, + c1md_bank_acct b + WHERE a.account_id = b.ROW_ID) a + JOIN c1md_bank_acct b + ON b.row_id = a.account_id + JOIN c1md_company c + ON c.row_id = b.company_id + WHERE 1 = 1 + AND c.row_id IN (SELECT t1.row_id + FROM c1md_company t1, c1md_company t2 + WHERE t1.sys_id = t2.sys_id) + GROUP BY a.CURRENCY_ID) a; + +DROP DATABASE issue1931_test_db; diff --git a/storage/tianmu/core/engine_execute.cpp b/storage/tianmu/core/engine_execute.cpp index 78fe836bd..6ad994967 100644 --- a/storage/tianmu/core/engine_execute.cpp +++ b/storage/tianmu/core/engine_execute.cpp @@ -418,15 +418,6 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE } } - if (!exec_direct) { - for (SELECT_LEX *sl = selects_list; sl; sl = sl->next_select()) { - if ((!sl->join->m_select_limit) && (!sl->join->where_cond)) { - exec_direct = true; - break; - } - } - } - if (exec_direct) { if ((selects_list->fields_list.elements)) { List_iterator_fast li(selects_list->fields_list); diff --git a/storage/tianmu/core/query_compile.cpp b/storage/tianmu/core/query_compile.cpp index 383cdeec7..1a550bf1e 100644 --- a/storage/tianmu/core/query_compile.cpp +++ b/storage/tianmu/core/query_compile.cpp @@ -1110,7 +1110,7 @@ QueryRouteTo Query::Compile(CompiledQuery *compiled_query, SELECT_LEX *selects_l // The primary key implementation of the current column storage engine has a problem with the primary key // index to scan the table for data Remove the following temporary practices after primary key indexing is complete if (zero_result) { - if (Item::Type::SUBSELECT_ITEM == (conds->type())) { + if (conds && Item::Type::SUBSELECT_ITEM == (conds->type())) { zero_result = false; } else { Item_cond *item_cond = dynamic_cast(conds);