Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
06be2c64
Commit
06be2c64
authored
Jun 30, 2022
by
Vicențiu Ciorbaru
Committed by
Sergei Petrunia
Feb 02, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup: Don't pass THD to get_merge_many_buff_cost_fast
We can pass the cost directly. Reviewer: Monty
parent
ca2851d1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
20 deletions
+26
-20
sql/filesort.cc
sql/filesort.cc
+3
-2
sql/filesort_utils.cc
sql/filesort_utils.cc
+17
-14
sql/filesort_utils.h
sql/filesort_utils.h
+6
-4
No files found.
sql/filesort.cc
View file @
06be2c64
...
...
@@ -1594,9 +1594,10 @@ static bool check_if_pq_applicable(Sort_param *param,
scanning the table and comparing the rows with the where clause!
*/
const
double
sort_merge_cost
=
get_merge_many_buffs_cost_fast
(
table
->
in_use
,
num_rows
,
get_merge_many_buffs_cost_fast
(
num_rows
,
num_available_keys
,
(
uint
)
row_length
);
(
uint
)
row_length
,
ROWID_COMPARE_COST_THD
(
table
->
in_use
));
/*
PQ has cost:
(insert + qsort) * log(queue size) * ROWID_COMPARE_COST
...
...
sql/filesort_utils.cc
View file @
06be2c64
...
...
@@ -27,12 +27,15 @@ PSI_memory_key key_memory_Filesort_buffer_sort_keys;
A local helper function. See comments for get_merge_buffers_cost().
*/
static
double
get_merge_cost
(
double
rowid_compare_cost
,
ha_rows
num_elements
,
ha_rows
num_buffers
,
uint
elem_size
)
static
double
get_merge_cost
(
ha_rows
num_elements
,
ha_rows
num_buffers
,
uint
elem_size
,
double
key_compare_cost
)
{
return
(
2.0
*
((
double
)
num_elements
*
elem_size
)
/
IO_SIZE
+
(
double
)
num_elements
*
log
((
double
)
num_buffers
)
*
rowid
_compare_cost
/
M_LN2
);
key
_compare_cost
/
M_LN2
);
}
/**
...
...
@@ -43,19 +46,19 @@ static double get_merge_cost(double rowid_compare_cost, ha_rows num_elements,
TODO: Use this function for Unique::get_use_cost().
*/
double
get_merge_many_buffs_cost_fast
(
THD
*
thd
,
ha_rows
num_rows
,
double
get_merge_many_buffs_cost_fast
(
ha_rows
num_rows
,
ha_rows
num_keys_per_buffer
,
uint
elem_size
)
uint
elem_size
,
double
key_compare_cost
)
{
ha_rows
num_buffers
=
num_rows
/
num_keys_per_buffer
;
ha_rows
last_n_elems
=
num_rows
%
num_keys_per_buffer
;
double
total_cost
,
rowid_compare_cost
=
ROWID_COMPARE_COST_THD
(
thd
)
;
double
total_cost
;
// Calculate CPU cost of sorting buffers.
total_cost
=
((
num_buffers
*
num_keys_per_buffer
*
log
(
1.0
+
num_keys_per_buffer
)
+
last_n_elems
*
log
(
1.0
+
last_n_elems
))
*
rowid
_compare_cost
);
last_n_elems
*
log
(
1.0
+
last_n_elems
))
*
key
_compare_cost
);
// Simulate behavior of merge_many_buff().
while
(
num_buffers
>=
MERGEBUFF2
)
...
...
@@ -69,16 +72,16 @@ double get_merge_many_buffs_cost_fast(THD *thd,
// Cost of merge sort 'num_merge_calls'.
total_cost
+=
num_merge_calls
*
get_merge_cost
(
rowid_compare_cost
,
num_keys_per_buffer
*
MERGEBUFF
,
MERGEBUFF
,
elem_size
);
get_merge_cost
(
num_keys_per_buffer
*
MERGEBUFF
,
MERGEBUFF
,
elem_size
,
key_compare_cost
);
// # of records in remaining buffers.
last_n_elems
+=
num_remaining_buffs
*
num_keys_per_buffer
;
// Cost of merge sort of remaining buffers.
total_cost
+=
get_merge_cost
(
rowid_compare_cost
,
last_n_elems
,
1
+
num_remaining_buffs
,
elem_size
);
get_merge_cost
(
last_n_elems
,
1
+
num_remaining_buffs
,
elem_size
,
key_compare_cost
);
num_buffers
=
num_merge_calls
;
num_keys_per_buffer
*=
MERGEBUFF
;
...
...
@@ -86,8 +89,8 @@ double get_merge_many_buffs_cost_fast(THD *thd,
// Simulate final merge_buff call.
last_n_elems
+=
num_keys_per_buffer
*
num_buffers
;
total_cost
+=
get_merge_cost
(
rowid_compare_cost
,
last_n_elems
,
1
+
num_buffers
,
elem_size
);
total_cost
+=
get_merge_cost
(
last_n_elems
,
1
+
num_buffers
,
elem_size
,
key_compare_cost
);
return
total_cost
;
}
...
...
sql/filesort_utils.h
View file @
06be2c64
...
...
@@ -20,12 +20,14 @@
#include "sql_array.h"
class
Sort_param
;
/*
/**
Calculate cost of merge sort
@param num_rows Total number of rows.
@param num_keys_per_buffer Number of keys per buffer.
@param elem_size Size of each element.
@param key_compare_cost Cost to compare two keys during QSort & merge
Calculates cost of merge sort by simulating call to merge_many_buff().
...
...
@@ -38,10 +40,10 @@ class Sort_param;
See also comments get_merge_many_buffs_cost().
*/
double
get_merge_many_buffs_cost_fast
(
THD
*
thd
,
ha_rows
num_rows
,
double
get_merge_many_buffs_cost_fast
(
ha_rows
num_rows
,
ha_rows
num_keys_per_buffer
,
uint
elem_size
);
uint
elem_size
,
double
key_compare_cost
);
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment