Skip to content

Commit

Permalink
fix(tianmu): The outermost query returned wrong result #1931 (#1936)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Double0101 committed Jul 13, 2023
1 parent 7321c63 commit 4b712ac
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 10 deletions.
74 changes: 74 additions & 0 deletions mysql-test/suite/tianmu/r/issue1931.result
Original file line number Diff line number Diff line change
@@ -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;
81 changes: 81 additions & 0 deletions mysql-test/suite/tianmu/t/issue1931.test
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 0 additions & 9 deletions storage/tianmu/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> li(selects_list->fields_list);
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/query_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item_cond *>(conds);
Expand Down

0 comments on commit 4b712ac

Please sign in to comment.