Skip to content

Commit

Permalink
Have ha_partition ignore HA_EXTRA..CHILDREN extra() calls if no myisamrg
Browse files Browse the repository at this point in the history
MDEV-33502 Slowdown when running nested statement with many partitions

Optimization for tables with a lot of partitions
  • Loading branch information
montywi committed Feb 27, 2024
1 parent 71834cc commit a8f6b86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ void ha_partition::init_handler_variables()
m_start_key.length= 0;
m_myisam= FALSE;
m_innodb= FALSE;
m_myisammrg= FALSE;
m_extra_cache= FALSE;
m_extra_cache_size= 0;
m_extra_prepare_for_update= FALSE;
Expand Down Expand Up @@ -3030,6 +3031,10 @@ bool ha_partition::create_handlers(MEM_ROOT *mem_root)
DBUG_PRINT("info", ("InnoDB"));
m_innodb= TRUE;
}
else if (ha_legacy_type(hton0) == DB_TYPE_MRG_MYISAM)
{
m_myisammrg= TRUE;
}
DBUG_RETURN(FALSE);
}

Expand Down Expand Up @@ -9419,9 +9424,14 @@ int ha_partition::extra(enum ha_extra_function operation)
}
/* Category 9) Operations only used by MERGE */
case HA_EXTRA_ADD_CHILDREN_LIST:
if (!m_myisammrg)
DBUG_RETURN(0);
DBUG_RETURN(loop_partitions(extra_cb, &operation));
case HA_EXTRA_ATTACH_CHILDREN:
{
if (!m_myisammrg)
DBUG_RETURN(0);

int result;
uint num_locks;
handler **file;
Expand All @@ -9440,8 +9450,9 @@ int ha_partition::extra(enum ha_extra_function operation)
break;
}
case HA_EXTRA_IS_ATTACHED_CHILDREN:
DBUG_RETURN(loop_partitions(extra_cb, &operation));
case HA_EXTRA_DETACH_CHILDREN:
if (!m_myisammrg)
DBUG_RETURN(0);
DBUG_RETURN(loop_partitions(extra_cb, &operation));
case HA_EXTRA_MARK_AS_LOG_TABLE:
/*
Expand Down
1 change: 1 addition & 0 deletions sql/ha_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ class ha_partition final :public handler
*/
bool m_innodb; // Are all underlying handlers
// InnoDB
bool m_myisammrg; // Are any of the handlers of type MERGE
/*
When calling extra(HA_EXTRA_CACHE) we do not pass this to the underlying
handlers immediately. Instead we cache it and call the underlying
Expand Down

0 comments on commit a8f6b86

Please sign in to comment.