mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-13049 Querying INFORMATION_SCHEMA becomes slow in MariaDB 10.1
Optimizations: * avoid faster ext_table_discovery_simple() *only* when there are engines with discover_table_names() method *and* they look at file names. P_S implements discover_table_names(), but it's not a reason to use slower extension_based_table_discovery(). * don't pre-sort table names if ORDER BY or GROUP BY was specified * starting from 10.3 only sort table names for SHOW commands
This commit is contained in:
@ -405,7 +405,7 @@ static int ha_finish_errors(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static volatile int32 need_full_discover_for_existence= 0;
|
static volatile int32 need_full_discover_for_existence= 0;
|
||||||
static volatile int32 engines_with_discover_table_names= 0;
|
static volatile int32 engines_with_discover_file_names= 0;
|
||||||
static volatile int32 engines_with_discover= 0;
|
static volatile int32 engines_with_discover= 0;
|
||||||
|
|
||||||
static int full_discover_for_existence(handlerton *, const char *, const char *)
|
static int full_discover_for_existence(handlerton *, const char *, const char *)
|
||||||
@ -430,8 +430,8 @@ static void update_discovery_counters(handlerton *hton, int val)
|
|||||||
if (hton->discover_table_existence == full_discover_for_existence)
|
if (hton->discover_table_existence == full_discover_for_existence)
|
||||||
my_atomic_add32(&need_full_discover_for_existence, val);
|
my_atomic_add32(&need_full_discover_for_existence, val);
|
||||||
|
|
||||||
if (hton->discover_table_names)
|
if (hton->discover_table_names && hton->tablefile_extensions[0])
|
||||||
my_atomic_add32(&engines_with_discover_table_names, val);
|
my_atomic_add32(&engines_with_discover_file_names, val);
|
||||||
|
|
||||||
if (hton->discover_table)
|
if (hton->discover_table)
|
||||||
my_atomic_add32(&engines_with_discover, val);
|
my_atomic_add32(&engines_with_discover, val);
|
||||||
@ -5189,6 +5189,7 @@ void Discovered_table_list::remove_duplicates()
|
|||||||
{
|
{
|
||||||
LEX_STRING **src= tables->front();
|
LEX_STRING **src= tables->front();
|
||||||
LEX_STRING **dst= src;
|
LEX_STRING **dst= src;
|
||||||
|
sort();
|
||||||
while (++dst <= tables->back())
|
while (++dst <= tables->back())
|
||||||
{
|
{
|
||||||
LEX_STRING *s= *src, *d= *dst;
|
LEX_STRING *s= *src, *d= *dst;
|
||||||
@ -5256,10 +5257,12 @@ int ha_discover_table_names(THD *thd, LEX_STRING *db, MY_DIR *dirp,
|
|||||||
int error;
|
int error;
|
||||||
DBUG_ENTER("ha_discover_table_names");
|
DBUG_ENTER("ha_discover_table_names");
|
||||||
|
|
||||||
if (engines_with_discover_table_names == 0 && !reusable)
|
if (engines_with_discover_file_names == 0 && !reusable)
|
||||||
{
|
{
|
||||||
error= ext_table_discovery_simple(dirp, result);
|
st_discover_names_args args= {db, NULL, result, 0};
|
||||||
result->sort();
|
error= ext_table_discovery_simple(dirp, result) ||
|
||||||
|
plugin_foreach(thd, discover_names,
|
||||||
|
MYSQL_STORAGE_ENGINE_PLUGIN, &args);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -5272,8 +5275,6 @@ int ha_discover_table_names(THD *thd, LEX_STRING *db, MY_DIR *dirp,
|
|||||||
error= extension_based_table_discovery(dirp, reg_ext, result) ||
|
error= extension_based_table_discovery(dirp, reg_ext, result) ||
|
||||||
plugin_foreach(thd, discover_names,
|
plugin_foreach(thd, discover_names,
|
||||||
MYSQL_STORAGE_ENGINE_PLUGIN, &args);
|
MYSQL_STORAGE_ENGINE_PLUGIN, &args);
|
||||||
result->sort();
|
|
||||||
|
|
||||||
if (args.possible_duplicates > 0)
|
if (args.possible_duplicates > 0)
|
||||||
result->remove_duplicates();
|
result->remove_duplicates();
|
||||||
}
|
}
|
||||||
|
@ -979,13 +979,20 @@ find_files(THD *thd, Dynamic_array<LEX_STRING*> *files, LEX_STRING *db,
|
|||||||
if (tl.add_file(file->name))
|
if (tl.add_file(file->name))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
tl.sort();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ha_discover_table_names(thd, db, dirp, &tl, false))
|
if (ha_discover_table_names(thd, db, dirp, &tl, false))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
#if MYSQL_VERSION_ID < 100300
|
||||||
|
/* incomplete optimization, but a less drastic change in GA version */
|
||||||
|
if (!thd->lex->select_lex.order_list.elements &&
|
||||||
|
!thd->lex->select_lex.group_list.elements)
|
||||||
|
#else
|
||||||
|
if (is_show_command(thd))
|
||||||
|
#endif
|
||||||
|
tl.sort();
|
||||||
|
|
||||||
DBUG_PRINT("info",("found: %zu files", files->elements()));
|
DBUG_PRINT("info",("found: %zu files", files->elements()));
|
||||||
my_dirend(dirp);
|
my_dirend(dirp);
|
||||||
|
Reference in New Issue
Block a user