Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tianmu): fix crashed when the subquery includes a SORT clause (#906) #930

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions mysql-test/suite/tianmu/r/issue906.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#
# issue 906 test for crashed when the subquery includes a SORT clause but it cannot be flattened
#
use test;
DROP TABLE IF EXISTS shop;
CREATE TABLE shop (
article INT DEFAULT '0000' NOT NULL,
dealer CHAR(20) DEFAULT '' NOT NULL,
price DECIMAL(16,2) DEFAULT '0.00' NOT NULL
) ENGINE=TIANMU;
INSERT INTO shop
VALUES(1, 'A', 3.45),(1, 'B', 3.99),
(2, 'A', 10.99),(3, 'B', 1.45),
(3, 'C', 1.69),(3, 'D', 1.25),
(4, 'D', 19.95);
SELECT
*
FROM
shop
WHERE
article IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
);
article dealer price
1 A 3.45
1 B 3.99
2 A 10.99
3 B 1.45
3 C 1.69
3 D 1.25
SELECT
*
FROM
shop
WHERE
article NOT IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
);
article dealer price
4 D 19.95
SELECT
*
FROM
shop
WHERE
article IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
)
UNION
SELECT
*
FROM
shop
WHERE
article NOT IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
);
article dealer price
1 A 3.45
1 B 3.99
2 A 10.99
3 B 1.45
3 C 1.69
3 D 1.25
4 D 19.95
DROP TABLE shop;
89 changes: 89 additions & 0 deletions mysql-test/suite/tianmu/t/issue906.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
--echo #
--echo # issue 906 test for crashed when the subquery includes a SORT clause but it cannot be flattened
--echo #

use test;

--disable_warnings

DROP TABLE IF EXISTS shop;

CREATE TABLE shop (
article INT DEFAULT '0000' NOT NULL,
dealer CHAR(20) DEFAULT '' NOT NULL,
price DECIMAL(16,2) DEFAULT '0.00' NOT NULL
) ENGINE=TIANMU;

INSERT INTO shop
VALUES(1, 'A', 3.45),(1, 'B', 3.99),
(2, 'A', 10.99),(3, 'B', 1.45),
(3, 'C', 1.69),(3, 'D', 1.25),
(4, 'D', 19.95);

## subquery

### EXPR IN subquery

SELECT
*
FROM
shop
WHERE
article IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
);

### EXPR NOT IN subquery

SELECT
*
FROM
shop
WHERE
article NOT IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
);


## union

SELECT
*
FROM
shop
WHERE
article IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
)
UNION
SELECT
*
FROM
shop
WHERE
article NOT IN (
SELECT
COUNT(*)
FROM
shop
GROUP BY
article
);


DROP TABLE shop;
3 changes: 2 additions & 1 deletion storage/tianmu/core/temp_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class TempTable : public JustATable {
int operator==(const Attr &);
~Attr();

bool ShouldOutput() const { return (mode == common::ColOperation::LISTING) && term.vc && alias; }
bool IsListField() const { return (mode == common::ColOperation::LISTING) && term.vc; };
bool ShouldOutput() const { return IsListField() && alias; }
bool NeedFill() const {
return ((mode == common::ColOperation::LISTING) && term.vc && alias) ||
!term.vc->IsConst(); // constant value, the buffer is already
Expand Down