Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL)
Description
Please check the following test case kindly supplied by a customer of ours.
The 2nd query produces wrong resultset (should list all rows , it only lists those
explicited by the second condition).
If optimizer switch semijoin is turned off, it will produce correct results.
This bug is not present in Oracle MySQL 5.6.
CREATE TABLE `store_loan` (
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`local_name` varchar(64) NOT NULL,
|
PRIMARY KEY (`id`)
|
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1;
|
|
insert into `store_loan`(`id`,`local_name`) values
|
(1,'Cash Advance'),
|
(2,'Cash Advance'),
|
(3,'Rollover'),
|
(4,'AL Installment'),
|
(5,'AL Installment'),
|
(6,'AL Installment'),
|
(7,'AL Installment'),
|
(8,'AL Installment'),
|
(9,'AL Installment'),
|
(10,'Internet Payday'),
|
(11,'Rollover - Internet Payday'),
|
(12,'AL Monthly Installment'),
|
(13,'AL Semi-Monthly Installment');
|
|
## Make sure @@Optimizer_switch semijoin=on is set
|
## current settings in my env is: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=off
|
##
|
## I would expect both queries below to return the same result set since the sub-queries in query 1 returns the same data s the IN() clause in query 2
|
|
#Query 1
|
SELECT SQL_NO_CACHE sl.id
|
FROM store_loan sl
|
WHERE (
|
sl.id IN (SELECT A.id FROM store_loan AS A WHERE A.local_name IN (SELECT B.local_name FROM store_loan AS B WHERE B.id IN (0,4,12,13,1,10,3,11)))
|
OR
|
(sl.id IN (0,4,12,13,1,10,3,11))
|
);
|
+----+
|
| id |
|
+----+
|
| 1 |
|
| 3 |
|
| 4 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
+----+
|
7 rows in set (0.01 sec)
|
|
#Query 2
|
SELECT SQL_NO_CACHE sl.id
|
FROM store_loan sl
|
WHERE (
|
sl.id IN (1,2,3,4,5,6,7,8,9,10,11,12,13)
|
OR
|
(sl.id IN (0,4,12,13,1,10,3,11))
|
);
|
+----+
|
| id |
|
+----+
|
| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
+----+
|
13 rows in set (0.00 sec)
|
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Component/s | Optimizer [ 10200 ] | |
Labels | semi-join upstream-not-affected |
Assignee | Varun Gupta [ varun ] |
Status | Open [ 1 ] | In Progress [ 3 ] |
Assignee | Varun Gupta [ varun ] | Sergei Petrunia [ psergey ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Assignee | Sergei Petrunia [ psergey ] | Varun Gupta [ varun ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Fix Version/s | 5.5 [ 15800 ] |
Affects Version/s | 5.5 [ 15800 ] | |
Affects Version/s | 10.0 [ 16000 ] | |
Affects Version/s | 10.1 [ 16100 ] | |
Affects Version/s | 10.2 [ 14601 ] | |
Affects Version/s | 10.3 [ 22126 ] | |
Affects Version/s | 10.1.33 [ 22909 ] |
Fix Version/s | 10.0 [ 16000 ] | |
Fix Version/s | 10.1 [ 16100 ] | |
Fix Version/s | 10.2 [ 14601 ] | |
Fix Version/s | 10.3 [ 22126 ] |
Fix Version/s | 5.5.61 [ 22914 ] | |
Fix Version/s | 10.0.36 [ 22916 ] | |
Fix Version/s | 10.1.34 [ 23100 ] | |
Fix Version/s | 10.2.16 [ 23110 ] | |
Fix Version/s | 10.3.8 [ 23113 ] | |
Fix Version/s | 10.2 [ 14601 ] | |
Fix Version/s | 5.5 [ 15800 ] | |
Fix Version/s | 10.0 [ 16000 ] | |
Fix Version/s | 10.1 [ 16100 ] | |
Fix Version/s | 10.3 [ 22126 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Workflow | MariaDB v3 [ 87353 ] | MariaDB v4 [ 154391 ] |
Zendesk Related Tickets | 197669 |
Output for analyze format=json
ANALYZE
{
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": 6.5435,
"table": {
"table_name": "sl",
"access_type": "index",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["id"],
"r_loops": 1,
"rows": 13,
"r_rows": 13,
"r_total_time_ms": 0.8685,
"filtered": 100,
"r_filtered": 53.846,
"attached_condition": "<in_optimizer>(sl.`id`,sl.`id` in (subquery#2)) or sl.`id` in (0,4,12,13,1,10,3,11)",
"using_index": true
},
"subqueries": [
{
"query_block": {
"select_id": 2,
"r_loops": 1,
"r_total_time_ms": 5.5768,
"table": {
"table_name": "<subquery3>",
"access_type": "ALL",
"possible_keys": ["distinct_key"],
"r_loops": 1,
"rows": 8,
"r_rows": 7,
"r_total_time_ms": 0.0975,
"filtered": 100,
"r_filtered": 100,
"materialized": {
"unique": 1,
"query_block": {
"select_id": 3,
"table": {
"table_name": "B",
"access_type": "ALL",
"possible_keys": ["PRIMARY"],
"r_loops": 1,
"rows": 13,
"r_rows": 13,
"r_total_time_ms": 4.2749,
"filtered": 61.538,
"r_filtered": 53.846,
"attached_condition": "b.`id` in (0,4,12,13,1,10,3,11)"
}
}
}
},
"table": {
"table_name": "A",
"access_type": "eq_ref",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["id"],
"ref": ["func"],
"r_loops": 7,
"rows": 1,
"r_rows": 1,
"r_total_time_ms": 0.5449,
"filtered": 100,
"r_filtered": 14.286,
"attached_condition": "a.local_name = b.local_name"
}
}
}
]
}
}