[MDEV-2592] LP:858038 - The result of a query with NOT IN subquery depends on the state of the optimizer switch Created: 2011-09-24  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: Igor Babaev Assignee: Timour Katchaounov (Inactive)
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug858038.xml    

 Description   

The following query from subselect_mat_cost.test

select count
from CountryLanguage
where (Language, Country) NOT IN
(SELECT City.Name, Country.Code
FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000));

returns different results with different settings of the optimizer switch:

MariaDB [world]> set optimizer_switch='materialization=off';
Query OK, 0 rows affected (0.00 sec)

MariaDB [world]> EXPLAIN
-> select count
-> from CountryLanguage
-> where (Language, Country) NOT IN
-> (SELECT City.Name, Country.Code
-> FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000));
--------------------------------------------------------------------------------------------------------------------+

id select_type table type possible_keys key key_len ref rows Extra

--------------------------------------------------------------------------------------------------------------------+

1 PRIMARY CountryLanguage index NULL PRIMARY 33 NULL 984 Using where; Using index
2 DEPENDENT SUBQUERY City ALL NULL NULL NULL NULL 4079 Using where
2 DEPENDENT SUBQUERY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using index

--------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

MariaDB [world]>
MariaDB [world]> select count
-> from CountryLanguage
-> where (Language, Country) NOT IN
-> (SELECT City.Name, Country.Code
-> FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000));
----------

count

----------

979

----------
1 row in set (9.33 sec)

MariaDB [world]> set optimizer_switch='materialization=on';
Query OK, 0 rows affected (0.00 sec)

MariaDB [world]> EXPLAIN
-> select count
-> from CountryLanguage
-> where (Language, Country) NOT IN
-> (SELECT City.Name, Country.Code
-> FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000));
-------------------------------------------------------------------------------------------------------------+

id select_type table type possible_keys key key_len ref rows Extra

-------------------------------------------------------------------------------------------------------------+

1 PRIMARY CountryLanguage index NULL PRIMARY 33 NULL 984 Using where; Using index
2 SUBQUERY City ALL NULL NULL NULL NULL 4079  
2 SUBQUERY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using index

-------------------------------------------------------------------------------------------------------------+
3 rows in set (0.01 sec)

MariaDB [world]>
MariaDB [world]> select count
-> from CountryLanguage
-> where (Language, Country) NOT IN
-> (SELECT City.Name, Country.Code
-> FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000));
----------

count

----------

984

----------
1 row in set (0.12 sec)



 Comments   
Comment by Rasmus Johansson (Inactive) [ 2011-10-03 ]

Launchpad bug id: 858038

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