Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.11
-
Can result in unexpected behaviour
-
Slow query log will now have Rows_examined: to correct value instead of 0 for queries with subquery and degenerate select
-
Q3/2025 Maintenance
Description
Example:
create table t1 (id INT); |
create table t2 (id INT); |
|
insert into t1(id) select seq from seq_1_to_20; |
insert into t2(id) select seq from seq_21_to_40; |
|
select 100 in (select id from t1) AS res; |
+------+
|
| res |
|
+------+
|
| 0 |
|
+------+
|
Here, the slow query log shows Rows_examined as 0, although explain plan shows rows as 20 for the subquery
|
|
# Time: 250621 0:05:55
|
# User@Host: bsrikanth[bsrikanth] @ localhost []
|
# Thread_id: 3 Schema: db1 QC_hit: No
|
# Query_time: 0.001479 Lock_time: 0.000475 Rows_sent: 1 Rows_examined: 0
|
# Rows_affected: 0 Bytes_sent: 60
|
# Pages_accessed: 0 Pages_read: 0 Pages_prefetched: 0 Pages_updated: 0 Old_rows_read: 0
|
# Pages_read_time: 0.0000 Engine_time: 0.0219
|
# Full_scan: Yes Full_join: No Tmp_table: No Tmp_table_on_disk: No
|
# Filesort: No Filesort_on_disk: No Merge_passes: 0 Priority_queue: No
|
#
|
# explain: id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
# explain: 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
# explain: 2 SUBQUERY t1 ALL NULL NULL NULL NULL 20 20.00 100.00 0.00 Using where
|
#
|
|
However, If the top-level SELECT is not a degenerate, the subquery 's table reads will be still counted:
For example, for
select 100 in (select id from t1) AS res from t2; |
+------+
|
| res |
|
+------+
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
| 0 |
|
+------+
|
this time, slow query log shows Rows_examined: 40. Here, 20 rows are from the top-level SELECT and 20 are from the child SELECT.
# Time: 250621 0:06:51
|
# User@Host: bsrikanth[bsrikanth] @ localhost []
|
# Thread_id: 3 Schema: db1 QC_hit: No
|
# Query_time: 0.003730 Lock_time: 0.000845 Rows_sent: 20 Rows_examined: 40
|
# Rows_affected: 0 Bytes_sent: 174
|
# Pages_accessed: 0 Pages_read: 0 Pages_prefetched: 0 Pages_updated: 0 Old_rows_read: 0
|
# Pages_read_time: 0.0000 Engine_time: 0.0728
|
# Tmp_tables: 1 Tmp_disk_tables: 0 Tmp_table_sizes: 1572800
|
# Full_scan: Yes Full_join: No Tmp_table: Yes Tmp_table_on_disk: No
|
# Filesort: No Filesort_on_disk: No Merge_passes: 0 Priority_queue: No
|
#
|
# explain: id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
# explain: 1 PRIMARY t2 ALL NULL NULL NULL NULL 20 20.00 100.00 100.00
|
# explain: 2 SUBQUERY t1 ALL NULL NULL NULL NULL 20 20.00 100.00 0.00 Using where
|
#
|
SET timestamp=1750478811;
|
select 100 in (select id from t1) AS res from t2;
|