From e8497370b9557e77c0a791f89712a6ae8505f925 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 4 Jan 2012 17:51:53 -0800 Subject: The main patch for the MWL#248 back-ported from lp:~igorb-seattle/mysql-server/mysql-azalea-wl4777. --- sql/table.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sql/table.h') diff --git a/sql/table.h b/sql/table.h index 376aa9824dc..bdfcaf9b5db 100644 --- a/sql/table.h +++ b/sql/table.h @@ -747,6 +747,25 @@ struct st_table { */ query_id_t query_id; + /* Statistical data on a table */ + class Table_statistics + { + public: + my_bool cardinality_is_null; /* TRUE if the cardinality is unknown */ + ha_rows cardinality; /* Number of rows in the table */ + }; + + /* + This structure is used for statistical data on the table + that has been read from the statistical table table_stat + */ + Table_statistics read_stat; + /* + This structure is used for statistical data on the table that + is collected by the function collect_statistics_for_table + */ + Table_statistics write_stat; + /* For each key that has quick_keys.is_set(key) == TRUE: estimate of #records and max #key parts that range access would use. -- cgit v1.2.1 From 1c0a89afcc1581187e8ee84abbd445da2bfa45d9 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 11 Apr 2012 17:14:06 -0700 Subject: The pilot implementation of mwl#250: Use the statistics from persistent statistical tables instead of the statistics provided by engine. --- sql/table.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sql/table.h') diff --git a/sql/table.h b/sql/table.h index e7f41576215..0deb793aa57 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1025,6 +1025,9 @@ public: */ Table_statistics write_stat; + /* The estimate of the number of records in the table used by optimizer */ + ha_rows used_stat_records; + /* For each key that has quick_keys.is_set(key) == TRUE: estimate of #records and max #key parts that range access would use. @@ -1271,6 +1274,7 @@ public: bool update_const_key_parts(COND *conds); uint actual_n_key_parts(KEY *keyinfo); ulong actual_key_flags(KEY *keyinfo); + inline ha_rows stat_records() { return used_stat_records; } }; -- cgit v1.2.1 From 8c499274da21af6226785d51dd24968bf2b1befe Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 26 Jul 2012 17:50:08 -0700 Subject: Performed re-factoring and re-structuring of the code for mwl#248: - Moved the definitions of the classes to store data from persistent statistical tables into statistics.h, leaving in other internal data structures only references to the corresponding objects. - Defined class Column_statistics_collected derived from the class Column_statistics. This is a helper class to collect statistics on columns. - Moved references to read statistics to TABLE SHARE, leaving the the reference to the collected statistics in TABLE. - Added a new clone method for the class Field allowing to clone fields attached to table shares. It was was used to create fields for min/max values in the memory of the table share. A lso: - Added procedures to allocate memory for statistical data in the table share memory and in table memory. Also: - Added a test case demonstrating how ANALYZE could work in parallel to collect statistics on different indexes of the same table. - Added a test two demonstrate how two connections working simultaneously could allocate memory for statistical data in the table share memory. --- sql/table.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'sql/table.h') diff --git a/sql/table.h b/sql/table.h index b9a256b132b..e52a1858916 100644 --- a/sql/table.h +++ b/sql/table.h @@ -45,6 +45,7 @@ struct TABLE_LIST; class ACL_internal_schema_access; class ACL_internal_table_access; class Field; +class Table_statistics; /* Used to identify NESTED_JOIN structures within a join (applicable only to @@ -577,6 +578,15 @@ struct TABLE_SHARE KEY *key_info; /* data of keys in database */ uint *blob_field; /* Index to blobs in Field arrray*/ + bool stats_can_be_read; /* Memory for statistical data is allocated */ + bool stats_is_read; /* Statistical data for table has been read + from statistical tables */ + /* + This structure is used for statistical data on the table + that has been read from the statistical table table_stat + */ + Table_statistics *read_stats; + uchar *default_values; /* row with default values */ LEX_STRING comment; /* Comment about table */ CHARSET_INFO *table_charset; /* Default charset of string fields */ @@ -1007,24 +1017,11 @@ public: */ query_id_t query_id; - /* Statistical data on a table */ - class Table_statistics - { - public: - my_bool cardinality_is_null; /* TRUE if the cardinality is unknown */ - ha_rows cardinality; /* Number of rows in the table */ - }; - - /* - This structure is used for statistical data on the table - that has been read from the statistical table table_stat - */ - Table_statistics read_stat; /* This structure is used for statistical data on the table that is collected by the function collect_statistics_for_table */ - Table_statistics write_stat; + Table_statistics *collected_stats; /* The estimate of the number of records in the table used by optimizer */ ha_rows used_stat_records; -- cgit v1.2.1