summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2019-04-22 17:10:42 -0700
committerIgor Babaev <igor@askmonty.org>2019-04-22 17:11:07 -0700
commit279a907fd0dea30be6d11fc4a5d63b1b98d0b329 (patch)
tree23cf9722a9aaf85b2dee4fbb9419c93cc7d3f89e /sql
parenta4f7d859322ab771289abf13f50752266af43187 (diff)
downloadmariadb-git-279a907fd0dea30be6d11fc4a5d63b1b98d0b329.tar.gz
MDEV-17605 Statistics for InnoDB table is wrong if persistent statistics is used
The command SHOW INDEXES ignored setting of the system variable use_stat_tables to the value of 'preferably' and and showed statistical data received from the engine. Similarly queries over the table STATISTICS from INFORMATION_SCHEMA ignored this setting. It happened because the function fill_schema_table_by_open() did not read any data from statistical tables.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_class.h3
-rw-r--r--sql/sql_show.cc5
-rw-r--r--sql/sql_statistics.cc5
3 files changed, 12 insertions, 1 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 6640e02147a..2517f5cc06f 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -2199,6 +2199,9 @@ public:
*/
bool create_tmp_table_for_derived;
+ /* The flag to force reading statistics from EITS tables */
+ bool force_read_stats;
+
bool save_prep_leaf_list;
/* container for handler's private per-connection data */
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 73f0f564c4c..46914ea14c4 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -4273,6 +4273,7 @@ fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
'only_view_structure()'.
*/
lex->sql_command= SQLCOM_SHOW_FIELDS;
+ thd->force_read_stats= get_schema_table_idx(schema_table) == SCH_STATISTICS;
result= (open_temporary_tables(thd, table_list) ||
open_normal_and_derived_tables(thd, table_list,
(MYSQL_OPEN_IGNORE_FLUSH |
@@ -4280,6 +4281,10 @@ fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
(can_deadlock ?
MYSQL_OPEN_FAIL_ON_MDL_CONFLICT : 0)),
DT_PREPARE | DT_CREATE));
+
+ (void) read_statistics_for_tables_if_needed(thd, table_list);
+ thd->force_read_stats= false;
+
/*
Restore old value of sql_command back as it is being looked at in
process_table() function.
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index d3a2094e272..b435971a4d6 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -2177,7 +2177,10 @@ inline bool statistics_for_command_is_needed(THD *thd)
{
if (thd->bootstrap || thd->variables.use_stat_tables == NEVER)
return FALSE;
-
+
+ if (thd->force_read_stats)
+ return TRUE;
+
switch(thd->lex->sql_command) {
case SQLCOM_SELECT:
case SQLCOM_INSERT: