Skip to content

Commit cd03bf5

Browse files
montywispetrunia
authored andcommitted
Fixed costs in JOIN_TAB::estimate_scan_time() and HEAP
MDEV-35958 Cost estimates for materialized derived tables are poor (Backport 11.8->11.4, the same patch) Estimate_scan_time() calculates the cost of scanning a derivied table. The old code did not take into account that the temporary table heap table may be converted to Aria. Things fixed: - Added checking if the temporary tables data will fit in the heap. If not, then calculate the cost based on the designated internal temporary table engine (Aria). - Removed MY_MAX(records, 1000) and instead trust the optimizer's estimate of records. This reduces the cost of temporary tables a bit for small tables, which caused a few changes in mtr results. - Fixed cost calculation for HEAP. - HEAP costs->row_next_find_cost was not set. This does not affect old costs calculation as this cost slot was not used anywhere. Now HEAP cost->row_next_find_cost is set, which allowed me to remove some duplicated computation in ha_heap::scan_time() Reviewed by: Sergei Petrunia <sergey@mariadb.com>
1 parent b7d67ce commit cd03bf5

File tree

10 files changed

+316
-238
lines changed

10 files changed

+316
-238
lines changed

mysql-test/main/cte_recursive.result

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,8 +3913,8 @@ id select_type table type possible_keys key key_len ref rows Extra
39133913
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
39143914
1 PRIMARY <derived3> ref key0 key0 23 test.t1.a1 1 FirstMatch(t1)
39153915
3 DERIVED t2 const PRIMARY PRIMARY 22 const 1 Using index
3916-
4 RECURSIVE UNION tt2 ALL b1 NULL NULL NULL 14 Using where
3917-
4 RECURSIVE UNION <derived3> ref key0 key0 23 test.tt2.b1 1
3916+
4 RECURSIVE UNION <derived3> ALL NULL NULL NULL NULL 2 Using where
3917+
4 RECURSIVE UNION tt2 ref b1 b1 23 cte.a2 1
39183918
NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL
39193919
analyze format=json select fv
39203920
from (select t1.a1, f1(t1.a2) fv from t1) dt
@@ -4013,38 +4013,37 @@ ANALYZE
40134013
"nested_loop": [
40144014
{
40154015
"table": {
4016-
"table_name": "tt2",
4016+
"table_name": "<derived3>",
40174017
"access_type": "ALL",
4018-
"possible_keys": ["b1"],
40194018
"loops": 1,
40204019
"r_loops": 1,
4021-
"rows": 14,
4022-
"r_rows": 14,
4020+
"rows": 2,
4021+
"r_rows": 1,
40234022
"cost": "REPLACED",
40244023
"r_table_time_ms": "REPLACED",
40254024
"r_other_time_ms": "REPLACED",
4026-
"r_engine_stats": REPLACED,
40274025
"filtered": 100,
40284026
"r_filtered": 100,
4029-
"attached_condition": "tt2.b1 is not null"
4027+
"attached_condition": "cte.a2 is not null"
40304028
}
40314029
},
40324030
{
40334031
"table": {
4034-
"table_name": "<derived3>",
4032+
"table_name": "tt2",
40354033
"access_type": "ref",
4036-
"possible_keys": ["key0"],
4037-
"key": "key0",
4034+
"possible_keys": ["b1"],
4035+
"key": "b1",
40384036
"key_length": "23",
4039-
"used_key_parts": ["a2"],
4040-
"ref": ["test.tt2.b1"],
4041-
"loops": 14,
4042-
"r_loops": 14,
4037+
"used_key_parts": ["b1"],
4038+
"ref": ["cte.a2"],
4039+
"loops": 2,
4040+
"r_loops": 1,
40434041
"rows": 1,
4044-
"r_rows": 0.071428571,
4042+
"r_rows": 1,
40454043
"cost": "REPLACED",
40464044
"r_table_time_ms": "REPLACED",
40474045
"r_other_time_ms": "REPLACED",
4046+
"r_engine_stats": REPLACED,
40484047
"filtered": 100,
40494048
"r_filtered": 100
40504049
}

0 commit comments

Comments
 (0)