Details
Description
We've encountered inconsistent query results. By an trial/error we found out that the cause of the inconsistency is use of LATERAL DERIVED in the query plan. When it's used, the query doesn't return correct results.
We've found similar open issues already reported, but I can't say if it's the same cause or not:
Disabling the optimization fixed the issue for us and the query results started to behave:
set global optimizer_switch='split_materialized=off'
|
I'm attaching minimal dump, that can be used to reproduce the issue. The query to reproduce the issue is:
SELECT COUNT(*) |
FROM project_time_lines_dates ptld |
|
INNER JOIN date_revision dr |
ON dr.id = ptld.date_revision_id |
|
INNER JOIN ( |
SELECT |
ptld.project_id AS project_id, |
ptld.project_type_id AS project_type_id, |
ptld.leaf_component_id AS leaf_component_id, |
dr.date_id AS date_id, |
MAX(dr.order_idx) AS max_order |
FROM project_time_lines_dates ptld |
INNER JOIN date_revision dr |
ON dr.id = ptld.date_revision_id |
WHERE dr.date_id IN ( |
SELECT DISTINCT dr.date_id |
FROM time_sheet_activities_time_sheet_roles_date_revisions tstrdr |
INNER JOIN date_revision dr |
ON dr.id = tstrdr.start_date_revision_id |
WHERE tstrdr.offered_for_overdue |
)
|
|
GROUP BY |
ptld.project_id,
|
ptld.project_type_id,
|
ptld.leaf_component_id,
|
dr.date_id
|
) max_anticipated
|
ON max_anticipated.project_id = ptld.project_id |
AND max_anticipated.project_type_id = ptld.project_type_id |
AND max_anticipated.date_id = dr.date_id |
AND max_anticipated.max_order = dr.order_idx |
|
WHERE dr.is_anticipated = TRUE |
AND ptld.project_id = 5896 |
The anticipated result is 2, but when LATERAL DERIVED is used, the number of returned rows is 0.
EXPLAIN of the query with disabled LATERAL DERIVED looks like this:
+------+-------------+------------+--------+---------------------------------------------------------------------------------------+------------------------+---------+---------------------------------------------+------+----------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+------------+--------+---------------------------------------------------------------------------------------+------------------------+---------+---------------------------------------------+------+----------------------------------------------+
|
| 1 | PRIMARY | ptld | ref | project_id_project_type_id_leaf_component_id_date_revision_id,project_id,project_id_2 | project_id_2 | 4 | const | 34 | Using index |
|
| 1 | PRIMARY | dr | eq_ref | PRIMARY,date_id | PRIMARY | 4 | bugreport.ptld.date_revision_id | 1 | Using where |
|
| 1 | PRIMARY | <derived2> | ref | key1 | key1 | 9 | bugreport.dr.date_id,bugreport.dr.order_idx | 10 | Using where |
|
| 2 | DERIVED | ptld | ref | project_id_project_type_id_leaf_component_id_date_revision_id,project_id,project_id_2 | project_id_2 | 4 | const | 34 | Using index; Using temporary; Using filesort |
|
| 2 | DERIVED | dr | eq_ref | PRIMARY,date_id | PRIMARY | 4 | bugreport.ptld.date_revision_id | 1 | |
|
| 2 | DERIVED | dr | ref | PRIMARY,date_id | date_id | 4 | bugreport.dr.date_id | 1 | Using index |
|
| 2 | DERIVED | tstrdr | ref | start_date_revision_id | start_date_revision_id | 5 | bugreport.dr.id | 4 | Using where; FirstMatch(dr) |
|
+------+-------------+------------+--------+---------------------------------------------------------------------------------------+------------------------+---------+---------------------------------------------+------+----------------------------------------------+
|
EXPLAIN of the query with enabled LATERAL DERIVED looks like this:
+------+-----------------+------------+--------+---------------------------------------------------------------------------------------+------------------------+---------+---------------------------------+------+---------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-----------------+------------+--------+---------------------------------------------------------------------------------------+------------------------+---------+---------------------------------+------+---------------------------------+
|
| 1 | PRIMARY | ptld | ref | project_id_project_type_id_leaf_component_id_date_revision_id,project_id,project_id_2 | project_id_2 | 4 | const | 34 | Using index |
|
| 1 | PRIMARY | dr | eq_ref | PRIMARY,date_id | PRIMARY | 4 | bugreport.ptld.date_revision_id | 1 | Using where |
|
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 4 | bugreport.ptld.project_type_id | 2 | Using where |
|
| 2 | LATERAL DERIVED | dr | ref | PRIMARY,date_id | date_id | 4 | bugreport.dr.date_id | 1 | Using temporary; Using filesort |
|
| 2 | LATERAL DERIVED | dr | ref | PRIMARY,date_id | date_id | 4 | bugreport.dr.date_id | 1 | Using index; Start temporary |
|
| 2 | LATERAL DERIVED | tstrdr | ref | start_date_revision_id | start_date_revision_id | 5 | bugreport.dr.id | 4 | Using where; End temporary |
|
| 2 | LATERAL DERIVED | ptld | ref | project_id_project_type_id_leaf_component_id_date_revision_id,project_id,project_id_2 | project_id_2 | 4 | const | 34 | Using index |
|
+------+-----------------+------------+--------+---------------------------------------------------------------------------------------+------------------------+---------+---------------------------------+------+---------------------------------+
|
7 rows in set (0.001 sec)
|
Attachments
- bugreport.sql.gz
- 227 kB
- raw_ab.tar.gz
- 0.6 kB
Issue Links
- is duplicated by
-
MDEV-26749 Optimizer_switch split_materialized Returns Wrong Results
-
- Closed
-
-
MDEV-26965 Left join to derived table on multiple clauses with aggregation returns missing/incorrect results
-
- Closed
-
- relates to
-
MDEV-25714 Join using derived with aggregation returns incorrect results
-
- Closed
-
-
MDEV-26965 Left join to derived table on multiple clauses with aggregation returns missing/incorrect results
-
- Closed
-
-
MDEV-27510 Query returns wrong result when using split optimization
-
- Closed
-
Activity
alice,
Please create a new MDEV for the bug of mhadji@gmail.com. The cause of his problem is quite different.
If we look at the output of EXPLAIN FORMAT=JSON for the first reported test we see that the condition
ptld.date_revision_id = dr.`id` has been lost:
MariaDB [test]> EXPLAIN FORMAT=JSON
|
-> SELECT COUNT(*)
|
-> FROM project_time_lines_dates ptld
|
->
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = ptld.date_revision_id
|
->
|
-> INNER JOIN (
|
-> SELECT
|
-> ptld.project_id AS project_id,
|
-> ptld.project_type_id AS project_type_id,
|
-> ptld.leaf_component_id AS leaf_component_id,
|
-> dr.date_id AS date_id,
|
-> MAX(dr.order_idx) AS max_order
|
-> FROM project_time_lines_dates ptld
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = ptld.date_revision_id
|
-> WHERE dr.date_id IN (
|
-> SELECT DISTINCT dr.date_id
|
-> FROM time_sheet_activities_time_sheet_roles_date_revisions tstrdr
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = tstrdr.start_date_revision_id
|
-> WHERE tstrdr.offered_for_overdue
|
-> )
|
->
|
-> GROUP BY
|
-> ptld.project_id,
|
-> ptld.project_type_id,
|
-> ptld.leaf_component_id,
|
-> dr.date_id
|
-> ) max_anticipated
|
-> ON max_anticipated.project_id = ptld.project_id
|
-> AND max_anticipated.project_type_id = ptld.project_type_id
|
-> AND max_anticipated.date_id = dr.date_id
|
-> AND max_anticipated.max_order = dr.order_idx
|
->
|
-> WHERE dr.is_anticipated = TRUE
|
-> AND ptld.project_id = 5896
|
-> ;
|
ERROR 2006 (HY000): MySQL server has gone away
|
No connection. Trying to reconnect...
|
Connection id: 8
|
Current database: test
|
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| EXPLAIN |
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| {
|
"query_block": {
|
"select_id": 1,
|
"table": {
|
"table_name": "ptld",
|
"access_type": "ref",
|
"possible_keys": [
|
"project_id_project_type_id_leaf_component_id_date_revision_id",
|
"project_id",
|
"project_id_2"
|
],
|
"key": "project_id_project_type_id_leaf_component_id_date_revision_id",
|
"key_length": "4",
|
"used_key_parts": ["project_id"],
|
"ref": ["const"],
|
"rows": 34,
|
"filtered": 100,
|
"using_index": true
|
},
|
"table": {
|
"table_name": "dr",
|
"access_type": "eq_ref",
|
"possible_keys": ["PRIMARY", "date_id"],
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"ref": ["test.ptld.date_revision_id"],
|
"rows": 1,
|
"filtered": 100,
|
"attached_condition": "dr.is_anticipated = 1"
|
},
|
"table": {
|
"table_name": "<derived2>",
|
"access_type": "ref",
|
"possible_keys": ["key0"],
|
"key": "key0",
|
"key_length": "4",
|
"used_key_parts": ["project_type_id"],
|
"ref": ["test.ptld.project_type_id"],
|
"rows": 2,
|
"filtered": 100,
|
"attached_condition": "max_anticipated.project_id = 5896 and max_anticipated.date_id = dr.date_id and max_anticipated.max_order = dr.order_idx",
|
"materialized": {
|
"lateral": 1,
|
"query_block": {
|
"select_id": 2,
|
"filesort": {
|
"sort_key": "ptld.leaf_component_id",
|
"temporary_table": {
|
"table": {
|
"table_name": "dr",
|
"access_type": "ref",
|
"possible_keys": ["PRIMARY", "date_id"],
|
"key": "date_id",
|
"key_length": "4",
|
"used_key_parts": ["date_id"],
|
"ref": ["test.dr.date_id"],
|
"rows": 1,
|
"filtered": 100
|
},
|
"duplicates_removal": {
|
"table": {
|
"table_name": "dr",
|
"access_type": "ref",
|
"possible_keys": ["PRIMARY", "date_id"],
|
"key": "date_id",
|
"key_length": "4",
|
"used_key_parts": ["date_id"],
|
"ref": ["test.dr.date_id"],
|
"rows": 1,
|
"filtered": 100,
|
"using_index": true
|
},
|
"table": {
|
"table_name": "tstrdr",
|
"access_type": "ref",
|
"possible_keys": ["start_date_revision_id"],
|
"key": "start_date_revision_id",
|
"key_length": "5",
|
"used_key_parts": ["start_date_revision_id"],
|
"ref": ["test.dr.id"],
|
"rows": 4,
|
"filtered": 100,
|
"attached_condition": "tstrdr.offered_for_overdue <> 0"
|
}
|
},
|
"table": {
|
"table_name": "ptld",
|
"access_type": "ref",
|
"possible_keys": [
|
"project_id_project_type_id_leaf_component_id_date_revision_id",
|
"project_id",
|
"project_id_2"
|
],
|
"key": "project_id_project_type_id_leaf_component_id_date_revision_id",
|
"key_length": "4",
|
"used_key_parts": ["project_id"],
|
"ref": ["const"],
|
"rows": 34,
|
"filtered": 100,
|
"using_index": true
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
} |
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
After the fix we have:
MariaDB [test]> EXPLAIN FORMAT=JSON
|
-> SELECT COUNT(*)
|
-> FROM project_time_lines_dates ptld
|
->
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = ptld.date_revision_id
|
->
|
-> INNER JOIN (
|
-> SELECT
|
-> ptld.project_id AS project_id,
|
-> ptld.project_type_id AS project_type_id,
|
-> ptld.leaf_component_id AS leaf_component_id,
|
-> dr.date_id AS date_id,
|
-> MAX(dr.order_idx) AS max_order
|
-> FROM project_time_lines_dates ptld
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = ptld.date_revision_id
|
-> WHERE dr.date_id IN (
|
-> SELECT DISTINCT dr.date_id
|
-> FROM time_sheet_activities_time_sheet_roles_date_revisions tstrdr
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = tstrdr.start_date_revision_id
|
-> WHERE tstrdr.offered_for_overdue
|
-> )
|
->
|
-> GROUP BY
|
-> ptld.project_id,
|
-> ptld.project_type_id,
|
-> ptld.leaf_component_id,
|
-> dr.date_id
|
-> ) max_anticipated
|
-> ON max_anticipated.project_id = ptld.project_id
|
-> AND max_anticipated.project_type_id = ptld.project_type_id
|
-> AND max_anticipated.date_id = dr.date_id
|
-> AND max_anticipated.max_order = dr.order_idx
|
->
|
-> WHERE dr.is_anticipated = TRUE
|
-> AND ptld.project_id = 5896
|
-> ;
|
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| EXPLAIN |
|
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
| {
|
"query_block": {
|
"select_id": 1,
|
"table": {
|
"table_name": "ptld",
|
"access_type": "ref",
|
"possible_keys": [
|
"project_id_project_type_id_leaf_component_id_date_revision_id",
|
"project_id",
|
"project_id_2"
|
],
|
"key": "project_id_project_type_id_leaf_component_id_date_revision_id",
|
"key_length": "4",
|
"used_key_parts": ["project_id"],
|
"ref": ["const"],
|
"rows": 34,
|
"filtered": 100,
|
"using_index": true
|
},
|
"table": {
|
"table_name": "dr",
|
"access_type": "eq_ref",
|
"possible_keys": ["PRIMARY", "date_id"],
|
"key": "PRIMARY",
|
"key_length": "4",
|
"used_key_parts": ["id"],
|
"ref": ["test.ptld.date_revision_id"],
|
"rows": 1,
|
"filtered": 100,
|
"attached_condition": "dr.is_anticipated = 1"
|
},
|
"table": {
|
"table_name": "<derived2>",
|
"access_type": "ref",
|
"possible_keys": ["key0"],
|
"key": "key0",
|
"key_length": "4",
|
"used_key_parts": ["project_type_id"],
|
"ref": ["test.ptld.project_type_id"],
|
"rows": 2,
|
"filtered": 100,
|
"attached_condition": "max_anticipated.project_id = 5896 and max_anticipated.date_id = dr.date_id and max_anticipated.max_order = dr.order_idx",
|
"materialized": {
|
"lateral": 1,
|
"query_block": {
|
"select_id": 2,
|
"filesort": {
|
"sort_key": "ptld.leaf_component_id",
|
"temporary_table": {
|
"table": {
|
"table_name": "dr",
|
"access_type": "ref",
|
"possible_keys": ["PRIMARY", "date_id"],
|
"key": "date_id",
|
"key_length": "4",
|
"used_key_parts": ["date_id"],
|
"ref": ["test.dr.date_id"],
|
"rows": 1,
|
"filtered": 100
|
},
|
"duplicates_removal": {
|
"table": {
|
"table_name": "dr",
|
"access_type": "ref",
|
"possible_keys": ["PRIMARY", "date_id"],
|
"key": "date_id",
|
"key_length": "4",
|
"used_key_parts": ["date_id"],
|
"ref": ["test.dr.date_id"],
|
"rows": 1,
|
"filtered": 100,
|
"using_index": true
|
},
|
"table": {
|
"table_name": "tstrdr",
|
"access_type": "ref",
|
"possible_keys": ["start_date_revision_id"],
|
"key": "start_date_revision_id",
|
"key_length": "5",
|
"used_key_parts": ["start_date_revision_id"],
|
"ref": ["test.dr.id"],
|
"rows": 4,
|
"filtered": 100,
|
"attached_condition": "tstrdr.offered_for_overdue <> 0"
|
}
|
},
|
"table": {
|
"table_name": "ptld",
|
"access_type": "ref",
|
"possible_keys": [
|
"project_id_project_type_id_leaf_component_id_date_revision_id",
|
"project_id",
|
"project_id_2"
|
],
|
"key": "project_id_project_type_id_leaf_component_id_date_revision_id",
|
"key_length": "4",
|
"used_key_parts": ["project_id"],
|
"ref": ["const"],
|
"rows": 34,
|
"filtered": 100,
|
"attached_condition": "ptld.date_revision_id = dr.`id`",
|
"using_index": true
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
} |
|
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
MariaDB [test]> SELECT COUNT(*)
|
-> FROM project_time_lines_dates ptld
|
->
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = ptld.date_revision_id
|
->
|
-> INNER JOIN (
|
-> SELECT
|
-> ptld.project_id AS project_id,
|
-> ptld.project_type_id AS project_type_id,
|
-> ptld.leaf_component_id AS leaf_component_id,
|
-> dr.date_id AS date_id,
|
-> MAX(dr.order_idx) AS max_order
|
-> FROM project_time_lines_dates ptld
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = ptld.date_revision_id
|
-> WHERE dr.date_id IN (
|
-> SELECT DISTINCT dr.date_id
|
-> FROM time_sheet_activities_time_sheet_roles_date_revisions tstrdr
|
-> INNER JOIN date_revision dr
|
-> ON dr.id = tstrdr.start_date_revision_id
|
-> WHERE tstrdr.offered_for_overdue
|
-> )
|
->
|
-> GROUP BY
|
-> ptld.project_id,
|
-> ptld.project_type_id,
|
-> ptld.leaf_component_id,
|
-> dr.date_id
|
-> ) max_anticipated
|
-> ON max_anticipated.project_id = ptld.project_id
|
-> AND max_anticipated.project_type_id = ptld.project_type_id
|
-> AND max_anticipated.date_id = dr.date_id
|
-> AND max_anticipated.max_order = dr.order_idx
|
->
|
-> WHERE dr.is_anticipated = TRUE
|
-> AND ptld.project_id = 5896
|
-> ;
|
+----------+
|
| COUNT(*) |
|
+----------+
|
| 2 |
|
+----------+
|
A fix for this bug was pushed into 10.3. It has to be merged upstream as it is.
The output of EXPLAIN FORMAT=JSON for the last query shows the the condition reporting_person = 1 has been lost:
MariaDB [test]> EXPLAIN FORMAT=JSON
-> SELECT t1.id
-> FROM t1
-> JOIN t3 ON t3.t1_id = t1.id
-> JOIN (SELECT t1_id FROM t2 WHERE reporting_person = 1 GROUP BY t1_id) tx
-> ON tx.t1_id = t1.id
-> WHERE t1.id in(1, 2070);
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {
"query_block": {
"select_id": 1,
"table": {
"table_name": "t3",
"access_type": "index",
"possible_keys": ["t1_id"],
"key": "t1_id",
"key_length": "15",
"used_key_parts": ["t1_id", "YEAR", "quarter"],
"rows": 1,
"filtered": 100,
"attached_condition": "t3.t1_id in (1,2070) and t3.t1_id is not null and t3.t1_id is not null",
"using_index": true
},
"table": {
"table_name": "t1",
"access_type": "eq_ref",
"possible_keys": ["id"],
"key": "id",
"key_length": "5",
"used_key_parts": ["id"],
"ref": ["test.t3.t1_id"],
"rows": 1,
"filtered": 100,
"using_index": true
},
"table": {
"table_name": "<derived2>",
"access_type": "ref",
"possible_keys": ["key0"],
"key": "key0",
"key_length": "5",
"used_key_parts": ["t1_id"],
"ref": ["test.t3.t1_id"],
"rows": 2,
"filtered": 100,
"materialized": {
"lateral": 1,
"query_block": {
"select_id": 2,
"outer_ref_condition": "t1.`id` is not null",
"table": {
"table_name": "t2",
"access_type": "ref",
"possible_keys": ["t1_id"],
"key": "t1_id",
"key_length": "5",
"used_key_parts": ["t1_id"],
"ref": ["test.t1.id"],
"rows": 1,
"filtered": 100,
"index_condition": "t2.t1_id in (1,2070)"
}
}
}
}
}
} |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)