Skip to content

Commit 4b712ac

Browse files
authored
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.
1 parent 7321c63 commit 4b712ac

File tree

4 files changed

+156
-10
lines changed

4 files changed

+156
-10
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
DROP DATABASE IF EXISTS issue1931_test_db;
2+
CREATE DATABASE issue1931_test_db;
3+
USE issue1931_test_db;
4+
CREATE TABLE `c1am_acct_day` (
5+
`ACCOUNT_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '账户ID',
6+
`FISCAL_DATE` date DEFAULT NULL COMMENT '记账日期',
7+
`BALANCE` decimal(16,2) NOT NULL DEFAULT '0.00' COMMENT '余额',
8+
`DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除'
9+
) ENGINE=TIANMU;
10+
CREATE TABLE `c1md_bank_acct` (
11+
`ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID',
12+
`CURRENCY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '币种ID',
13+
`COMPANY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '单位ID',
14+
`DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除'
15+
) ENGINE=TIANMU;
16+
CREATE TABLE `c1md_company` (
17+
`ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID',
18+
`SYS_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '系统ID'
19+
) ENGINE=TIANMU;
20+
INSERT INTO `c1am_acct_day`
21+
VALUES
22+
(3000000000028804, '2023-04-16', 7628617.08, '0'),
23+
(3000000000028804, '2023-04-17', 7626656.73, '0'),
24+
(3000000000028804, '2023-04-18', 7626471.23, '0'),
25+
(3000000000028806, '2023-04-15', 605253889.19, '0'),
26+
(3000000000028806, '2023-04-16', 611274357.27, '0'),
27+
(3000000000028806, '2023-04-17', 605257716.01, '0'),
28+
(3000000000028808, '2023-04-18', 79322521.29, '0'),
29+
(3000000000028808, '2023-04-19', 79322521.29, '0'),
30+
(3000000000028808, '2023-04-20', 79322521.29, '0'),
31+
(3000000000028809, '2023-04-18', 79322521.29, '0'),
32+
(3000000000028809, '2023-04-19', 79322521.29, '0'),
33+
(3000000000028809, '2023-04-20', 79322521.29, '0');
34+
INSERT INTO `c1md_bank_acct`
35+
VALUES
36+
(3000000000028804, 1, 3000000000027247, '0'),
37+
(3000000000028806, 3, 3000000000027248, '0'),
38+
(3000000000028808, 15, 3000000000027249, '0'),
39+
(3000000000028809, 6, 3000000000027250, '0');
40+
INSERT INTO `c1md_company`
41+
VALUES
42+
(3000000000027247, 2),
43+
(3000000000027248, 2),
44+
(3000000000027249, 2),
45+
(3000000000027250, 2);
46+
SELECT a.*
47+
FROM (SELECT
48+
'合计' total,
49+
a.CURRENCY_ID,
50+
'aaaa' inner_code
51+
FROM (SELECT
52+
b.CURRENCY_ID,
53+
a.account_id,
54+
a.fiscal_date,
55+
a.balance
56+
FROM
57+
c1am_acct_day a,
58+
c1md_bank_acct b
59+
WHERE a.account_id = b.ROW_ID) a
60+
JOIN c1md_bank_acct b
61+
ON b.row_id = a.account_id
62+
JOIN c1md_company c
63+
ON c.row_id = b.company_id
64+
WHERE 1 = 1
65+
AND c.row_id IN (SELECT t1.row_id
66+
FROM c1md_company t1, c1md_company t2
67+
WHERE t1.sys_id = t2.sys_id)
68+
GROUP BY a.CURRENCY_ID) a;
69+
total CURRENCY_ID inner_code
70+
合计 1 aaaa
71+
合计 3 aaaa
72+
合计 15 aaaa
73+
合计 6 aaaa
74+
DROP DATABASE issue1931_test_db;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
--source include/have_tianmu.inc
2+
3+
--disable_warnings
4+
DROP DATABASE IF EXISTS issue1931_test_db;
5+
--enable_warnings
6+
CREATE DATABASE issue1931_test_db;
7+
USE issue1931_test_db;
8+
9+
CREATE TABLE `c1am_acct_day` (
10+
`ACCOUNT_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '账户ID',
11+
`FISCAL_DATE` date DEFAULT NULL COMMENT '记账日期',
12+
`BALANCE` decimal(16,2) NOT NULL DEFAULT '0.00' COMMENT '余额',
13+
`DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除'
14+
) ENGINE=TIANMU;
15+
16+
CREATE TABLE `c1md_bank_acct` (
17+
`ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID',
18+
`CURRENCY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '币种ID',
19+
`COMPANY_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '单位ID',
20+
`DELETED_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '记录删除标志 [0]-未删除;[1]-逻辑删除'
21+
) ENGINE=TIANMU;
22+
23+
CREATE TABLE `c1md_company` (
24+
`ROW_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT 'ROW_ID',
25+
`SYS_ID` decimal(18,0) NOT NULL DEFAULT '-1' COMMENT '系统ID'
26+
) ENGINE=TIANMU;
27+
28+
INSERT INTO `c1am_acct_day`
29+
VALUES
30+
(3000000000028804, '2023-04-16', 7628617.08, '0'),
31+
(3000000000028804, '2023-04-17', 7626656.73, '0'),
32+
(3000000000028804, '2023-04-18', 7626471.23, '0'),
33+
(3000000000028806, '2023-04-15', 605253889.19, '0'),
34+
(3000000000028806, '2023-04-16', 611274357.27, '0'),
35+
(3000000000028806, '2023-04-17', 605257716.01, '0'),
36+
(3000000000028808, '2023-04-18', 79322521.29, '0'),
37+
(3000000000028808, '2023-04-19', 79322521.29, '0'),
38+
(3000000000028808, '2023-04-20', 79322521.29, '0'),
39+
(3000000000028809, '2023-04-18', 79322521.29, '0'),
40+
(3000000000028809, '2023-04-19', 79322521.29, '0'),
41+
(3000000000028809, '2023-04-20', 79322521.29, '0');
42+
43+
INSERT INTO `c1md_bank_acct`
44+
VALUES
45+
(3000000000028804, 1, 3000000000027247, '0'),
46+
(3000000000028806, 3, 3000000000027248, '0'),
47+
(3000000000028808, 15, 3000000000027249, '0'),
48+
(3000000000028809, 6, 3000000000027250, '0');
49+
50+
INSERT INTO `c1md_company`
51+
VALUES
52+
(3000000000027247, 2),
53+
(3000000000027248, 2),
54+
(3000000000027249, 2),
55+
(3000000000027250, 2);
56+
57+
SELECT a.*
58+
FROM (SELECT
59+
'合计' total,
60+
a.CURRENCY_ID,
61+
'aaaa' inner_code
62+
FROM (SELECT
63+
b.CURRENCY_ID,
64+
a.account_id,
65+
a.fiscal_date,
66+
a.balance
67+
FROM
68+
c1am_acct_day a,
69+
c1md_bank_acct b
70+
WHERE a.account_id = b.ROW_ID) a
71+
JOIN c1md_bank_acct b
72+
ON b.row_id = a.account_id
73+
JOIN c1md_company c
74+
ON c.row_id = b.company_id
75+
WHERE 1 = 1
76+
AND c.row_id IN (SELECT t1.row_id
77+
FROM c1md_company t1, c1md_company t2
78+
WHERE t1.sys_id = t2.sys_id)
79+
GROUP BY a.CURRENCY_ID) a;
80+
81+
DROP DATABASE issue1931_test_db;

storage/tianmu/core/engine_execute.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,6 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE
418418
}
419419
}
420420

421-
if (!exec_direct) {
422-
for (SELECT_LEX *sl = selects_list; sl; sl = sl->next_select()) {
423-
if ((!sl->join->m_select_limit) && (!sl->join->where_cond)) {
424-
exec_direct = true;
425-
break;
426-
}
427-
}
428-
}
429-
430421
if (exec_direct) {
431422
if ((selects_list->fields_list.elements)) {
432423
List_iterator_fast<Item> li(selects_list->fields_list);

storage/tianmu/core/query_compile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ QueryRouteTo Query::Compile(CompiledQuery *compiled_query, SELECT_LEX *selects_l
11101110
// The primary key implementation of the current column storage engine has a problem with the primary key
11111111
// index to scan the table for data Remove the following temporary practices after primary key indexing is complete
11121112
if (zero_result) {
1113-
if (Item::Type::SUBSELECT_ITEM == (conds->type())) {
1113+
if (conds && Item::Type::SUBSELECT_ITEM == (conds->type())) {
11141114
zero_result = false;
11151115
} else {
11161116
Item_cond *item_cond = dynamic_cast<Item_cond *>(conds);

0 commit comments

Comments
 (0)