[MDEV-4590] Wrong result on second PS execution with early constant subquery optimization (MDEV-83) Created: 2013-05-27  Updated: 2013-06-03  Resolved: 2013-06-03

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Timour Katchaounov (Inactive) Assignee: Timour Katchaounov (Inactive)
Resolution: Fixed Votes: 0
Labels: None


 Description   

The following test case extracted from subselect_sj.test fails with MDEV-83 due to early subquery optimization.

drop table if exists t0, t1, t2, t10;

set @@storage_engine=myisam;

create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1(a int, b int);
insert into t1 values (0,0),(1,1),(2,2);
create table t10 (pk int, a int, primary key(pk));
insert into t10 select a,a from t0;
create table t2 as select * from t1;

– Force a very simple query plan
set join_cache_level=0;
set optimizer_switch='semijoin=off';

select *
from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
where t1.a < 5;

prepare s1 from
' select * from
t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
where t1.a < 5';
execute s1;
execute s1;



 Comments   
Comment by Timour Katchaounov (Inactive) [ 2013-05-27 ]

The bug is related to materialization (both with and without sem-join.

Simpler test case:

------------------------------------------
drop table if exists t1, t2, t10;

set @@storage_engine=myisam;

create table t1(a int, b int);
insert into t1 values (5,5),(7,7);

create table t2(c int, d int);
insert into t2 values (5,5),(7,7);

create table t10 (pk int, a int, primary key(pk));
insert into t10 values (5,5), (7,7);

– Force a very simple query plan
set join_cache_level=0;
set optimizer_switch='semijoin=off,materialization=on,subquery_cache=off';

prepare s1 from
'select * from t1 left join t2 on (t2.c = t1.a and t2.c in (select pk from t10))';
execute s1;
execute s1;

deallocate prepare s1;

Comment by Timour Katchaounov (Inactive) [ 2013-06-03 ]

Approved by SergeyP, pushed to mdev-83.

Generated at Thu Feb 08 06:57:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.