From d7d80689b37f02129a32f5dc93729d539aca2a39 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 12 Jun 2020 13:24:23 +0300 Subject: MDEV-15101: Stop ANALYZE TABLE from flushing table definition cache Apply this patch from Percona Server (amended for 10.5): commit cd7201514fee78aaf7d3eb2b28d2573c76f53b84 Author: Laurynas Biveinis Date: Tue Nov 14 06:34:19 2017 +0200 Fix bug 1704195 / 87065 / TDB-83 (Stop ANALYZE TABLE from flushing table definition cache) Make ANALYZE TABLE stop flushing affected tables from the table definition cache, which has the effect of not blocking any subsequent new queries involving the table if there's a parallel long-running query: - new table flag HA_ONLINE_ANALYZE, return it for InnoDB and TokuDB tables; - in mysql_admin_table, if we are performing ANALYZE TABLE, and the table flag is set, do not remove the table from the table definition cache, do not invalidate query cache; - in partitioning handler, refresh the query optimizer statistics after ANALYZE if the underlying handler supports HA_ONLINE_ANALYZE; - new testcases main.percona_nonflushing_analyze_debug, parts.percona_nonflushing_abalyze_debug and a supporting debug sync point. For TokuDB, this change exposes bug TDB-83 (Index cardinality stats updated for handler::info(HA_STATUS_CONST), not often enough for tokudb_cardinality_scale_percent). TokuDB may return different rec_per_key values depending on dynamic variable tokudb_cardinality_scale_percent value. The server does not have a way of knowing that changing this variable invalidates the previous rec_per_key values in any opened table shares, and so does not call info(HA_STATUS_CONST) again. Fix by updating rec_per_key for both HA_STATUS_CONST and HA_STATUS_VARIABLE. This also forces a re-record of tokudb.bugs.db756_card_part_hash_1_pick, with the new output seeming to be more correct. --- sql/sql_admin.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'sql/sql_admin.cc') diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 03822acf564..71939936da0 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -1141,6 +1141,13 @@ send_result_message: } if (table->table && !table->view) { + /* + Don't skip flushing if we are collecting EITS statistics. + */ + const bool skip_flush= + (operator_func == &handler::ha_analyze) && + (table->table->file->ha_table_flags() & HA_ONLINE_ANALYZE) && + !collect_eis; if (table->table->s->tmp_table) { /* @@ -1150,7 +1157,7 @@ send_result_message: if (open_for_modify && !open_error) table->table->file->info(HA_STATUS_CONST); } - else if (open_for_modify || fatal_error) + else if ((!skip_flush && open_for_modify) || fatal_error) { table->table->s->tdc->flush_unused(true); /* -- cgit v1.2.1