[MDEV-31922] Wrong result for LATERAL DERIVED join Created: 2023-08-15  Updated: 2023-08-15  Resolved: 2023-08-15

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 11.0, 11.1, 11.2
Fix Version/s: 11.0.4

Type: Bug Priority: Major
Reporter: Oleg Smirnov Assignee: Oleg Smirnov
Resolution: Duplicate Votes: 0
Labels: None


 Description   

--source include/have_innodb.inc
 
CREATE TABLE t1 (a varchar(35), b varchar(4)) ENGINE=InnoDB;
INSERT INTO t1 VALUES
('Albania','AXA'),('Australia','AUS'),('American Samoa','AMSA'),('Bahamas','BS');
 
CREATE TABLE t2 (a varchar(4), b varchar(50), PRIMARY KEY (b,a), KEY (a)) ENGINE=InnoDB;
INSERT INTO t2 VALUES
  ('BERM','African Methodist Episcopal'),
  ('AUS','Anglican'),('BERM','Anglican'),
  ('BS','Anglican'),
  ('BS','Baptist'),
  ('BS','Methodist'),
  ('BS','Protestant');
 
let query=
SELECT t1.a
FROM (SELECT a FROM t2 GROUP BY a ORDER BY COUNT(DISTINCT b) LIMIT 1) dt
JOIN t1 ON dt.a=t1.b;
--replace_column 9 #
eval EXPLAIN $query;
eval $query;
 
DROP TABLES t1, t2;

There are two rows in the result set although there must be only one ('Australia').
This error only appears when the LATERAL DERIVED join method is employed. In earlier versions of MariaDB the DERIVED method is chosen, so the result is correct. Starting from 11.0 the optimizer chooses LATERAL DERIVED for this query, and the bug appears.



 Comments   
Comment by Oleg Smirnov [ 2023-08-15 ]

Closed as duplicate of MDEV-31887.

Generated at Thu Feb 08 10:27:28 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.