Skip to content

Commit

Permalink
fix(tianmu) Query results more data (stoneatom#282)
Browse files Browse the repository at this point in the history
Cause:
Execution plan error when AND/OR sql logical operator in condition occurs at the same time
Resolvent:
Optimize multiple equal execution plan logic
  • Loading branch information
konghaiya committed Oct 17, 2022
1 parent c2be08d commit 2950596
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 101 deletions.
111 changes: 111 additions & 0 deletions mysql-test/suite/tianmu/r/issue282.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use test;
CREATE TABLE issue282_t1 (sku int PRIMARY KEY, pr int)engine=tianmu;
CREATE TABLE issue282_t2 (sku int PRIMARY KEY, sppr int, name varchar(255))engine=tianmu;
INSERT INTO issue282_t1 VALUES
(10, 10), (20, 10), (30, 20), (40, 30), (50, 10), (60, 10);
INSERT INTO issue282_t2 VALUES
(10, 10, 'aaa'), (20, 10, 'bbb'), (30, 10, 'ccc'), (40, 20, 'ddd'),
(50, 10, 'eee'), (60, 20, 'fff'), (70, 20, 'ggg'), (80, 30, 'hhh');
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 AND (issue282_t2.sku=issue282_t1.sku OR issue282_t2.sppr=issue282_t1.sku);
sku sppr name sku pr
20 10 bbb 10 10
20 10 bbb 20 10
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 OR (issue282_t2.sku=issue282_t1.sku OR issue282_t2.sppr=issue282_t1.sku) order by issue282_t2.sku asc;
sku sppr name sku pr
10 10 aaa 10 10
20 10 bbb 10 10
20 10 bbb 20 10
20 10 bbb 30 20
20 10 bbb 40 30
20 10 bbb 50 10
20 10 bbb 60 10
30 10 ccc 10 10
30 10 ccc 30 20
40 20 ddd 20 10
40 20 ddd 40 30
50 10 eee 10 10
50 10 eee 50 10
60 20 fff 20 10
60 20 fff 60 10
70 20 ggg 20 10
80 30 hhh 30 20
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 AND (issue282_t2.sku=issue282_t1.sku AND issue282_t2.sppr=issue282_t1.sku);
sku sppr name sku pr
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 OR (issue282_t2.sku=issue282_t1.sku AND issue282_t2.sppr=issue282_t1.sku);
sku sppr name sku pr
10 10 aaa 10 10
20 10 bbb 10 10
20 10 bbb 20 10
20 10 bbb 30 20
20 10 bbb 40 30
20 10 bbb 50 10
20 10 bbb 60 10
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 OR issue282_t2.sku=issue282_t1.sku AND issue282_t2.sppr=issue282_t1.sku;
sku sppr name sku pr
10 10 aaa 10 10
20 10 bbb 10 10
20 10 bbb 20 10
20 10 bbb 30 20
20 10 bbb 40 30
20 10 bbb 50 10
20 10 bbb 60 10
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE (issue282_t2.sku>20 OR issue282_t2.sku=issue282_t1.sku) AND issue282_t2.sppr=issue282_t1.sku;
sku sppr name sku pr
10 10 aaa 10 10
30 10 ccc 10 10
40 20 ddd 20 10
50 10 eee 10 10
60 20 fff 20 10
70 20 ggg 20 10
80 30 hhh 30 20
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE (issue282_t2.sku<=20 OR issue282_t2.sku=issue282_t1.sku) AND issue282_t2.sppr=issue282_t1.sku;
sku sppr name sku pr
10 10 aaa 10 10
20 10 bbb 10 10
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE (issue282_t2.sku<=20 AND issue282_t2.sku>issue282_t1.sku) OR issue282_t2.sppr=issue282_t1.sku;
sku sppr name sku pr
10 10 aaa 10 10
20 10 bbb 10 10
30 10 ccc 10 10
50 10 eee 10 10
40 20 ddd 20 10
60 20 fff 20 10
70 20 ggg 20 10
80 30 hhh 30 20
#
# Multiple nesting
#
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE
issue282_t1.sku=60 OR
(issue282_t2.sku=20 AND
(issue282_t2.sku=issue282_t1.sku OR
issue282_t2.sppr=issue282_t1.sku));
sku sppr name sku pr
20 10 bbb 10 10
20 10 bbb 20 10
10 10 aaa 60 10
20 10 bbb 60 10
30 10 ccc 60 10
40 20 ddd 60 10
50 10 eee 60 10
60 20 fff 60 10
70 20 ggg 60 10
80 30 hhh 60 10
SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE
issue282_t1.sku=10 AND
(issue282_t2.sku=20 AND
(issue282_t2.sku=issue282_t1.sku OR
issue282_t2.sppr=issue282_t1.sku));
sku sppr name sku pr
20 10 bbb 10 10
drop table issue282_t1 ,issue282_t2;
56 changes: 56 additions & 0 deletions mysql-test/suite/tianmu/t/issue282.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--source include/have_tianmu.inc

use test;
CREATE TABLE issue282_t1 (sku int PRIMARY KEY, pr int)engine=tianmu;
CREATE TABLE issue282_t2 (sku int PRIMARY KEY, sppr int, name varchar(255))engine=tianmu;

INSERT INTO issue282_t1 VALUES
(10, 10), (20, 10), (30, 20), (40, 30), (50, 10), (60, 10);

INSERT INTO issue282_t2 VALUES
(10, 10, 'aaa'), (20, 10, 'bbb'), (30, 10, 'ccc'), (40, 20, 'ddd'),
(50, 10, 'eee'), (60, 20, 'fff'), (70, 20, 'ggg'), (80, 30, 'hhh');

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 AND (issue282_t2.sku=issue282_t1.sku OR issue282_t2.sppr=issue282_t1.sku);

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 OR (issue282_t2.sku=issue282_t1.sku OR issue282_t2.sppr=issue282_t1.sku) order by issue282_t2.sku asc;

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 AND (issue282_t2.sku=issue282_t1.sku AND issue282_t2.sppr=issue282_t1.sku);

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 OR (issue282_t2.sku=issue282_t1.sku AND issue282_t2.sppr=issue282_t1.sku);

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE issue282_t2.sku=20 OR issue282_t2.sku=issue282_t1.sku AND issue282_t2.sppr=issue282_t1.sku;

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE (issue282_t2.sku>20 OR issue282_t2.sku=issue282_t1.sku) AND issue282_t2.sppr=issue282_t1.sku;

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE (issue282_t2.sku<=20 OR issue282_t2.sku=issue282_t1.sku) AND issue282_t2.sppr=issue282_t1.sku;

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE (issue282_t2.sku<=20 AND issue282_t2.sku>issue282_t1.sku) OR issue282_t2.sppr=issue282_t1.sku;

--echo #
--echo # Multiple nesting
--echo #

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE
issue282_t1.sku=60 OR
(issue282_t2.sku=20 AND
(issue282_t2.sku=issue282_t1.sku OR
issue282_t2.sppr=issue282_t1.sku));

SELECT issue282_t2.sku, issue282_t2.sppr, issue282_t2.name, issue282_t1.sku, issue282_t1.pr
FROM issue282_t2, issue282_t1 WHERE
issue282_t1.sku=10 AND
(issue282_t2.sku=20 AND
(issue282_t2.sku=issue282_t1.sku OR
issue282_t2.sppr=issue282_t1.sku));

drop table issue282_t1 ,issue282_t2;
Loading

0 comments on commit 2950596

Please sign in to comment.