diff options
author | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2018-04-10 17:43:18 +0300 |
---|---|---|
committer | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2018-04-10 17:43:18 +0300 |
commit | 45e6d0aebf023acb50671f82b87e6de5d1e78f5e (patch) | |
tree | c6079a18e158706a0a877d1b522ceb851d6055b5 /sql/sql_statistics.cc | |
parent | f5cb66fb97101bc0f17ff879025fd7146c032cbc (diff) | |
parent | 2e91eb7547dfc7c9a999568bd8245832bbcfefaa (diff) | |
download | mariadb-git-45e6d0aebf023acb50671f82b87e6de5d1e78f5e.tar.gz |
Merge branch '10.1' into 10.2
Diffstat (limited to 'sql/sql_statistics.cc')
-rw-r--r-- | sql/sql_statistics.cc | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 5a9bf08d99b..5badcad3492 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -3083,18 +3083,19 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables) return FALSE; /* - Do not read statistics for any query over non-user tables. - If the query references some statistical tables, but not all - of them, reading the statistics may lead to a deadlock - */ + Do not read statistics for any query that explicity involves + statistical tables, failure to to do so we may end up + in a deadlock. + */ + for (TABLE_LIST *tl= tables; tl; tl= tl->next_global) { if (!tl->is_view_or_derived() && tl->table) { TABLE_SHARE *table_share= tl->table->s; if (table_share && - (table_share->table_category != TABLE_CATEGORY_USER || - table_share->tmp_table != NO_TMP_TABLE)) + table_share->table_category != TABLE_CATEGORY_USER + && is_stat_table(tl->db, tl->alias)) return FALSE; } } @@ -3770,6 +3771,15 @@ double get_column_range_cardinality(Field *field, if (!col_stats) return tab_records; + /* + Use statistics for a table only when we have actually read + the statistics from the stat tables. For example due to + chances of getting a deadlock we disable reading statistics for + a table. + */ + + if (!table->stats_is_read) + return tab_records; double col_nulls= tab_records * col_stats->get_nulls_ratio(); @@ -3993,4 +4003,3 @@ bool is_stat_table(const char *db, const char *table) } return false; } - |