summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2019-01-11 23:57:11 +0300
committerSergei Petrunia <psergey@askmonty.org>2019-01-11 23:57:11 +0300
commitb4ea18300a08bd6f8e35d2ffdaec41b58ae8fe3b (patch)
tree5fd37a25e981edc8b7fb94a1cf5a59b242cbf336 /sql
parent82490a97dbbe1dfdf88ed6b9fee8974cf58c63e3 (diff)
downloadmariadb-git-bb-10.3-mdev15101.tar.gz
Apply this patch from Percona Server:bb-10.3-mdev15101
commit cd7201514fee78aaf7d3eb2b28d2573c76f53b84 Author: Laurynas Biveinis <laurynas.biveinis@gmail.com> 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.
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_partition.cc12
-rw-r--r--sql/handler.cc3
-rw-r--r--sql/handler.h6
-rw-r--r--sql/sql_admin.cc5
4 files changed, 24 insertions, 2 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 1349571a3f8..361dacb51f4 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -1162,7 +1162,17 @@ int ha_partition::analyze(THD *thd, HA_CHECK_OPT *check_opt)
{
DBUG_ENTER("ha_partition::analyze");
- DBUG_RETURN(handle_opt_partitions(thd, check_opt, ANALYZE_PARTS));
+ int result= handle_opt_partitions(thd, check_opt, ANALYZE_PARTS);
+
+ if ((result == 0) && m_file[0]
+ && (m_file[0]->ha_table_flags() & HA_ONLINE_ANALYZE))
+ {
+ /* If this is ANALYZE TABLE that will not force table definition cache
+ eviction, update statistics for the partition handler. */
+ this->info(HA_STATUS_CONST | HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
+ }
+
+ DBUG_RETURN(result);
}
diff --git a/sql/handler.cc b/sql/handler.cc
index 897d468f2ba..08735f284d8 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -2880,6 +2880,9 @@ int handler::ha_index_next(uchar * buf)
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
}
table->status=result ? STATUS_NOT_FOUND: 0;
+
+ DEBUG_SYNC(ha_thd(), "handler_ha_index_next_end");
+
DBUG_RETURN(result);
}
diff --git a/sql/handler.h b/sql/handler.h
index a4e81ea0365..2e469e23e04 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -304,6 +304,12 @@ enum enum_alter_inplace_result {
/* Engine wants primary keys for everything except sequences */
#define HA_WANTS_PRIMARY_KEY (1ULL << 55)
+/*
+ There is no need to evict the table from the table definition cache having
+ run ANALYZE TABLE on it
+ */
+#define HA_ONLINE_ANALYZE (1ULL << 56)
+
/* bits in index_flags(index_number) for what you can do with index */
#define HA_READ_NEXT 1 /* TODO really use this flag */
#define HA_READ_PREV 2 /* supports ::index_prev */
diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc
index c17567e6a89..221220ba3d4 100644
--- a/sql/sql_admin.cc
+++ b/sql/sql_admin.cc
@@ -1143,6 +1143,9 @@ send_result_message:
}
if (table->table && !table->view)
{
+ const bool skip_flush=
+ (operator_func == &handler::ha_analyze)
+ && (table->table->file->ha_table_flags() & HA_ONLINE_ANALYZE);
if (table->table->s->tmp_table)
{
/*
@@ -1152,7 +1155,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)
{
tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
table->db.str, table->table_name.str, FALSE);