summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc33
1 files changed, 32 insertions, 1 deletions
diff --git a/sql/table.cc b/sql/table.cc
index 9954d91cab4..22d4eed1b12 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -39,6 +39,7 @@
#include "my_bit.h"
#include "sql_select.h"
#include "sql_derived.h"
+#include "sql_statistics.h"
#include "mdl.h" // MDL_wait_for_graph_visitor
/* INFORMATION_SCHEMA name */
@@ -339,6 +340,8 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
share->free_tables.empty();
share->m_flush_tickets.empty();
+ init_sql_alloc(&share->stats_cb.mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
+
memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root));
mysql_mutex_init(key_TABLE_SHARE_LOCK_ha_data,
&share->LOCK_ha_data, MY_MUTEX_INIT_FAST);
@@ -419,6 +422,14 @@ void TABLE_SHARE::destroy()
uint idx;
KEY *info_it;
+ if (tmp_table == NO_TMP_TABLE)
+ mysql_mutex_lock(&LOCK_ha_data);
+ free_root(&stats_cb.mem_root, MYF(0));
+ stats_cb.stats_can_be_read= FALSE;
+ stats_cb.stats_is_read= FALSE;
+ if (tmp_table == NO_TMP_TABLE)
+ mysql_mutex_unlock(&LOCK_ha_data);
+
/* The mutex is initialized only for shares that are part of the TDC */
if (tmp_table == NO_TMP_TABLE)
mysql_mutex_destroy(&LOCK_ha_data);
@@ -544,6 +555,13 @@ inline bool is_system_table_name(const char *name, uint length)
my_tolower(ci, name[2]) == 'm' &&
my_tolower(ci, name[3]) == 'e') ||
+ /* one of mysql.*_stat tables */
+ (my_tolower(ci, name[length-5]) == 's' &&
+ my_tolower(ci, name[length-4]) == 't' &&
+ my_tolower(ci, name[length-3]) == 'a' &&
+ my_tolower(ci, name[length-2]) == 't' &&
+ my_tolower(ci, name[length-1]) == 's') ||
+
/* mysql.event table */
(my_tolower(ci, name[0]) == 'e' &&
my_tolower(ci, name[1]) == 'v' &&
@@ -753,7 +771,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
uchar forminfo[288];
uchar *record;
uchar *disk_buff, *strpos, *null_flags, *null_pos;
- ulong pos, record_offset;
+ ulong pos, record_offset;
ulong *rec_per_key= NULL;
ulong rec_buff_length;
handler *handler_file= 0;
@@ -6033,6 +6051,7 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
keyinfo->flags= HA_GENERATED_KEY;
keyinfo->ext_key_flags= keyinfo->flags;
+ keyinfo->is_statistics_from_stat_tables= FALSE;
if (unique)
keyinfo->flags|= HA_NOSAME;
sprintf(buf, "key%i", key);
@@ -6043,6 +6062,8 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
if (!keyinfo->rec_per_key)
return TRUE;
bzero(keyinfo->rec_per_key, sizeof(ulong)*key_parts);
+ keyinfo->read_stats= NULL;
+ keyinfo->collected_stats= NULL;
for (i= 0; i < key_parts; i++)
{
@@ -6786,6 +6807,7 @@ int TABLE_LIST::fetch_number_of_rows()
{
table->file->stats.records= ((select_union*)derived->result)->records;
set_if_bigger(table->file->stats.records, 2);
+ table->used_stat_records= table->file->stats.records;
}
else
error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
@@ -6881,3 +6903,12 @@ uint TABLE_SHARE::actual_n_key_parts(THD *thd)
ext_key_parts : key_parts;
}
+
+double KEY::actual_rec_per_key(uint i)
+{
+ if (rec_per_key == 0)
+ return 0;
+ return (is_statistics_from_stat_tables ?
+ read_stats->get_avg_frequency(i) : (double) rec_per_key[i]);
+}
+