Skip to content

Commit 31463f1

Browse files
committed
MDEV-33502: part#4: Dont make redundant extra(HA_EXTRA_[NO]_KEYREAD) calls
In most cases, ha_partition forwards calls to extra() to all locked_partitions. It doesn't make sense to forward some calls for partitions that were pruned away. This patch introduces ha_partition::loop_read_partitions and makes these calls use it: - ha_partition::extra_opt(HA_EXTRA_KEYREAD) - ha_partition::extra(HA_EXTRA_KEYREAD) - ha_partition::extra(HA_EXTRA_NO_KEYREAD) Reviewed-by: Monty
1 parent 0772ac1 commit 31463f1

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

sql/ha_partition.cc

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9314,8 +9314,9 @@ int ha_partition::extra(enum ha_extra_function operation)
93149314
switch (operation) {
93159315
/* Category 1), used by most handlers */
93169316
case HA_EXTRA_NO_KEYREAD:
9317-
DBUG_RETURN(loop_partitions(end_keyread_cb, NULL));
9317+
DBUG_RETURN(loop_read_partitions(end_keyread_cb, NULL));
93189318
case HA_EXTRA_KEYREAD:
9319+
DBUG_RETURN(loop_read_partitions(extra_cb, &operation));
93199320
case HA_EXTRA_FLUSH:
93209321
case HA_EXTRA_PREPARE_FOR_FORCED_CLOSE:
93219322
DBUG_RETURN(loop_partitions(extra_cb, &operation));
@@ -9537,7 +9538,7 @@ int ha_partition::extra_opt(enum ha_extra_function operation, ulong arg)
95379538
switch (operation)
95389539
{
95399540
case HA_EXTRA_KEYREAD:
9540-
DBUG_RETURN(loop_partitions(start_keyread_cb, &arg));
9541+
DBUG_RETURN(loop_read_partitions(start_keyread_cb, &arg));
95419542
case HA_EXTRA_CACHE:
95429543
prepare_extra_cache(arg);
95439544
DBUG_RETURN(0);
@@ -9625,14 +9626,53 @@ int ha_partition::loop_extra_alter(enum ha_extra_function operation)
96259626
*/
96269627

96279628
int ha_partition::loop_partitions(handler_callback callback, void *param)
9629+
{
9630+
int result= loop_partitions_over_map(&m_part_info->lock_partitions,
9631+
callback, param);
9632+
/* Add all used partitions to be called in reset(). */
9633+
bitmap_union(&m_partitions_to_reset, &m_part_info->lock_partitions);
9634+
return result;
9635+
}
9636+
9637+
9638+
/*
9639+
Call callback(part, param) on read_partitions (the ones used by the query)
9640+
*/
9641+
9642+
int ha_partition::loop_read_partitions(handler_callback callback, void *param)
9643+
{
9644+
/*
9645+
There is no need to record partitions on m_partitions_to_reset as
9646+
read_partitions were opened, etc - they will be reset anyway.
9647+
*/
9648+
return loop_partitions_over_map(&m_part_info->read_partitions, callback,
9649+
param);
9650+
}
9651+
9652+
9653+
/**
9654+
Call callback(part, param) on specified set of partitions
9655+
9656+
@part_map The set of partitions to call callback for
9657+
@param callback a callback to call for each partition
9658+
@param param a void*-parameter passed to callback
9659+
9660+
@return Operation status
9661+
@retval >0 Error code
9662+
@retval 0 Success
9663+
*/
9664+
9665+
int ha_partition::loop_partitions_over_map(const MY_BITMAP *part_map,
9666+
handler_callback callback,
9667+
void *param)
96289668
{
96299669
int result= 0, tmp;
96309670
uint i;
9631-
DBUG_ENTER("ha_partition::loop_partitions");
9671+
DBUG_ENTER("ha_partition::loop_partitions_over_map");
96329672

9633-
for (i= bitmap_get_first_set(&m_part_info->lock_partitions);
9673+
for (i= bitmap_get_first_set(part_map);
96349674
i < m_tot_parts;
9635-
i= bitmap_get_next_set(&m_part_info->lock_partitions, i))
9675+
i= bitmap_get_next_set(part_map, i))
96369676
{
96379677
/*
96389678
This can be called after an error in ha_open.
@@ -9642,8 +9682,6 @@ int ha_partition::loop_partitions(handler_callback callback, void *param)
96429682
(tmp= callback(m_file[i], param)))
96439683
result= tmp;
96449684
}
9645-
/* Add all used partitions to be called in reset(). */
9646-
bitmap_union(&m_partitions_to_reset, &m_part_info->lock_partitions);
96479685
DBUG_RETURN(result);
96489686
}
96499687

sql/ha_partition.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,10 @@ class ha_partition final :public handler
989989
handler *file, uint *n);
990990
static const uint NO_CURRENT_PART_ID= NOT_A_PARTITION_ID;
991991
int loop_partitions(handler_callback callback, void *param);
992+
int loop_partitions_over_map(const MY_BITMAP *map,
993+
handler_callback callback,
994+
void *param);
995+
int loop_read_partitions(handler_callback callback, void *param);
992996
int loop_extra_alter(enum ha_extra_function operations);
993997
void late_extra_cache(uint partition_id);
994998
void late_extra_no_cache(uint partition_id);

0 commit comments

Comments
 (0)