Bug #6460 LEFT JOIN with multiple LIKE in WHERE produces wrong result

Submitted: 5 Nov 2004 12:09 Modified: 9 Nov 2004 3:04
Reporter: Mattias Jiderhamn Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.7 OS:Any (all)
Assigned to: Igor Babaev CPU Architecture:Any

[5 Nov 2004 12:09] Mattias Jiderhamn
Description:
# Set up data

DROP TABLE IF EXISTS invoice;
CREATE TABLE invoice (
  id int(11) unsigned NOT NULL auto_increment,
  text_id int(10) unsigned default NULL,
  PRIMARY KEY  (id)
);

INSERT INTO invoice VALUES("1", "0");
INSERT INTO invoice VALUES("2", "10");

DROP TABLE IF EXISTS text_table;
CREATE TABLE text_table (
  text_id char(3) NOT NULL default '',
  language_id char(3) NOT NULL default '',
  text_data text,
  PRIMARY KEY  (text_id,language_id)
);

INSERT INTO text_table VALUES("0", "EN", "0-EN");
INSERT INTO text_table VALUES("0", "SV", "0-SV");
INSERT INTO text_table VALUES("10", "EN", "10-EN");
INSERT INTO text_table VALUES("10", "SV", "10-SV");

# Perform a query

SELECT invoice.id, invoice.text_id, text_table.text_data
FROM invoice
LEFT JOIN text_table ON invoice.text_id = text_table.text_id
AND text_table.language_id = 'SV'
WHERE (invoice.id LIKE '%' OR text_table.text_data LIKE '%');

The expected result is of course
+----+---------+-----------+
| id | text_id | text_data |
+----+---------+-----------+
|  1 |       0 | 0-SV      |
|  2 |      10 | 10-SV     |
+----+---------+-----------+

Though, the query above, run on MySQL 4.1.7 on Windows will provide the following result
+----+---------+-----------+
| id | text_id | text_data |
+----+---------+-----------+
|  1 |       0 | 0-EN      |
|  1 |       0 | 0-SV      |
|  1 |       0 | 10-EN     |
|  1 |       0 | 10-SV     |
|  2 |      10 | 0-EN      |
|  2 |      10 | 0-SV      |
|  2 |      10 | 10-EN     |
|  2 |      10 | 10-SV     |
+----+---------+-----------+

I noticed also, that if one of the two WHERE conditions are removed, the expected result will be provided. Charset is latin1 (latin1_swedish_ci).

How to repeat:
Se above.

Suggested fix:
Make it return the same result as 4.0 did.
[5 Nov 2004 12:44] MySQL Verification Team
Verified with 4.1.8-debug-log
OS: Windows, Linux
[9 Nov 2004 3:04] Igor Babaev
The fix for bug #6307 resolved this problem as well.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.051 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.