[MDEV-3479] LP:891995 - Wrong result with semijoin + IN + join_cache_level Created: 2011-11-18  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: Critical
Reporter: Philip Stoev (Inactive) Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug891995.xml    

 Description   

The following query:

SELECT * FROM t1, t2
WHERE t2.a IN (
SELECT b
FROM t3
WHERE t3.d <= t1.d
);

returns 1 row less when executed with semijoin, join_cache_level >= 3:

d a b
w 2 18:56:33
w 5 19:11:10

the correct result is:

d a b
w 2 18:56:33
q 2 18:56:33
w 5 19:11:10

EXPLAIN:

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t3 ALL d NULL NULL NULL 5 Range checked for each record (index map: 0x2); Start temporary
1 PRIMARY t2 hash_ALL PRIMARY #hash#PRIMARY 4 test.t3.b 2 End temporary; Using join buffer (flat, BNLH join)

but the bug was also observed with this EXPLAIN:

d select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t3 ALL col_varchar_key NULL NULL NULL 5 Range checked for each record (index map: 0x2); Start temporary
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t3.col_int_nokey 1 End temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan

The date column does not participate in the query, but its removal causes the bug to disappear. So it may be a record-size issue of some sort.

bzr version-info
revision-id: <email address hidden>
date: 2011-11-17 08:00:22 -0800
build-date: 2011-11-18 12:32:54 +0200
revno: 3291
branch-nick: maria-5.3

test case:

CREATE TABLE t1 ( d varchar(1)) engine=aria;
INSERT INTO t1 VALUES ('w'),('q');

CREATE TABLE t2 ( a int NOT NULL, b time, PRIMARY KEY (a)) engine=aria;
INSERT INTO t2 VALUES (2,'18:56:33'),(5,'19:11:10');

CREATE TABLE t3 ( a int NOT NULL, b int, c int, d varchar(1), PRIMARY KEY (a), KEY (d,c)) engine=aria;
INSERT INTO t3 VALUES (25,158,10,'f'),(26,5,2,'v'),(27,163,103,'f'),(28,2,3,'q'),(29,8,6,'y');

SET SESSION optimizer_switch='semijoin=on,join_cache_hashed=on';
SET SESSION join_cache_level=3;

SELECT * FROM t1, t2
WHERE t2.a IN (
SELECT b
FROM t3
WHERE t3.d <= t1.d
);



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

Launchpad bug id: 891995

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