[MDEV-2356] LP:879882 - Wrong result with derived_merge=ON, derived table, RIGHT JOIN Created: 2011-10-22  Updated: 2015-02-02  Resolved: 2012-10-04

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

Type: Bug Priority: Major
Reporter: Philip Stoev (Inactive) Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug879882.xml    

 Description   

The following query:

SELECT alias2.b, alias2.c, t1.a
FROM t1 , (
SELECT t3.* FROM t2
RIGHT JOIN t3
ON ( t3.a = t2.b )
) AS alias2
WHERE alias2.b
AND alias2.c = t1.a;

returns no rows with derived_merge=ON (impossible where, even though the WHERE clause is true) and 1 row with derived_merge=ON (which is the correct result:

EXPLAIN with derived_merge=ON:

1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Note 1003 select 8 AS `b`,'c' AS `c`,'c' AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where 0

EXPLAIN with derived_merge=off:

1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00  
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00  
2 DERIVED t2 system NULL NULL NULL NULL 0 0.00 const row not found
2 DERIVED t3 system NULL NULL NULL NULL 1 100.00  

select 8 AS `b`,'c' AS `c`,'c' AS `a` from `test`.`t1` join (select 29 AS `a`,8 AS `b`,'c' AS `c` from `test`.`t3` left join `test`.`t2` on(0)) `alias2` where (8)

minimal optimizer switch: derived_merge=on
full optimizer_switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=on,mrr_cost_based=off,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

test case:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 ( a varchar(1)) engine=myisam ;
INSERT INTO t1 VALUES ('c');

DROP TABLE IF EXISTS t2;
CREATE TABLE t2 ( b int) engine=myisam;

DROP TABLE IF EXISTS t3;
CREATE TABLE t3 ( a int(11) NOT NULL , b int, c varchar(1)) engine=myisam;
INSERT INTO t3 VALUES (29,8,'c');

SELECT alias2.b, alias2.c, t1.a
FROM t1 , (
SELECT t3.* FROM t2
RIGHT JOIN t3
ON ( t3.a = t2.b )
) AS alias2
WHERE alias2.b
AND alias2.c = t1.a;

This particular test case contains a degenerate WHERE condition, however the bug was also observed with a WHERE condition containing x IN (SELECT y), so I think it is a valid bug.

bzr version-info:

revision-id: <email address hidden>
date: 2011-10-22 00:14:27 -0700
build-date: 2011-10-22 15:04:21 +0300
revno: 3246
branch-nick: maria-5.3



 Comments   
Comment by Rasmus Johansson (Inactive) [ 2011-12-13 ]

Launchpad bug id: 879882

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