Skip to content

Commit 89dbe47

Browse files
author
Steinar H. Gunderson
committed
WL #12074: Volcano iterator executor base [1/15, CALC_FOUND_ROWS LIMIT]
Prepatarory patch: Stop pushing LIMIT into filesort if CALC_FOUND_ROWS is enabled. Change-Id: Idf0d7fe97a3e44c2cd42585ad6c39e970ba92a03
1 parent a3a0330 commit 89dbe47

File tree

2 files changed

+51
-57
lines changed

2 files changed

+51
-57
lines changed

mysql-test/suite/opt_trace/r/filesort_pq.result

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,23 +3042,22 @@ ORDER BY f1, f0 LIMIT 30 {
30423042
}
30433043
],
30443044
"filesort_priority_queue_optimization": {
3045-
"limit": 30,
3046-
"chosen": true
3045+
"usable": false,
3046+
"cause": "not applicable (no LIMIT)"
30473047
},
30483048
"filesort_execution": [
30493049
],
30503050
"filesort_summary": {
30513051
"memory_available": 32768,
30523052
"key_size": 9,
3053-
"row_size": 219,
3054-
"max_rows_per_buffer": 31,
3053+
"row_size": 221,
3054+
"max_rows_per_buffer": 110,
30553055
"num_rows_estimate": 110,
30563056
"num_rows_found": 100,
30573057
"num_initial_chunks_spilled_to_disk": 0,
30583058
"peak_memory_used": "NNN",
30593059
"sort_algorithm": "std::sort",
3060-
"unpacked_addon_fields": "using_priority_queue",
3061-
"sort_mode": "<fixed_sort_key, additional_fields>"
3060+
"sort_mode": "<fixed_sort_key, packed_additional_fields>"
30623061
}
30633062
}
30643063
]
@@ -3214,23 +3213,22 @@ ORDER BY f1, f0 LIMIT 0 {
32143213
}
32153214
],
32163215
"filesort_priority_queue_optimization": {
3217-
"limit": 0,
3218-
"chosen": true
3216+
"usable": false,
3217+
"cause": "not applicable (no LIMIT)"
32193218
},
32203219
"filesort_execution": [
32213220
],
32223221
"filesort_summary": {
32233222
"memory_available": 32768,
32243223
"key_size": 9,
3225-
"row_size": 219,
3226-
"max_rows_per_buffer": 1,
3224+
"row_size": 221,
3225+
"max_rows_per_buffer": 110,
32273226
"num_rows_estimate": 110,
32283227
"num_rows_found": 100,
32293228
"num_initial_chunks_spilled_to_disk": 0,
32303229
"peak_memory_used": "NNN",
3231-
"sort_algorithm": "none",
3232-
"unpacked_addon_fields": "using_priority_queue",
3233-
"sort_mode": "<fixed_sort_key, additional_fields>"
3230+
"sort_algorithm": "std::sort",
3231+
"sort_mode": "<fixed_sort_key, packed_additional_fields>"
32343232
}
32353233
}
32363234
]
@@ -3435,23 +3433,22 @@ ORDER BY f2, f0 LIMIT 20 {
34353433
}
34363434
],
34373435
"filesort_priority_queue_optimization": {
3438-
"limit": 20,
3439-
"chosen": true
3436+
"usable": false,
3437+
"cause": "not applicable (no LIMIT)"
34403438
},
34413439
"filesort_execution": [
34423440
],
34433441
"filesort_summary": {
34443442
"memory_available": 32768,
34453443
"key_size": 205,
3446-
"row_size": 415,
3447-
"max_rows_per_buffer": 21,
3444+
"row_size": 417,
3445+
"max_rows_per_buffer": 77,
34483446
"num_rows_estimate": 110,
34493447
"num_rows_found": 89,
34503448
"num_initial_chunks_spilled_to_disk": 0,
34513449
"peak_memory_used": "NNN",
34523450
"sort_algorithm": "std::sort",
3453-
"unpacked_addon_fields": "using_priority_queue",
3454-
"sort_mode": "<fixed_sort_key, additional_fields>"
3451+
"sort_mode": "<fixed_sort_key, packed_additional_fields>"
34553452
}
34563453
}
34573454
]
@@ -3636,23 +3633,22 @@ ORDER BY f2, f0 LIMIT 0 {
36363633
}
36373634
],
36383635
"filesort_priority_queue_optimization": {
3639-
"limit": 0,
3640-
"chosen": true
3636+
"usable": false,
3637+
"cause": "not applicable (no LIMIT)"
36413638
},
36423639
"filesort_execution": [
36433640
],
36443641
"filesort_summary": {
36453642
"memory_available": 32768,
36463643
"key_size": 205,
3647-
"row_size": 415,
3648-
"max_rows_per_buffer": 1,
3644+
"row_size": 417,
3645+
"max_rows_per_buffer": 77,
36493646
"num_rows_estimate": 110,
36503647
"num_rows_found": 89,
36513648
"num_initial_chunks_spilled_to_disk": 0,
36523649
"peak_memory_used": "NNN",
3653-
"sort_algorithm": "none",
3654-
"unpacked_addon_fields": "using_priority_queue",
3655-
"sort_mode": "<fixed_sort_key, additional_fields>"
3650+
"sort_algorithm": "std::sort",
3651+
"sort_mode": "<fixed_sort_key, packed_additional_fields>"
36563652
}
36573653
}
36583654
]
@@ -3847,23 +3843,22 @@ ORDER BY f2, f0 LIMIT 10 OFFSET 10 {
38473843
}
38483844
],
38493845
"filesort_priority_queue_optimization": {
3850-
"limit": 20,
3851-
"chosen": true
3846+
"usable": false,
3847+
"cause": "not applicable (no LIMIT)"
38523848
},
38533849
"filesort_execution": [
38543850
],
38553851
"filesort_summary": {
38563852
"memory_available": 32768,
38573853
"key_size": 205,
3858-
"row_size": 415,
3859-
"max_rows_per_buffer": 21,
3854+
"row_size": 417,
3855+
"max_rows_per_buffer": 77,
38603856
"num_rows_estimate": 110,
38613857
"num_rows_found": 89,
38623858
"num_initial_chunks_spilled_to_disk": 0,
38633859
"peak_memory_used": "NNN",
38643860
"sort_algorithm": "std::sort",
3865-
"unpacked_addon_fields": "using_priority_queue",
3866-
"sort_mode": "<fixed_sort_key, additional_fields>"
3861+
"sort_mode": "<fixed_sort_key, packed_additional_fields>"
38673862
}
38683863
}
38693864
]
@@ -4048,23 +4043,22 @@ ORDER BY f2, f0 LIMIT 0 OFFSET 10 {
40484043
}
40494044
],
40504045
"filesort_priority_queue_optimization": {
4051-
"limit": 10,
4052-
"chosen": true
4046+
"usable": false,
4047+
"cause": "not applicable (no LIMIT)"
40534048
},
40544049
"filesort_execution": [
40554050
],
40564051
"filesort_summary": {
40574052
"memory_available": 32768,
40584053
"key_size": 205,
4059-
"row_size": 415,
4060-
"max_rows_per_buffer": 11,
4054+
"row_size": 417,
4055+
"max_rows_per_buffer": 77,
40614056
"num_rows_estimate": 110,
40624057
"num_rows_found": 89,
40634058
"num_initial_chunks_spilled_to_disk": 0,
40644059
"peak_memory_used": "NNN",
40654060
"sort_algorithm": "std::sort",
4066-
"unpacked_addon_fields": "using_priority_queue",
4067-
"sort_mode": "<fixed_sort_key, additional_fields>"
4061+
"sort_mode": "<fixed_sort_key, packed_additional_fields>"
40684062
}
40694063
}
40704064
]
@@ -5042,22 +5036,22 @@ ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30 {
50425036
}
50435037
],
50445038
"filesort_priority_queue_optimization": {
5045-
"limit": 60,
5046-
"chosen": true
5039+
"usable": false,
5040+
"cause": "not applicable (no LIMIT)"
50475041
},
50485042
"filesort_execution": [
50495043
],
50505044
"filesort_summary": {
50515045
"memory_available": 327680,
50525046
"key_size": 17,
50535047
"row_size": 17,
5054-
"max_rows_per_buffer": 61,
5048+
"max_rows_per_buffer": 1510,
50555049
"num_rows_estimate": 1510,
50565050
"num_rows_found": 1500,
50575051
"num_initial_chunks_spilled_to_disk": 0,
50585052
"peak_memory_used": "NNN",
5059-
"sort_algorithm": "std::sort",
5060-
"unpacked_addon_fields": "using_priority_queue",
5053+
"sort_algorithm": "std::stable_sort",
5054+
"unpacked_addon_fields": "using_heap_table",
50615055
"sort_mode": "<fixed_sort_key, rowid>"
50625056
}
50635057
}
@@ -5434,22 +5428,22 @@ ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30 {
54345428
}
54355429
],
54365430
"filesort_priority_queue_optimization": {
5437-
"limit": 60,
5438-
"chosen": true
5431+
"usable": false,
5432+
"cause": "not applicable (no LIMIT)"
54395433
},
54405434
"filesort_execution": [
54415435
],
54425436
"filesort_summary": {
54435437
"memory_available": 327680,
54445438
"key_size": 17,
54455439
"row_size": 17,
5446-
"max_rows_per_buffer": 61,
5440+
"max_rows_per_buffer": 1195,
54475441
"num_rows_estimate": 1195,
54485442
"num_rows_found": 1185,
54495443
"num_initial_chunks_spilled_to_disk": 0,
54505444
"peak_memory_used": "NNN",
5451-
"sort_algorithm": "std::sort",
5452-
"unpacked_addon_fields": "using_priority_queue",
5445+
"sort_algorithm": "std::stable_sort",
5446+
"unpacked_addon_fields": "using_heap_table",
54535447
"sort_mode": "<fixed_sort_key, rowid>"
54545448
}
54555449
}
@@ -7856,23 +7850,22 @@ ORDER BY f2, f0 LIMIT 15 OFFSET 15 {
78567850
}
78577851
],
78587852
"filesort_priority_queue_optimization": {
7859-
"limit": 30,
7860-
"chosen": true
7853+
"usable": false,
7854+
"cause": "not applicable (no LIMIT)"
78617855
},
78627856
"filesort_execution": [
78637857
],
78647858
"filesort_summary": {
78657859
"memory_available": 327680,
78667860
"key_size": 205,
7867-
"row_size": 415,
7868-
"max_rows_per_buffer": 31,
7861+
"row_size": 417,
7862+
"max_rows_per_buffer": 510,
78697863
"num_rows_estimate": 510,
78707864
"num_rows_found": 445,
78717865
"num_initial_chunks_spilled_to_disk": 0,
78727866
"peak_memory_used": "NNN",
7873-
"sort_algorithm": "std::sort",
7874-
"unpacked_addon_fields": "using_priority_queue",
7875-
"sort_mode": "<fixed_sort_key, additional_fields>"
7867+
"sort_algorithm": "std::stable_sort",
7868+
"sort_mode": "<fixed_sort_key, packed_additional_fields>"
78767869
}
78777870
}
78787871
]

sql/sql_select.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,13 +4450,14 @@ bool JOIN::make_tmp_tables_info() {
44504450
filesort_limit: Return only this many rows from filesort().
44514451
We can use select_limit_cnt only if we have no group_by and 1 table.
44524452
This allows us to use Bounded_queue for queries like:
4453-
"select SQL_CALC_FOUND_ROWS * from t1 order by b desc limit 1;"
4453+
"select * from t1 order by b desc limit 1;"
44544454
m_select_limit == HA_POS_ERROR (we need a full table scan)
44554455
unit->select_limit_cnt == 1 (we only need one row in the result set)
44564456
*/
44574457
if (sort_tab->filesort)
44584458
sort_tab->filesort->limit =
4459-
(has_group_by || (primary_tables > curr_tmp_table + 1))
4459+
(has_group_by || (primary_tables > curr_tmp_table + 1) ||
4460+
calc_found_rows)
44604461
? m_select_limit
44614462
: unit->select_limit_cnt;
44624463
}

0 commit comments

Comments
 (0)