[MDEV-3537] LP:702301 - Wrong empty result for MIN/MAX without GROUP BY filtered by an empty subquery Created: 2011-01-13  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: Timour Katchaounov (Inactive) Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug702301.xml    

 Description   

The following test case subselect_mat.test:
"BUG#37896 Assertion on entry of Item_in_subselect::exec on subquery with AND NOT"
produces an incorrect empty result for MIN/MAX, while it should produce a NULL
according to the SQL standard.



 Comments   
Comment by Timour Katchaounov (Inactive) [ 2011-01-13 ]

Re: Wrong empty result for MIN/MAX without GROUP BY filtered by an empty subquery
This bug is also present in the latest MySQL server as:
http://bugs.mysql.com/bug.php?id=40037

Comment by Timour Katchaounov (Inactive) [ 2011-01-13 ]

Re: Wrong empty result for MIN/MAX without GROUP BY filtered by an empty subquery
Test case extracted from subselect_mat.test:

create table t1 (a1 int key);
create table t2 (b1 int);
insert into t1 values (5);
– echo Only the last query returns correct result. Filed as BUG#40037.

  1. Query with group by, executed via materialization
    set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';
    explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
    select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
  2. Query with group by, executed via IN=>EXISTS
    set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off';
    explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
    select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
  1. Executed with materialization
    set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';
    explain select min(a1) from t1 where 7 in (select b1 from t2);
    select min(a1) from t1 where 7 in (select b1 from t2);
  2. Executed via IN=>EXISTS
    set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off';
    explain select min(a1) from t1 where 7 in (select b1 from t2);
    select min(a1) from t1 where 7 in (select b1 from t2);
  3. Executed with semi-join. Notice, this time we get a different result (NULL).
  4. This is the only correct result of all five queries. This difference is
  5. filed as BUG#40037.
    set @@optimizer_switch='materialization=off,in_to_exists=off,semijoin=on';
    explain select min(a1) from t1 where 7 in (select b1 from t2);
    select min(a1) from t1 where 7 in (select b1 from t2);
    drop table t1,t2;
Comment by Igor Babaev [ 2011-07-20 ]

Re: Wrong empty result for MIN/MAX without GROUP BY filtered by an empty subquery
The following simple test case constructed by Timour demonstrates this problem:

CREATE TABLE t1 (a int, b int, KEY (b));
INSERT INTO t1 VALUES (3,1), (4,2);
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (7), (8);

MariaDB [test]> SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2)
Empty set (0.00 sec)

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

Launchpad bug id: 702301

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