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
d1e09972
Commit
d1e09972
authored
Nov 07, 2022
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup: cache the result of Rows_log_event::find_key()
parent
6ecc90ae
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
60 deletions
+62
-60
sql/log_event_server.cc
sql/log_event_server.cc
+50
-46
sql/rpl_utility.h
sql/rpl_utility.h
+12
-14
No files found.
sql/log_event_server.cc
View file @
d1e09972
...
@@ -7105,12 +7105,17 @@ static bool record_compare(TABLE *table, bool vers_from_plain= false)
...
@@ -7105,12 +7105,17 @@ static bool record_compare(TABLE *table, bool vers_from_plain= false)
*/
*/
int
Rows_log_event
::
find_key
()
int
Rows_log_event
::
find_key
()
{
{
uint
i
,
best_key_nr
,
last_part
;
DBUG_ASSERT
(
m_table
);
KEY
*
key
,
*
UNINIT_VAR
(
best_key
);
RPL_TABLE_LIST
*
tl
=
(
RPL_TABLE_LIST
*
)
m_table
->
pos_in_table_list
;
uint
i
,
best_key_nr
;
KEY
*
key
;
ulong
UNINIT_VAR
(
best_rec_per_key
),
tmp
;
ulong
UNINIT_VAR
(
best_rec_per_key
),
tmp
;
DBUG_ENTER
(
"Rows_log_event::find_key"
);
DBUG_ENTER
(
"Rows_log_event::find_key"
);
DBUG_ASSERT
(
m_table
);
if
((
best_key_nr
=
tl
->
cached_key_nr
)
!=
~
0U
)
DBUG_ASSERT
(
best_key_nr
<=
MAX_KEY
);
// use the cached value
else
{
best_key_nr
=
MAX_KEY
;
best_key_nr
=
MAX_KEY
;
/*
/*
...
@@ -7130,14 +7135,13 @@ int Rows_log_event::find_key()
...
@@ -7130,14 +7135,13 @@ int Rows_log_event::find_key()
if
((
key
->
flags
&
(
HA_NOSAME
|
HA_NULL_PART_KEY
))
==
HA_NOSAME
)
if
((
key
->
flags
&
(
HA_NOSAME
|
HA_NULL_PART_KEY
))
==
HA_NOSAME
)
{
{
best_key_nr
=
i
;
best_key_nr
=
i
;
best_key
=
key
;
break
;
break
;
}
}
/*
/*
We can only use a non-unique key if it allows range scans (ie. skip
We can only use a non-unique key if it allows range scans (ie. skip
FULLTEXT indexes and such).
FULLTEXT indexes and such).
*/
*/
last_part
=
key
->
user_defined_key_parts
-
1
;
uint
last_part
=
key
->
user_defined_key_parts
-
1
;
DBUG_PRINT
(
"info"
,
(
"Index %s rec_per_key[%u]= %lu"
,
DBUG_PRINT
(
"info"
,
(
"Index %s rec_per_key[%u]= %lu"
,
key
->
name
.
str
,
last_part
,
key
->
rec_per_key
[
last_part
]));
key
->
name
.
str
,
last_part
,
key
->
rec_per_key
[
last_part
]));
if
(
!
(
m_table
->
file
->
index_flags
(
i
,
last_part
,
1
)
&
HA_READ_NEXT
))
if
(
!
(
m_table
->
file
->
index_flags
(
i
,
last_part
,
1
)
&
HA_READ_NEXT
))
...
@@ -7147,25 +7151,25 @@ int Rows_log_event::find_key()
...
@@ -7147,25 +7151,25 @@ int Rows_log_event::find_key()
if
(
best_key_nr
==
MAX_KEY
||
(
tmp
>
0
&&
tmp
<
best_rec_per_key
))
if
(
best_key_nr
==
MAX_KEY
||
(
tmp
>
0
&&
tmp
<
best_rec_per_key
))
{
{
best_key_nr
=
i
;
best_key_nr
=
i
;
best_key
=
key
;
best_rec_per_key
=
tmp
;
best_rec_per_key
=
tmp
;
}
}
}
}
tl
->
cached_key_nr
=
best_key_nr
;
}
m_key_nr
=
best_key_nr
;
if
(
best_key_nr
==
MAX_KEY
)
if
(
best_key_nr
==
MAX_KEY
)
{
m_key_info
=
NULL
;
m_key_info
=
NULL
;
DBUG_RETURN
(
0
);
else
}
{
m_key_info
=
m_table
->
key_info
+
best_key_nr
;
// Allocate buffer for key searches
// Allocate buffer for key searches
m_key
=
(
uchar
*
)
my_malloc
(
PSI_INSTRUMENT_ME
,
best_key
->
key_length
,
MYF
(
MY_WME
));
m_key
=
(
uchar
*
)
my_malloc
(
PSI_INSTRUMENT_ME
,
m_key_info
->
key_length
,
MYF
(
MY_WME
));
if
(
m_key
==
NULL
)
if
(
m_key
==
NULL
)
DBUG_RETURN
(
HA_ERR_OUT_OF_MEM
);
DBUG_RETURN
(
HA_ERR_OUT_OF_MEM
);
m_key_info
=
best_key
;
}
m_key_nr
=
best_key_nr
;
DBUG_RETURN
(
0
);
;
DBUG_RETURN
(
0
);
}
}
...
...
sql/rpl_utility.h
View file @
d1e09972
...
@@ -249,24 +249,24 @@ class table_def
...
@@ -249,24 +249,24 @@ class table_def
Extend the normal table list with a few new fields needed by the
Extend the normal table list with a few new fields needed by the
slave thread, but nowhere else.
slave thread, but nowhere else.
*/
*/
struct
RPL_TABLE_LIST
struct
RPL_TABLE_LIST
:
public
TABLE_LIST
:
public
TABLE_LIST
{
{
bool
m_tabledef_valid
;
bool
master_had_triggers
;
table_def
m_tabledef
;
table_def
m_tabledef
;
TABLE
*
m_conv_table
;
TABLE
*
m_conv_table
;
const
Copy_field
*
m_online_alter_copy_fields
;
const
Copy_field
*
m_online_alter_copy_fields
;
const
Copy_field
*
m_online_alter_copy_fields_end
;
const
Copy_field
*
m_online_alter_copy_fields_end
;
uint
cached_key_nr
;
// [0..MAX_KEY] if set, ~0U if unset
bool
m_tabledef_valid
;
bool
master_had_triggers
;
RPL_TABLE_LIST
(
const
LEX_CSTRING
*
db_arg
,
const
LEX_CSTRING
*
table_name_arg
,
RPL_TABLE_LIST
(
const
LEX_CSTRING
*
db_arg
,
const
LEX_CSTRING
*
table_name_arg
,
thr_lock_type
thr_lock_type
,
thr_lock_type
thr_lock_type
,
table_def
&&
tabledef
,
bool
master_had_trigers
)
table_def
&&
tabledef
,
bool
master_had_trigers
)
:
TABLE_LIST
(
db_arg
,
table_name_arg
,
NULL
,
thr_lock_type
),
:
TABLE_LIST
(
db_arg
,
table_name_arg
,
NULL
,
thr_lock_type
),
m_tabledef_valid
(
true
),
master_had_triggers
(
master_had_trigers
),
m_tabledef
(
std
::
move
(
tabledef
)),
m_conv_table
(
NULL
),
m_tabledef
(
std
::
move
(
tabledef
)),
m_conv_table
(
NULL
),
m_online_alter_copy_fields
(
NULL
),
m_online_alter_copy_fields
(
NULL
),
m_online_alter_copy_fields_end
(
NULL
),
m_online_alter_copy_fields_end
(
NULL
)
cached_key_nr
(
~
0U
),
m_tabledef_valid
(
true
),
master_had_triggers
(
master_had_trigers
)
{}
{}
RPL_TABLE_LIST
(
TABLE
*
table
,
thr_lock_type
lock_type
,
TABLE
*
conv_table
,
RPL_TABLE_LIST
(
TABLE
*
table
,
thr_lock_type
lock_type
,
TABLE
*
conv_table
,
...
@@ -274,12 +274,10 @@ struct RPL_TABLE_LIST
...
@@ -274,12 +274,10 @@ struct RPL_TABLE_LIST
const
Copy_field
online_alter_copy_fields
[],
const
Copy_field
online_alter_copy_fields
[],
const
Copy_field
*
online_alter_copy_fields_end
)
const
Copy_field
*
online_alter_copy_fields_end
)
:
TABLE_LIST
(
table
,
lock_type
),
:
TABLE_LIST
(
table
,
lock_type
),
m_tabledef_valid
(
true
),
m_tabledef
(
std
::
move
(
tabledef
)),
m_conv_table
(
conv_table
),
master_had_triggers
(
false
),
m_tabledef
(
std
::
move
(
tabledef
)),
m_conv_table
(
conv_table
),
m_online_alter_copy_fields
(
online_alter_copy_fields
),
m_online_alter_copy_fields
(
online_alter_copy_fields
),
m_online_alter_copy_fields_end
(
online_alter_copy_fields_end
)
m_online_alter_copy_fields_end
(
online_alter_copy_fields_end
),
cached_key_nr
(
~
0U
),
m_tabledef_valid
(
true
),
master_had_triggers
(
false
)
{}
{}
};
};
...
...
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