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 mysqld crash when exec query limit 0 (#1394) #1395

Merged
merged 1 commit into from
Mar 17, 2023
Merged
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
79 changes: 79 additions & 0 deletions mysql-test/suite/tianmu/r/issue1394.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
DROP DATABASE IF EXISTS issue1394_test;
CREATE DATABASE issue1394_test;
USE issue1394_test;
create table c(c1 int, c2 varchar(2)) engine=TIANMU;
create table d(d1 int, d2 varchar(2)) engine=TIANMU;
insert into c values(1, 'c1');
insert into c values(2, 'c2');
insert into c values(null, 'c3');
insert into d values(1, 'd1');
insert into d values(2, 'd2');
insert into d values(null, 'd3');
select * from d;
d1 d2
1 d1
2 d2
NULL d3
select * from d limit 0;
d1 d2
select * from d limit 1;
d1 d2
1 d1
select * from d where d1=1 limit 0;
d1 d2
select * from d where d1=1 limit 1;
d1 d2
1 d1
select * from c where exists ( select * from d where d1=1 limit 0);
c1 c2
1 c1
2 c2
NULL c3
select * from c where exists ( select * from d where d1=1 limit 1);
c1 c2
1 c1
2 c2
NULL c3
select * from c where exists ( select * from d where d1=1 limit 0,1) limit 0;
c1 c2
select * from c where exists ( select * from d where d1=1 limit 0,1) limit 1;
c1 c2
1 c1
select * from c where exists ( select * from d where d1=1 limit 0) limit 0;
c1 c2
select * from c where exists ( select * from d where d1=1 limit 1) limit 1;
c1 c2
1 c1
SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL;
c1 c2 d1 d2
NULL NULL NULL d3
SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 1;
c1 c2 d1 d2
NULL NULL NULL d3
SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 0;
c1 c2 d1 d2
SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL;
c1 c2 d1 d2
1 c1 1 d1
2 c2 2 d2
SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 1;
c1 c2 d1 d2
1 c1 1 d1
SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 0;
c1 c2 d1 d2
SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL;
c1 c2 d1 d2
SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 1;
c1 c2 d1 d2
SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 0;
c1 c2 d1 d2
SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL;
c1 c2 d1 d2
1 c1 1 d1
2 c2 2 d2
SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 1;
c1 c2 d1 d2
1 c1 1 d1
SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 0;
c1 c2 d1 d2
DROP DATABASE issue1394_test;
83 changes: 83 additions & 0 deletions mysql-test/suite/tianmu/t/issue1394.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS issue1394_test;
--enable_warnings

CREATE DATABASE issue1394_test;

USE issue1394_test;

--disable_warnings

## DDL

create table c(c1 int, c2 varchar(2)) engine=TIANMU;

create table d(d1 int, d2 varchar(2)) engine=TIANMU;

## insert data

insert into c values(1, 'c1');

insert into c values(2, 'c2');

insert into c values(null, 'c3');

insert into d values(1, 'd1');

insert into d values(2, 'd2');

insert into d values(null, 'd3');

## query

select * from d;

select * from d limit 0;

select * from d limit 1;

select * from d where d1=1 limit 0;

select * from d where d1=1 limit 1;

select * from c where exists ( select * from d where d1=1 limit 0);

select * from c where exists ( select * from d where d1=1 limit 1);

select * from c where exists ( select * from d where d1=1 limit 0,1) limit 0;

select * from c where exists ( select * from d where d1=1 limit 0,1) limit 1;

select * from c where exists ( select * from d where d1=1 limit 0) limit 0;

select * from c where exists ( select * from d where d1=1 limit 1) limit 1;
RingsC marked this conversation as resolved.
Show resolved Hide resolved

SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL;

SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 1;

SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 0;

SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL;

SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 1;

SELECT * FROM c RIGHT OUTER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 0;

SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL;

SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 1;

SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NULL limit 0;

SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL;

SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 1;

SELECT * FROM c INNER JOIN d ON c.c1 = d.d1 WHERE d.d1 IS NOT NULL limit 0;

## clean test table

DROP DATABASE issue1394_test;
7 changes: 7 additions & 0 deletions storage/tianmu/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE
}
}

for (SELECT_LEX *sl = selects_list; sl; sl = sl->next_select()) {
if (sl->join->m_select_limit == 0) {
exec_direct = true;
break;
}
}

if (exec_direct) {
return join_exec();
}
Expand Down