Commit 7c903453 authored by Monty's avatar Monty

MDEV-34043 Drastically slower query performance between CentOS (2sec) and Rocky (48sec)

One cause of the slowdown is because the ftruncate call can be much
slower on some systems.  ftruncate() is called by Aria for internal
temporary tables, tables created by the optimzer, when the upper level
asks Aria to delete the previous result set. This is needed when some
content from previous tables changes.

I have now changed Aria so that for internal temporary tables we don't
call ftruncate anymore.

I also had to update the Aria repair code to use the logical datafile
size and not the on-disk datafile size, which may contain data from a
previous result set.  The repair code is called to create indexes for
the internal temporary table after it is filled.
parent 16394f1a
......@@ -2409,7 +2409,17 @@ static int initialize_variables_for_repair(HA_CHECK *param,
return 1;
/* calculate max_records */
sort_info->filelength= my_seek(info->dfile.file, 0L, MY_SEEK_END, MYF(0));
if (!share->internal_table)
{
/* Get real file size */
sort_info->filelength= my_seek(info->dfile.file, 0L, MY_SEEK_END, MYF(0));
}
else
{
/* For internal temporary files we are using the logical file length */
sort_info->filelength= share->state.state.data_file_length;
}
param->max_progress= sort_info->filelength;
if ((param->testflag & T_CREATE_MISSING_KEYS) ||
sort_info->org_data_file_type == COMPRESSED_RECORD)
......
......@@ -103,9 +103,16 @@ int maria_delete_all_rows(MARIA_HA *info)
#endif
if (_ma_flush_table_files(info, MARIA_FLUSH_DATA|MARIA_FLUSH_INDEX,
FLUSH_IGNORE_CHANGED, FLUSH_IGNORE_CHANGED) ||
mysql_file_chsize(info->dfile.file, 0, 0, MYF(MY_WME)) ||
mysql_file_chsize(share->kfile.file, share->base.keystart, 0, MYF(MY_WME)))
FLUSH_IGNORE_CHANGED, FLUSH_IGNORE_CHANGED))
goto err;
/*
Avoid truncate of internal temporary tables as this can have a big
performance overhead when using single_derived tables in MariaDB.
*/
if (!share->internal_table &&
(mysql_file_chsize(info->dfile.file, 0, 0, MYF(MY_WME)) ||
mysql_file_chsize(share->kfile.file, share->base.keystart, 0,
MYF(MY_WME))))
goto err;
if (_ma_initialize_data_file(share, info->dfile.file))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment