[MDEV-2251] LP:702384 - Wrong empty result in subselect_sj.test:Bug#49097 when all subquery related optimizer switches are ON 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: Timour Katchaounov (Inactive)
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug702384.xml    

 Description   

The following test case for Bug#49097, extracted from subselect_sj
produces an incorrect empty result for all tree statements, when all
three optimizer siwtches are ON: materialization, in_to_exists, semijoin.
This is the only combination of switches that exposes the wrong
result.

--echo
--echo Bug#49097 subquery with view generates wrong result with
--echo non-prepared statement
--echo

--disable_warnings
DROP TABLE IF EXISTS t1, t2;
DROP VIEW IF EXISTS v1;
--enable_warnings

CREATE TABLE t1 (
city VARCHAR(50) NOT NULL,
country_id SMALLINT UNSIGNED NOT NULL
);

INSERT INTO t1 VALUES
('Batna',2),
('Bchar',2),
('Skikda',2),
('Tafuna',3),
('Algeria',2) ;

CREATE TABLE t2 (
country_id SMALLINT UNSIGNED NOT NULL,
country VARCHAR(50) NOT NULL
);

INSERT INTO t2 VALUES
(2,'Algeria'),
(3,'XAmerican Samoa') ;

CREATE VIEW v1 AS
SELECT country_id, country
FROM t2
WHERE LEFT(country,1) = "A"
;

set @@optimizer_switch='materialization=on,in_to_exists=on,semijoin=on';

SELECT city, country_id
FROM t1
WHERE country_id IN (
SELECT country_id
FROM t2
WHERE LEFT(country,1) = "A"
);

SELECT city, country_id
FROM t1
WHERE country_id IN (
SELECT country_id
FROM v1
);

PREPARE stmt FROM
"
SELECT city, country_id
FROM t1
WHERE country_id IN (
SELECT country_id
FROM v1
);
";

execute stmt;

deallocate prepare stmt;
drop table t1, t2;
drop view v1;



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

Re: Wrong empty result in subselect_sj.test:Bug#49097 when all subquery related optimizer switches are ON
The bug is fixed after Monty's patch for 5.3-mwl89:

revno: 2877
committer: Michael Widenius <monty@askmonty.org>
branch nick: maria-5.3-mwl89
timestamp: Fri 2011-01-14 01:26:20 +0200
message:
Don't recalculate conditions that have already been checked.
This fixes the wrong result in tests like compress, join, join_cache, greedy_optimizer and select_pkeycache

Comment by Rasmus Johansson (Inactive) [ 2011-01-14 ]

Launchpad bug id: 702384

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