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. --- mysql-test/include/system_db_struct.inc | 3 + mysql-test/include/world_schema_utf8.inc | 25 ++ mysql-test/r/1st.result | 3 + mysql-test/r/connect.result | 9 + mysql-test/r/information_schema.result | 6 + mysql-test/r/information_schema_all_engines.result | 2 +- mysql-test/r/log_tables_upgrade.result | 3 + mysql-test/r/mysqlcheck.result | 6 + mysql-test/r/statistics.result | 455 +++++++++++++++++++++ mysql-test/r/system_mysql_db.result | 34 ++ mysql-test/suite/pbxt/r/connect.result | 9 + mysql-test/t/statistics.test | 290 +++++++++++++ mysql-test/t/system_mysql_db_fix30020.test | 3 +- mysql-test/t/system_mysql_db_fix40123.test | 7 +- mysql-test/t/system_mysql_db_fix50030.test | 8 +- mysql-test/t/system_mysql_db_fix50117.test | 8 +- 16 files changed, 866 insertions(+), 5 deletions(-) create mode 100644 mysql-test/include/world_schema_utf8.inc create mode 100644 mysql-test/r/statistics.result create mode 100644 mysql-test/t/statistics.test (limited to 'mysql-test') diff --git a/mysql-test/include/system_db_struct.inc b/mysql-test/include/system_db_struct.inc index 123c82484b9..3d97ff67043 100644 --- a/mysql-test/include/system_db_struct.inc +++ b/mysql-test/include/system_db_struct.inc @@ -16,3 +16,6 @@ show create table proc; show create table event; show create table general_log; show create table slow_log; +show create table table_stat; +show create table column_stat; +show create table index_stat; diff --git a/mysql-test/include/world_schema_utf8.inc b/mysql-test/include/world_schema_utf8.inc new file mode 100644 index 00000000000..2a09c5d32d5 --- /dev/null +++ b/mysql-test/include/world_schema_utf8.inc @@ -0,0 +1,25 @@ +CREATE TABLE Country ( + Code char(3) NOT NULL default '', + Name char(52) NOT NULL default '', + SurfaceArea float(10,2) NOT NULL default '0.00', + Population int(11) NOT NULL default '0', + Capital int(11) default NULL, + PRIMARY KEY (Code), + UNIQUE INDEX (Name) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE City ( + ID int(11) NOT NULL auto_increment, + Name char(35) NOT NULL default '', + Country char(3) NOT NULL default '', + Population int(11) NOT NULL default '0', + PRIMARY KEY (ID), + INDEX (Population), + INDEX (Country) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE CountryLanguage ( + Country char(3) NOT NULL default '', + Language char(30) NOT NULL default '', + Percentage float(3,1) NOT NULL default '0.0', + PRIMARY KEY (Country, Language), + INDEX (Percentage) +) CHARACTER SET utf8 COLLATE utf8_bin; diff --git a/mysql-test/r/1st.result b/mysql-test/r/1st.result index 4a82f8c66e9..7675c9ec35c 100644 --- a/mysql-test/r/1st.result +++ b/mysql-test/r/1st.result @@ -6,6 +6,7 @@ mysql test show tables in mysql; Tables_in_mysql +column_stat columns_priv db event @@ -16,12 +17,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result index 7a972f4814a..544e2d29846 100644 --- a/mysql-test/r/connect.result +++ b/mysql-test/r/connect.result @@ -1,6 +1,7 @@ drop table if exists t1,t2; show tables; Tables_in_mysql +column_stat columns_priv db event @@ -11,12 +12,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second @@ -34,6 +37,7 @@ grant ALL on *.* to test@localhost identified by "gambling"; grant ALL on *.* to test@127.0.0.1 identified by "gambling"; show tables; Tables_in_mysql +column_stat columns_priv db event @@ -44,12 +48,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second @@ -75,6 +81,7 @@ ERROR HY000: Password hash should be a 41-digit hexadecimal number set password=old_password('gambling3'); show tables; Tables_in_mysql +column_stat columns_priv db event @@ -85,12 +92,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 6694cf48109..1370fb86875 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -95,6 +95,7 @@ USER_STATISTICS VIEWS XTRADB_ADMIN_COMMAND XTRADB_ENHANCEMENTS +column_stat columns_priv db event @@ -105,6 +106,7 @@ help_keyword help_relation help_topic host +index_stat plugin proc procs_priv @@ -115,6 +117,7 @@ t2 t3 t4 t5 +table_stat tables_priv time_zone time_zone_leap_second @@ -132,6 +135,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TABLE_STATISTICS TABLE_STATISTICS TRIGGERS TRIGGERS +table_stat table_stat tables_priv tables_priv time_zone time_zone time_zone_leap_second time_zone_leap_second @@ -152,6 +156,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TABLE_STATISTICS TABLE_STATISTICS TRIGGERS TRIGGERS +table_stat table_stat tables_priv tables_priv time_zone time_zone time_zone_leap_second time_zone_leap_second @@ -172,6 +177,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TABLE_STATISTICS TABLE_STATISTICS TRIGGERS TRIGGERS +table_stat table_stat tables_priv tables_priv time_zone time_zone time_zone_leap_second time_zone_leap_second diff --git a/mysql-test/r/information_schema_all_engines.result b/mysql-test/r/information_schema_all_engines.result index 7a2c548a329..ad172710052 100644 --- a/mysql-test/r/information_schema_all_engines.result +++ b/mysql-test/r/information_schema_all_engines.result @@ -382,4 +382,4 @@ Wildcard: inf_rmation_schema SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA; table_schema count(*) information_schema 52 -mysql 22 +mysql 25 diff --git a/mysql-test/r/log_tables_upgrade.result b/mysql-test/r/log_tables_upgrade.result index a9d1b41cf2c..53d6b6ce4eb 100644 --- a/mysql-test/r/log_tables_upgrade.result +++ b/mysql-test/r/log_tables_upgrade.result @@ -19,6 +19,7 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -28,12 +29,14 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.renamed_general_log OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK diff --git a/mysql-test/r/mysqlcheck.result b/mysql-test/r/mysqlcheck.result index 8aa121f9854..45904b0f088 100644 --- a/mysql-test/r/mysqlcheck.result +++ b/mysql-test/r/mysqlcheck.result @@ -3,6 +3,7 @@ drop view if exists v1; drop database if exists client_test_db; mtr.global_suppressions OK mtr.test_suppressions OK +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -12,11 +13,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -24,6 +27,7 @@ mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -33,11 +37,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result new file mode 100644 index 00000000000..424dec3bb9d --- /dev/null +++ b/mysql-test/r/statistics.result @@ -0,0 +1,455 @@ +drop table if exists t1,t2; +CREATE VIEW table_stat AS +SELECT * FROM mysql.table_stat; +CREATE VIEW column_stat AS +SELECT db_name, table_name, column_name, +min_value, max_value, +CAST(nulls_ratio AS decimal(12,4)) AS 'nulls_ratio', +CAST(avg_length AS decimal(12,4)) AS 'avg_length', +CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' + FROM mysql.column_stat; +CREATE VIEW index_stat AS +SELECT db_name, table_name, index_name, prefix_arity, +CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' + FROM mysql.index_stat; +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; +set optimizer_use_stat_tables='preferably'; +CREATE TABLE t1 ( +a int NOT NULL PRIMARY KEY, +b varchar(32), +c char(16), +d date, +e double, +f bit(3), +INDEX idx1 (b, e), +INDEX idx2(c, d), +INDEX idx3 (d), +INDEX idx4 (e, b, d) +); +INSERT INTO t1 VALUES +(0, NULL, NULL, NULL, NULL, NULL), +(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd', '1990-05-15', 0.1, b'100'), +(17, 'vvvvvvvvvvvvv', 'aaaa', '1989-03-12', 0.01, b'101'), +(1, 'vvvvvvvvvvvvv', NULL, '1989-03-12', 0.01, b'100'), +(12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.112, b'001'), +(23, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.1, b'100'), +(8, 'vvvvvvvvvvvvv', 'aaaa', '1999-07-23', 0.1, b'100'), +(22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa', '1989-03-12', 0.112, b'001'), +(31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa', '1999-07-23', 0.01, b'001'), +(10, NULL, 'aaaa', NULL, 0.01, b'010'), +(5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.1, b'100'), +(15, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.1, b'010'), +(30, NULL, 'bbbbbb', NULL, NULL, b'100'), +(38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, NULL, NULL), +(18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc', '1990-05-15', 0.01, b'010'), +(9, 'yyy', 'bbbbbb', '1998-08-28', 0.01, NULL), +(29, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.012, b'010'), +(3, 'yyy', 'dddddddd', '1990-05-15', 0.112, b'010'), +(39, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, 0.01, b'100'), +(14, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.1, b'100'), +(40, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', '1989-03-12', NULL, NULL), +(44, NULL, 'aaaa', '1989-03-12', NULL, b'010'), +(19, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.012, b'011'), +(21, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.112, b'100'), +(45, NULL, NULL, '1989-03-12', NULL, b'011'), +(2, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'ccccccccc', '1990-05-15', 0.1, b'001'), +(35, 'yyy', 'aaaa', '1990-05-15', 0.05, b'011'), +(4, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.01, b'101'), +(47, NULL, 'aaaa', '1990-05-15', 0.05, b'010'), +(42, NULL, 'ccccccccc', '1989-03-12', 0.01, b'010'), +(32, NULL, 'bbbbbb', '1990-05-15', 0.01, b'011'), +(49, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'aaaa', '1990-05-15', NULL, NULL), +(43, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'bbbbbb', '1990-05-15', NULL, b'100'), +(37, 'yyy', NULL, '1989-03-12', 0.05, b'011'), +(41, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.05, NULL), +(34, 'yyy', NULL, NULL, NULL, NULL), +(33, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.05, b'011'), +(24, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1990-05-15', 0.01, b'101'), +(11, 'yyy', 'ccccccccc', '1999-07-23', 0.1, NULL), +(25, 'zzzzzzzzzzzzzzzzzz', 'bbb', '1989-03-12', 0.01, b'101'); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM table_stat; +db_name table_name cardinality +test t1 40 +SELECT * FROM column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +SELECT COUNT(*) FROM t1; +COUNT(*) +40 +SELECT * FROM column_stat +WHERE db_name='test' AND table_name='t1' AND column_name='a'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +SELECT MIN(t1.a), MAX(t1.a), +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.a)", +(SELECT COUNT(t1.a) FROM t1) / +(SELECT COUNT(DISTINCT t1.a) FROM t1) AS "AVG_FREQUENCY(t1.a)" +FROM t1; +MIN(t1.a) MAX(t1.a) NULLS_RATIO(t1.a) AVG_FREQUENCY(t1.a) +0 49 0.2000 1.0000 +SELECT * FROM column_stat +WHERE db_name='test' AND table_name='t1' AND column_name='b'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +SELECT MIN(t1.b), MAX(t1.b), +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.b)", +(SELECT COUNT(t1.b) FROM t1) / +(SELECT COUNT(DISTINCT t1.b) FROM t1) AS "AVG_FREQUENCY(t1.b)" +FROM t1; +MIN(t1.b) MAX(t1.b) NULLS_RATIO(t1.b) AVG_FREQUENCY(t1.b) +vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 +SELECT * FROM column_stat +WHERE db_name='test' AND table_name='t1' AND column_name='c'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +SELECT MIN(t1.c), MAX(t1.c), +(SELECT COUNT(*) FROM t1 WHERE t1.c IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.c)", +(SELECT COUNT(t1.c) FROM t1) / +(SELECT COUNT(DISTINCT t1.c) FROM t1) AS "AVG_FREQUENCY(t1.c)" +FROM t1; +MIN(t1.c) MAX(t1.c) NULLS_RATIO(t1.c) AVG_FREQUENCY(t1.c) +aaaa dddddddd 0.1250 7.0000 +SELECT * FROM column_stat +WHERE db_name='test' AND table_name='t1' AND column_name='d'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +SELECT MIN(t1.d), MAX(t1.d), +(SELECT COUNT(*) FROM t1 WHERE t1.d IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.d)", +(SELECT COUNT(t1.d) FROM t1) / +(SELECT COUNT(DISTINCT t1.d) FROM t1) AS "AVG_FREQUENCY(t1.d)" +FROM t1; +MIN(t1.d) MAX(t1.d) NULLS_RATIO(t1.d) AVG_FREQUENCY(t1.d) +1989-03-12 1999-07-23 0.1500 8.5000 +SELECT * FROM column_stat +WHERE db_name='test' AND table_name='t1' AND column_name='e'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +SELECT MIN(t1.e), MAX(t1.e), +(SELECT COUNT(*) FROM t1 WHERE t1.e IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.e)", +(SELECT COUNT(t1.e) FROM t1) / +(SELECT COUNT(DISTINCT t1.e) FROM t1) AS "AVG_FREQUENCY(t1.e)" +FROM t1; +MIN(t1.e) MAX(t1.e) NULLS_RATIO(t1.e) AVG_FREQUENCY(t1.e) +0.01 0.112 0.2250 6.2000 +SELECT * FROM index_stat +WHERE db_name='test' AND table_name='t1' AND index_name='idx1'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.b) FROM t1 WHERE t1.b IS NOT NULL) +AS 'ARITY 1', +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.b, t1.e) FROM t1 +WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) +AS 'ARITY 2'; +ARITY 1 ARITY 2 +6.4000 1.6875 +SELECT * FROM index_stat +WHERE db_name='test' AND table_name='t1' AND index_name='idx2'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.c) FROM t1 WHERE t1.c IS NOT NULL) +AS 'ARITY 1', +(SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.c, t1.d) FROM t1 +WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) +AS 'ARITY 2'; +ARITY 1 ARITY 2 +7.0000 2.3846 +SELECT * FROM index_stat +WHERE db_name='test' AND table_name='t1' AND index_name='idx3'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx3 1 8.5000 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.d IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.d) FROM t1 WHERE t1.d IS NOT NULL) +AS 'ARITY 1'; +ARITY 1 +8.5000 +SELECT * FROM index_stat +WHERE db_name='test' AND table_name='t1' AND index_name='idx4'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.e) FROM t1 WHERE t1.e IS NOT NULL) +AS 'ARITY 1', +(SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.e, t1.b) FROM t1 +WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) +AS 'ARITY 2', +(SELECT COUNT(*) FROM t1 +WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.e, t1.b, t1.d) FROM t1 +WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) +AS 'ARITY 3'; +ARITY 1 ARITY 2 ARITY 3 +6.2000 1.6875 1.1304 +CREATE TABLE t2 LIKE t1; +ALTER TABLE t2 ENGINE=InnoDB; +INSERT INTO t2 SELECT * FROM t1; +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM table_stat; +db_name table_name cardinality +test t1 40 +test t2 40 +SELECT * FROM column_stat ORDER BY column_name; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t2 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t2 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +test t2 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM index_stat ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t2 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t2 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t2 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t2 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t2 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t2 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t2 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t2 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t2 idx4 3 1.1304 +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; +ALTER TABLE t1 +DROP INDEX idx1, +DROP INDEX idx4; +ALTER TABLE t1 +MODIFY COLUMN b text, +ADD INDEX idx1 (b(4), e), +ADD INDEX idx4 (e, b(4), d); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b NULL NULL 0.2000 17.1250 NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx1 1 NULL +test t1 idx1 2 NULL +test t1 idx4 1 6.2000 +test t1 idx4 2 NULL +test t1 idx4 3 NULL +DROP TABLE t1,t2; +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; +set optimizer_use_stat_tables='never'; +set names utf8; +CREATE DATABASE world; +use world; +CREATE TABLE Country ( +Code char(3) NOT NULL default '', +Name char(52) NOT NULL default '', +SurfaceArea float(10,2) NOT NULL default '0.00', +Population int(11) NOT NULL default '0', +Capital int(11) default NULL, +PRIMARY KEY (Code), +UNIQUE INDEX (Name) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE City ( +ID int(11) NOT NULL auto_increment, +Name char(35) NOT NULL default '', +Country char(3) NOT NULL default '', +Population int(11) NOT NULL default '0', +PRIMARY KEY (ID), +INDEX (Population), +INDEX (Country) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE CountryLanguage ( +Country char(3) NOT NULL default '', +Language char(30) NOT NULL default '', +Percentage float(3,1) NOT NULL default '0.0', +PRIMARY KEY (Country, Language), +INDEX (Percentage) +) CHARACTER SET utf8 COLLATE utf8_bin; +set optimizer_use_stat_tables='preferably'; +ANALYZE TABLE Country, City, CountryLanguage; +SELECT * FROM test.table_stat; +db_name table_name cardinality +world Country 239 +world City 4079 +world CountryLanguage 984 +SELECT * FROM test.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +world Country Code ABW ZWE 0.0000 3.0000 1.0000 +world Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +world Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +world Country Population 0 1277558000 0.0000 4.0000 1.0575 +world Country Capital 1 4074 0.0293 4.0000 1.0000 +world City ID 1 4079 0.0000 4.0000 1.0000 +world City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +world City Country ABW ZWE 0.0000 3.0000 17.5819 +world City Population 42 10500000 0.0000 4.0000 1.0467 +world CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 +world CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +world CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT * FROM test.index_stat; +db_name table_name index_name prefix_arity avg_frequency +world Country PRIMARY 1 1.0000 +world Country Name 1 1.0000 +world City PRIMARY 1 1.0000 +world City Population 1 1.0467 +world City Country 1 17.5819 +world CountryLanguage PRIMARY 1 4.2232 +world CountryLanguage PRIMARY 2 1.0000 +world CountryLanguage Percentage 1 2.7640 +use test; +set optimizer_use_stat_tables='never'; +CREATE DATABASE world_innodb; +use world_innodb; +CREATE TABLE Country ( +Code char(3) NOT NULL default '', +Name char(52) NOT NULL default '', +SurfaceArea float(10,2) NOT NULL default '0.00', +Population int(11) NOT NULL default '0', +Capital int(11) default NULL, +PRIMARY KEY (Code), +UNIQUE INDEX (Name) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE City ( +ID int(11) NOT NULL auto_increment, +Name char(35) NOT NULL default '', +Country char(3) NOT NULL default '', +Population int(11) NOT NULL default '0', +PRIMARY KEY (ID), +INDEX (Population), +INDEX (Country) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE CountryLanguage ( +Country char(3) NOT NULL default '', +Language char(30) NOT NULL default '', +Percentage float(3,1) NOT NULL default '0.0', +PRIMARY KEY (Country, Language), +INDEX (Percentage) +) CHARACTER SET utf8 COLLATE utf8_bin; +ALTER TABLE Country ENGINE=InnoDB; +ALTER TABLE City ENGINE=InnoDB; +ALTER TABLE CountryLanguage ENGINE=InnoDB; +set optimizer_use_stat_tables='preferably'; +ANALYZE TABLE Country, City, CountryLanguage; +SELECT * FROM test.table_stat; +db_name table_name cardinality +world Country 239 +world City 4079 +world CountryLanguage 984 +world_innodb Country 239 +world_innodb City 4079 +world_innodb CountryLanguage 984 +SELECT * FROM test.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +world Country Code ABW ZWE 0.0000 3.0000 1.0000 +world Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +world Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +world Country Population 0 1277558000 0.0000 4.0000 1.0575 +world Country Capital 1 4074 0.0293 4.0000 1.0000 +world City ID 1 4079 0.0000 4.0000 1.0000 +world City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +world City Country ABW ZWE 0.0000 3.0000 17.5819 +world City Population 42 10500000 0.0000 4.0000 1.0467 +world CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 +world CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +world CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 +world_innodb Country Code ABW ZWE 0.0000 3.0000 1.0000 +world_innodb Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +world_innodb Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +world_innodb Country Population 0 1277558000 0.0000 4.0000 1.0575 +world_innodb Country Capital 1 4074 0.0293 4.0000 1.0000 +world_innodb City ID 1 4079 0.0000 4.0000 1.0000 +world_innodb City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +world_innodb City Country ABW ZWE 0.0000 3.0000 17.5819 +world_innodb City Population 42 10500000 0.0000 4.0000 1.0467 +world_innodb CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 +world_innodb CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +world_innodb CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT * FROM test.index_stat; +db_name table_name index_name prefix_arity avg_frequency +world Country PRIMARY 1 1.0000 +world Country Name 1 1.0000 +world City PRIMARY 1 1.0000 +world City Population 1 1.0467 +world City Country 1 17.5819 +world CountryLanguage PRIMARY 1 4.2232 +world CountryLanguage PRIMARY 2 1.0000 +world CountryLanguage Percentage 1 2.7640 +world_innodb Country PRIMARY 1 1.0000 +world_innodb Country Name 1 1.0000 +world_innodb City PRIMARY 1 1.0000 +world_innodb City Population 1 1.0467 +world_innodb City Country 1 17.5819 +world_innodb CountryLanguage PRIMARY 1 4.2232 +world_innodb CountryLanguage PRIMARY 2 1.0000 +world_innodb CountryLanguage Percentage 1 2.7640 +use test; +DROP DATABASE world; +DROP DATABASE world_innodb; +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; +DROP VIEW test.table_stat; +DROP VIEW test.column_stat; +DROP VIEW test.index_stat; diff --git a/mysql-test/r/system_mysql_db.result b/mysql-test/r/system_mysql_db.result index 5079d72aaea..312383c8ee6 100644 --- a/mysql-test/r/system_mysql_db.result +++ b/mysql-test/r/system_mysql_db.result @@ -1,5 +1,6 @@ show tables; Tables_in_db +column_stat columns_priv db event @@ -10,12 +11,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second @@ -262,5 +265,36 @@ slow_log CREATE TABLE `slow_log` ( `server_id` int(10) unsigned NOT NULL, `sql_text` mediumtext NOT NULL ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +show create table table_stat; +Table Create Table +table_stat CREATE TABLE `table_stat` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `cardinality` bigint(21) unsigned DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables' +show create table column_stat; +Table Create Table +column_stat CREATE TABLE `column_stat` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `column_name` varchar(64) COLLATE utf8_bin NOT NULL, + `min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `nulls_ratio` double DEFAULT NULL, + `avg_length` double DEFAULT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`column_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns' +show create table index_stat; +Table Create Table +index_stat CREATE TABLE `index_stat` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `index_name` varchar(64) COLLATE utf8_bin NOT NULL, + `prefix_arity` int(11) unsigned NOT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes' show tables; Tables_in_test diff --git a/mysql-test/suite/pbxt/r/connect.result b/mysql-test/suite/pbxt/r/connect.result index c8d048f4d38..f4b042a4e84 100644 --- a/mysql-test/suite/pbxt/r/connect.result +++ b/mysql-test/suite/pbxt/r/connect.result @@ -1,6 +1,7 @@ drop table if exists t1,t2; show tables; Tables_in_mysql +column_stat columns_priv db event @@ -11,12 +12,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second @@ -34,6 +37,7 @@ grant ALL on *.* to test@localhost identified by "gambling"; grant ALL on *.* to test@127.0.0.1 identified by "gambling"; show tables; Tables_in_mysql +column_stat columns_priv db event @@ -44,12 +48,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second @@ -75,6 +81,7 @@ ERROR HY000: Password hash should be a 41-digit hexadecimal number set password=old_password('gambling3'); show tables; Tables_in_mysql +column_stat columns_priv db event @@ -85,12 +92,14 @@ help_keyword help_relation help_topic host +index_stat ndb_binlog_index plugin proc procs_priv servers slow_log +table_stat tables_priv time_zone time_zone_leap_second diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test new file mode 100644 index 00000000000..9ea57aca14a --- /dev/null +++ b/mysql-test/t/statistics.test @@ -0,0 +1,290 @@ +--source include/have_innodb.inc +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + +CREATE VIEW table_stat AS +SELECT * FROM mysql.table_stat; + +CREATE VIEW column_stat AS + SELECT db_name, table_name, column_name, + min_value, max_value, + CAST(nulls_ratio AS decimal(12,4)) AS 'nulls_ratio', + CAST(avg_length AS decimal(12,4)) AS 'avg_length', + CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' + FROM mysql.column_stat; + +CREATE VIEW index_stat AS + SELECT db_name, table_name, index_name, prefix_arity, + CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' + FROM mysql.index_stat; + +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; + +set optimizer_use_stat_tables='preferably'; + +CREATE TABLE t1 ( + a int NOT NULL PRIMARY KEY, + b varchar(32), + c char(16), + d date, + e double, + f bit(3), + INDEX idx1 (b, e), + INDEX idx2(c, d), + INDEX idx3 (d), + INDEX idx4 (e, b, d) +); + +INSERT INTO t1 VALUES + (0, NULL, NULL, NULL, NULL, NULL), + (7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd', '1990-05-15', 0.1, b'100'), + (17, 'vvvvvvvvvvvvv', 'aaaa', '1989-03-12', 0.01, b'101'), + (1, 'vvvvvvvvvvvvv', NULL, '1989-03-12', 0.01, b'100'), + (12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.112, b'001'), + (23, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.1, b'100'), + (8, 'vvvvvvvvvvvvv', 'aaaa', '1999-07-23', 0.1, b'100'), + (22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa', '1989-03-12', 0.112, b'001'), + (31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa', '1999-07-23', 0.01, b'001'), + (10, NULL, 'aaaa', NULL, 0.01, b'010'), + (5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.1, b'100'), + (15, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.1, b'010'), + (30, NULL, 'bbbbbb', NULL, NULL, b'100'), + (38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, NULL, NULL), + (18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc', '1990-05-15', 0.01, b'010'), + (9, 'yyy', 'bbbbbb', '1998-08-28', 0.01, NULL), + (29, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.012, b'010'), + (3, 'yyy', 'dddddddd', '1990-05-15', 0.112, b'010'), + (39, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, 0.01, b'100'), + (14, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.1, b'100'), + (40, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', '1989-03-12', NULL, NULL), + (44, NULL, 'aaaa', '1989-03-12', NULL, b'010'), + (19, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.012, b'011'), + (21, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.112, b'100'), + (45, NULL, NULL, '1989-03-12', NULL, b'011'), + (2, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'ccccccccc', '1990-05-15', 0.1, b'001'), + (35, 'yyy', 'aaaa', '1990-05-15', 0.05, b'011'), + (4, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.01, b'101'), + (47, NULL, 'aaaa', '1990-05-15', 0.05, b'010'), + (42, NULL, 'ccccccccc', '1989-03-12', 0.01, b'010'), + (32, NULL, 'bbbbbb', '1990-05-15', 0.01, b'011'), + (49, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'aaaa', '1990-05-15', NULL, NULL), + (43, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'bbbbbb', '1990-05-15', NULL, b'100'), + (37, 'yyy', NULL, '1989-03-12', 0.05, b'011'), + (41, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.05, NULL), + (34, 'yyy', NULL, NULL, NULL, NULL), + (33, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.05, b'011'), + (24, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1990-05-15', 0.01, b'101'), + (11, 'yyy', 'ccccccccc', '1999-07-23', 0.1, NULL), + (25, 'zzzzzzzzzzzzzzzzzz', 'bbb', '1989-03-12', 0.01, b'101'); + +ANALYZE TABLE t1; + +SELECT * FROM table_stat; +SELECT * FROM column_stat; +SELECT * FROM index_stat; + +SELECT COUNT(*) FROM t1; + +SELECT * FROM column_stat + WHERE db_name='test' AND table_name='t1' AND column_name='a'; +SELECT MIN(t1.a), MAX(t1.a), + (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / + (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.a)", + (SELECT COUNT(t1.a) FROM t1) / + (SELECT COUNT(DISTINCT t1.a) FROM t1) AS "AVG_FREQUENCY(t1.a)" +FROM t1; + +SELECT * FROM column_stat + WHERE db_name='test' AND table_name='t1' AND column_name='b'; +SELECT MIN(t1.b), MAX(t1.b), + (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / + (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.b)", + (SELECT COUNT(t1.b) FROM t1) / + (SELECT COUNT(DISTINCT t1.b) FROM t1) AS "AVG_FREQUENCY(t1.b)" +FROM t1; + +SELECT * FROM column_stat + WHERE db_name='test' AND table_name='t1' AND column_name='c'; +SELECT MIN(t1.c), MAX(t1.c), + (SELECT COUNT(*) FROM t1 WHERE t1.c IS NULL) / + (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.c)", + (SELECT COUNT(t1.c) FROM t1) / + (SELECT COUNT(DISTINCT t1.c) FROM t1) AS "AVG_FREQUENCY(t1.c)" +FROM t1; + +SELECT * FROM column_stat + WHERE db_name='test' AND table_name='t1' AND column_name='d'; +SELECT MIN(t1.d), MAX(t1.d), + (SELECT COUNT(*) FROM t1 WHERE t1.d IS NULL) / + (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.d)", + (SELECT COUNT(t1.d) FROM t1) / + (SELECT COUNT(DISTINCT t1.d) FROM t1) AS "AVG_FREQUENCY(t1.d)" +FROM t1; + +SELECT * FROM column_stat + WHERE db_name='test' AND table_name='t1' AND column_name='e'; +SELECT MIN(t1.e), MAX(t1.e), + (SELECT COUNT(*) FROM t1 WHERE t1.e IS NULL) / + (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.e)", + (SELECT COUNT(t1.e) FROM t1) / + (SELECT COUNT(DISTINCT t1.e) FROM t1) AS "AVG_FREQUENCY(t1.e)" +FROM t1; + +SELECT * FROM index_stat + WHERE db_name='test' AND table_name='t1' AND index_name='idx1'; +SELECT + (SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.b) FROM t1 WHERE t1.b IS NOT NULL) + AS 'ARITY 1', + (SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.b, t1.e) FROM t1 + WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) + AS 'ARITY 2'; + +SELECT * FROM index_stat + WHERE db_name='test' AND table_name='t1' AND index_name='idx2'; +SELECT + (SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.c) FROM t1 WHERE t1.c IS NOT NULL) + AS 'ARITY 1', + (SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.c, t1.d) FROM t1 + WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) + AS 'ARITY 2'; + +SELECT * FROM index_stat + WHERE db_name='test' AND table_name='t1' AND index_name='idx3'; +SELECT + (SELECT COUNT(*) FROM t1 WHERE t1.d IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.d) FROM t1 WHERE t1.d IS NOT NULL) + AS 'ARITY 1'; + +SELECT * FROM index_stat + WHERE db_name='test' AND table_name='t1' AND index_name='idx4'; +SELECT + (SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.e) FROM t1 WHERE t1.e IS NOT NULL) + AS 'ARITY 1', + (SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.e, t1.b) FROM t1 + WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) + AS 'ARITY 2', + (SELECT COUNT(*) FROM t1 + WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) / + (SELECT COUNT(DISTINCT t1.e, t1.b, t1.d) FROM t1 + WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) + AS 'ARITY 3'; + + +CREATE TABLE t2 LIKE t1; +ALTER TABLE t2 ENGINE=InnoDB; +INSERT INTO t2 SELECT * FROM t1; + +ANALYZE TABLE t2; + +SELECT * FROM table_stat; +SELECT * FROM column_stat ORDER BY column_name; +SELECT * FROM index_stat ORDER BY index_name, prefix_arity, table_name; + + +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; + +ALTER TABLE t1 + DROP INDEX idx1, + DROP INDEX idx4; +ALTER TABLE t1 + MODIFY COLUMN b text, + ADD INDEX idx1 (b(4), e), + ADD INDEX idx4 (e, b(4), d); + +ANALYZE TABLE t1; + +SELECT * FROM column_stat; +SELECT * FROM index_stat; + +DROP TABLE t1,t2; + +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; + +set optimizer_use_stat_tables='never'; + +set names utf8; + +CREATE DATABASE world; + +use world; + +--source include/world_schema_utf8.inc + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/world.inc +--enable_warnings +--enable_result_log +--enable_query_log + +set optimizer_use_stat_tables='preferably'; + +--disable_result_log +ANALYZE TABLE Country, City, CountryLanguage; +--enable_result_log + +SELECT * FROM test.table_stat; +SELECT * FROM test.column_stat; +SELECT * FROM test.index_stat; + +use test; + +set optimizer_use_stat_tables='never'; + +CREATE DATABASE world_innodb; + +use world_innodb; + +--source include/world_schema_utf8.inc + +ALTER TABLE Country ENGINE=InnoDB; +ALTER TABLE City ENGINE=InnoDB; +ALTER TABLE CountryLanguage ENGINE=InnoDB; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/world.inc +--enable_warnings +--enable_result_log +--enable_query_log + +set optimizer_use_stat_tables='preferably'; + +--disable_result_log +ANALYZE TABLE Country, City, CountryLanguage; +--enable_result_log + +SELECT * FROM test.table_stat; +SELECT * FROM test.column_stat; +SELECT * FROM test.index_stat; + +use test; + +DROP DATABASE world; +DROP DATABASE world_innodb; + +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; + +DROP VIEW test.table_stat; +DROP VIEW test.column_stat; +DROP VIEW test.index_stat; + + + \ No newline at end of file diff --git a/mysql-test/t/system_mysql_db_fix30020.test b/mysql-test/t/system_mysql_db_fix30020.test index 0a7d9dad7c9..e5f743f25fe 100644 --- a/mysql-test/t/system_mysql_db_fix30020.test +++ b/mysql-test/t/system_mysql_db_fix30020.test @@ -97,7 +97,8 @@ INSERT INTO user VALUES ('localhost','', '','N','N','N','N','N','N','N','N',' DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, -time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index; +time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, +table_stat, column_stat, index_stat; -- enable_query_log diff --git a/mysql-test/t/system_mysql_db_fix40123.test b/mysql-test/t/system_mysql_db_fix40123.test index 08d40bdae0f..4a91872a27a 100644 --- a/mysql-test/t/system_mysql_db_fix40123.test +++ b/mysql-test/t/system_mysql_db_fix40123.test @@ -59,6 +59,11 @@ CREATE TABLE time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; +CREATE TABLE table_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables'; + +CREATE TABLE column_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio double DEFAULT NULL, avg_length double DEFAULT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns'; + +CREATE TABLE index_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes'; # Run the mysql_fix_privilege_tables.sql using "mysql --force" --exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES > $MYSQLTEST_VARDIR/log/system_mysql_db_fix40123.log 2>&1 @@ -72,7 +77,7 @@ CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL, -- disable_query_log # Drop all tables created by this test -DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index; +DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, table_stat, column_stat, index_stat; -- enable_query_log diff --git a/mysql-test/t/system_mysql_db_fix50030.test b/mysql-test/t/system_mysql_db_fix50030.test index 41e85661fe8..cabef0f6b8a 100644 --- a/mysql-test/t/system_mysql_db_fix50030.test +++ b/mysql-test/t/system_mysql_db_fix50030.test @@ -66,6 +66,12 @@ CREATE TABLE servers ( Server_name char(64) NOT NULL DEFAULT '', Host char(64) N INSERT INTO servers VALUES ('test','localhost','test','root','', 0,'','mysql','root'); +CREATE TABLE table_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables'; + +CREATE TABLE column_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio double DEFAULT NULL, avg_length double DEFAULT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns'; + +CREATE TABLE index_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes'; + # Run the mysql_fix_privilege_tables.sql using "mysql --force" --exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES > $MYSQLTEST_VARDIR/log/system_mysql_db_fix50030.log 2>&1 @@ -78,7 +84,7 @@ INSERT INTO servers VALUES ('test','localhost','test','root','', 0,'','mysql','r -- disable_query_log # Drop all tables created by this test -DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index; +DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, table_stat, column_stat, index_stat; -- enable_query_log diff --git a/mysql-test/t/system_mysql_db_fix50117.test b/mysql-test/t/system_mysql_db_fix50117.test index bed00239081..c2db3f191b0 100644 --- a/mysql-test/t/system_mysql_db_fix50117.test +++ b/mysql-test/t/system_mysql_db_fix50117.test @@ -85,6 +85,12 @@ CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_b CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; +CREATE TABLE table_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables'; + +CREATE TABLE column_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio double DEFAULT NULL, avg_length double DEFAULT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns'; + +CREATE TABLE index_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes'; + # Run the mysql_fix_privilege_tables.sql using "mysql --force" --exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES > $MYSQLTEST_VARDIR/log/system_mysql_db_fix50117.log 2>&1 @@ -97,7 +103,7 @@ CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, -- disable_query_log # Drop all tables created by this test -DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index; +DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, table_stat, column_stat, index_stat; -- enable_query_log -- cgit v1.2.1 From 7895f510a4019a8b96e447ca95b4e1ee4a9b6272 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 4 Jan 2012 18:32:21 -0800 Subject: In statistics.test: Saved at the very beginning and restored at the very end the value of optimizer_use_stat_tables. --- mysql-test/r/statistics.result | 2 ++ mysql-test/t/statistics.test | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'mysql-test') diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index 424dec3bb9d..59af26014c6 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -1,4 +1,5 @@ drop table if exists t1,t2; +set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; CREATE VIEW table_stat AS SELECT * FROM mysql.table_stat; CREATE VIEW column_stat AS @@ -453,3 +454,4 @@ DELETE FROM mysql.index_stat; DROP VIEW test.table_stat; DROP VIEW test.column_stat; DROP VIEW test.index_stat; +set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 9ea57aca14a..0a32fcde881 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -3,6 +3,8 @@ drop table if exists t1,t2; --enable_warnings +set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; + CREATE VIEW table_stat AS SELECT * FROM mysql.table_stat; @@ -286,5 +288,6 @@ DROP VIEW test.table_stat; DROP VIEW test.column_stat; DROP VIEW test.index_stat; - +set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; + \ No newline at end of file -- cgit v1.2.1 From 699dc423584fa86aafc9346377a02b98b1eebf47 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 5 Jan 2012 18:55:37 -0800 Subject: Fixed a compiler warning. Adjusted results for mysql_upgrade.test --- mysql-test/r/mysql_upgrade.result | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/mysql_upgrade.result b/mysql-test/r/mysql_upgrade.result index ca23dc9cca1..f0a7a036f0c 100644 --- a/mysql-test/r/mysql_upgrade.result +++ b/mysql-test/r/mysql_upgrade.result @@ -7,6 +7,7 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -16,11 +17,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -42,6 +45,7 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -51,11 +55,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -77,6 +83,7 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -86,11 +93,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -115,6 +124,7 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -124,11 +134,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -156,6 +168,7 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -165,11 +178,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -200,6 +215,7 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stat OK mysql.columns_priv OK mysql.db OK mysql.event OK @@ -209,11 +225,13 @@ mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stat OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK +mysql.table_stat OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK -- cgit v1.2.1 From 6f91e434f79287a6d31204e981813f7c62f608cc Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 5 Jan 2012 22:45:08 -0800 Subject: Adjusted results for the test suite funcs_1. --- mysql-test/suite/funcs_1/r/is_columns_mysql.result | 34 +++++++++++ .../suite/funcs_1/r/is_statistics_mysql.result | 9 +++ .../funcs_1/r/is_table_constraints_mysql.result | 3 + mysql-test/suite/funcs_1/r/is_tables_mysql.result | 69 ++++++++++++++++++++++ 4 files changed, 115 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/suite/funcs_1/r/is_columns_mysql.result b/mysql-test/suite/funcs_1/r/is_columns_mysql.result index 8d486bae3a3..27e44be7eae 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_mysql.result +++ b/mysql-test/suite/funcs_1/r/is_columns_mysql.result @@ -9,6 +9,14 @@ NULL mysql columns_priv Host 1 NO char 60 180 NULL NULL NULL utf8 utf8_bin char NULL mysql columns_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin char(64) PRI select,insert,update,references NULL mysql columns_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP select,insert,update,references NULL mysql columns_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references +NULL mysql column_stat avg_frequency 8 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references +NULL mysql column_stat avg_length 7 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references +NULL mysql column_stat column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references +NULL mysql column_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references +NULL mysql column_stat max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references +NULL mysql column_stat min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references +NULL mysql column_stat nulls_ratio 6 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references +NULL mysql column_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references NULL mysql db Alter_priv 13 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references NULL mysql db Alter_routine_priv 19 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references NULL mysql db Create_priv 8 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references @@ -97,6 +105,11 @@ NULL mysql host Select_priv 3 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci NULL mysql host Show_view_priv 16 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references NULL mysql host Trigger_priv 20 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references NULL mysql host Update_priv 5 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references +NULL mysql index_stat avg_frequency 5 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references +NULL mysql index_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references +NULL mysql index_stat index_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references +NULL mysql index_stat prefix_arity 4 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned PRI select,insert,update,references +NULL mysql index_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references NULL mysql ndb_binlog_index deletes 6 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references NULL mysql ndb_binlog_index epoch 3 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned PRI select,insert,update,references NULL mysql ndb_binlog_index File 2 NULL NO varchar 255 255 NULL NULL NULL latin1 latin1_swedish_ci varchar(255) select,insert,update,references @@ -162,6 +175,9 @@ NULL mysql tables_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin NULL mysql tables_priv Table_priv 7 NO set 98 294 NULL NULL NULL utf8 utf8_general_ci set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') select,insert,update,references NULL mysql tables_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP select,insert,update,references NULL mysql tables_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references +NULL mysql table_stat cardinality 3 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select,insert,update,references +NULL mysql table_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references +NULL mysql table_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references NULL mysql time_zone Time_zone_id 1 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned PRI auto_increment select,insert,update,references NULL mysql time_zone Use_leap_seconds 2 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('Y','N') select,insert,update,references NULL mysql time_zone_leap_second Correction 2 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references @@ -250,6 +266,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML; COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME 3.0000 char utf8 utf8_bin 3.0000 enum utf8 utf8_bin +3.0000 varchar utf8 utf8_bin 3.0000 char utf8 utf8_general_ci 3.0000 enum utf8 utf8_general_ci 3.0000 set utf8 utf8_general_ci @@ -266,6 +283,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML; COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME NULL bigint NULL NULL NULL datetime NULL NULL +NULL double NULL NULL NULL int NULL NULL NULL smallint NULL NULL NULL time NULL NULL @@ -294,6 +312,14 @@ COL_CML TABLE_SCHEMA TABLE_NAME COLUMN_NAME DATA_TYPE CHARACTER_MAXIMUM_LENGTH C 3.0000 mysql columns_priv Column_name char 64 192 utf8 utf8_bin char(64) NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp 3.0000 mysql columns_priv Column_priv set 31 93 utf8 utf8_general_ci set('Select','Insert','Update','References') +3.0000 mysql column_stat db_name varchar 64 192 utf8 utf8_bin varchar(64) +3.0000 mysql column_stat table_name varchar 64 192 utf8 utf8_bin varchar(64) +3.0000 mysql column_stat column_name varchar 64 192 utf8 utf8_bin varchar(64) +3.0000 mysql column_stat min_value varchar 255 765 utf8 utf8_bin varchar(255) +3.0000 mysql column_stat max_value varchar 255 765 utf8 utf8_bin varchar(255) +NULL mysql column_stat nulls_ratio double NULL NULL NULL NULL double +NULL mysql column_stat avg_length double NULL NULL NULL NULL double +NULL mysql column_stat avg_frequency double NULL NULL NULL NULL double 3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60) 3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64) 3.0000 mysql db User char 16 48 utf8 utf8_bin char(16) @@ -382,6 +408,11 @@ NULL mysql help_topic help_category_id smallint NULL NULL NULL NULL smallint(5) 3.0000 mysql host Alter_routine_priv enum 1 3 utf8 utf8_general_ci enum('N','Y') 3.0000 mysql host Execute_priv enum 1 3 utf8 utf8_general_ci enum('N','Y') 3.0000 mysql host Trigger_priv enum 1 3 utf8 utf8_general_ci enum('N','Y') +3.0000 mysql index_stat db_name varchar 64 192 utf8 utf8_bin varchar(64) +3.0000 mysql index_stat table_name varchar 64 192 utf8 utf8_bin varchar(64) +3.0000 mysql index_stat index_name varchar 64 192 utf8 utf8_bin varchar(64) +NULL mysql index_stat prefix_arity int NULL NULL NULL NULL int(11) unsigned +NULL mysql index_stat avg_frequency double NULL NULL NULL NULL double NULL mysql ndb_binlog_index Position bigint NULL NULL NULL NULL bigint(20) unsigned 1.0000 mysql ndb_binlog_index File varchar 255 255 latin1 latin1_swedish_ci varchar(255) NULL mysql ndb_binlog_index epoch bigint NULL NULL NULL NULL bigint(20) unsigned @@ -447,6 +478,9 @@ NULL mysql slow_log server_id int NULL NULL NULL NULL int(10) unsigned NULL mysql tables_priv Timestamp timestamp NULL NULL NULL NULL timestamp 3.0000 mysql tables_priv Table_priv set 98 294 utf8 utf8_general_ci set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') 3.0000 mysql tables_priv Column_priv set 31 93 utf8 utf8_general_ci set('Select','Insert','Update','References') +3.0000 mysql table_stat db_name varchar 64 192 utf8 utf8_bin varchar(64) +3.0000 mysql table_stat table_name varchar 64 192 utf8 utf8_bin varchar(64) +NULL mysql table_stat cardinality bigint NULL NULL NULL NULL bigint(21) unsigned NULL mysql time_zone Time_zone_id int NULL NULL NULL NULL int(10) unsigned 3.0000 mysql time_zone Use_leap_seconds enum 1 3 utf8 utf8_general_ci enum('Y','N') NULL mysql time_zone_leap_second Transition_time bigint NULL NULL NULL NULL bigint(20) diff --git a/mysql-test/suite/funcs_1/r/is_statistics_mysql.result b/mysql-test/suite/funcs_1/r/is_statistics_mysql.result index ee37f6ef222..56a852ff6a1 100644 --- a/mysql-test/suite/funcs_1/r/is_statistics_mysql.result +++ b/mysql-test/suite/funcs_1/r/is_statistics_mysql.result @@ -12,6 +12,9 @@ NULL mysql columns_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE NULL mysql columns_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE NULL mysql columns_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE NULL mysql columns_priv 0 mysql PRIMARY 5 Column_name A #CARD# NULL NULL BTREE +NULL mysql column_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE +NULL mysql column_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE +NULL mysql column_stat 0 mysql PRIMARY 3 column_name A #CARD# NULL NULL BTREE NULL mysql db 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE NULL mysql db 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE NULL mysql db 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE @@ -29,6 +32,10 @@ NULL mysql help_topic 0 mysql name 1 name A #CARD# NULL NULL BTREE NULL mysql help_topic 0 mysql PRIMARY 1 help_topic_id A #CARD# NULL NULL BTREE NULL mysql host 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE NULL mysql host 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE +NULL mysql index_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE +NULL mysql index_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE +NULL mysql index_stat 0 mysql PRIMARY 3 index_name A #CARD# NULL NULL BTREE +NULL mysql index_stat 0 mysql PRIMARY 4 prefix_arity A #CARD# NULL NULL BTREE NULL mysql ndb_binlog_index 0 mysql PRIMARY 1 epoch A #CARD# NULL NULL BTREE NULL mysql plugin 0 mysql PRIMARY 1 name A #CARD# NULL NULL BTREE NULL mysql proc 0 mysql PRIMARY 1 db A #CARD# NULL NULL BTREE @@ -46,6 +53,8 @@ NULL mysql tables_priv 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE NULL mysql tables_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE NULL mysql tables_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE NULL mysql tables_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE +NULL mysql table_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE +NULL mysql table_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE NULL mysql time_zone 0 mysql PRIMARY 1 Time_zone_id A #CARD# NULL NULL BTREE NULL mysql time_zone_leap_second 0 mysql PRIMARY 1 Transition_time A #CARD# NULL NULL BTREE NULL mysql time_zone_name 0 mysql PRIMARY 1 Name A #CARD# NULL NULL BTREE diff --git a/mysql-test/suite/funcs_1/r/is_table_constraints_mysql.result b/mysql-test/suite/funcs_1/r/is_table_constraints_mysql.result index ba5da23f069..25c6fbafdb0 100644 --- a/mysql-test/suite/funcs_1/r/is_table_constraints_mysql.result +++ b/mysql-test/suite/funcs_1/r/is_table_constraints_mysql.result @@ -8,6 +8,7 @@ WHERE table_schema = 'mysql' ORDER BY table_schema,table_name,constraint_name; CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE NULL mysql PRIMARY mysql columns_priv PRIMARY KEY +NULL mysql PRIMARY mysql column_stat PRIMARY KEY NULL mysql PRIMARY mysql db PRIMARY KEY NULL mysql PRIMARY mysql event PRIMARY KEY NULL mysql PRIMARY mysql func PRIMARY KEY @@ -19,12 +20,14 @@ NULL mysql PRIMARY mysql help_relation PRIMARY KEY NULL mysql name mysql help_topic UNIQUE NULL mysql PRIMARY mysql help_topic PRIMARY KEY NULL mysql PRIMARY mysql host PRIMARY KEY +NULL mysql PRIMARY mysql index_stat PRIMARY KEY NULL mysql PRIMARY mysql ndb_binlog_index PRIMARY KEY NULL mysql PRIMARY mysql plugin PRIMARY KEY NULL mysql PRIMARY mysql proc PRIMARY KEY NULL mysql PRIMARY mysql procs_priv PRIMARY KEY NULL mysql PRIMARY mysql servers PRIMARY KEY NULL mysql PRIMARY mysql tables_priv PRIMARY KEY +NULL mysql PRIMARY mysql table_stat PRIMARY KEY NULL mysql PRIMARY mysql time_zone PRIMARY KEY NULL mysql PRIMARY mysql time_zone_leap_second PRIMARY KEY NULL mysql PRIMARY mysql time_zone_name PRIMARY KEY diff --git a/mysql-test/suite/funcs_1/r/is_tables_mysql.result b/mysql-test/suite/funcs_1/r/is_tables_mysql.result index b41318d9bae..21c58ac118c 100644 --- a/mysql-test/suite/funcs_1/r/is_tables_mysql.result +++ b/mysql-test/suite/funcs_1/r/is_tables_mysql.result @@ -37,6 +37,29 @@ user_comment Column privileges Separator ----------------------------------------------------- TABLE_CATALOG NULL TABLE_SCHEMA mysql +TABLE_NAME column_stat +TABLE_TYPE BASE TABLE +ENGINE MYISAM_OR_MARIA +VERSION 10 +ROW_FORMAT DYNAMIC_OR_PAGE +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8_bin +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +user_comment Statistics on Columns +Separator ----------------------------------------------------- +TABLE_CATALOG NULL +TABLE_SCHEMA mysql TABLE_NAME db TABLE_TYPE BASE TABLE ENGINE MYISAM_OR_MARIA @@ -244,6 +267,29 @@ user_comment Host privileges; Merged with database privileges Separator ----------------------------------------------------- TABLE_CATALOG NULL TABLE_SCHEMA mysql +TABLE_NAME index_stat +TABLE_TYPE BASE TABLE +ENGINE MYISAM_OR_MARIA +VERSION 10 +ROW_FORMAT DYNAMIC_OR_PAGE +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8_bin +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +user_comment Statistics on Indexes +Separator ----------------------------------------------------- +TABLE_CATALOG NULL +TABLE_SCHEMA mysql TABLE_NAME ndb_binlog_index TABLE_TYPE BASE TABLE ENGINE MYISAM_OR_MARIA @@ -405,6 +451,29 @@ user_comment Table privileges Separator ----------------------------------------------------- TABLE_CATALOG NULL TABLE_SCHEMA mysql +TABLE_NAME table_stat +TABLE_TYPE BASE TABLE +ENGINE MYISAM_OR_MARIA +VERSION 10 +ROW_FORMAT DYNAMIC_OR_PAGE +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8_bin +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +user_comment Statistics on Tables +Separator ----------------------------------------------------- +TABLE_CATALOG NULL +TABLE_SCHEMA mysql TABLE_NAME time_zone TABLE_TYPE BASE TABLE ENGINE MYISAM_OR_MARIA -- cgit v1.2.1 From d0dc6e07f6b33447465db149d84cff86020afc34 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 7 Jan 2012 00:34:30 -0800 Subject: Made statistics.test platform independent. --- mysql-test/r/statistics.result | 172 ++++++++++++++++++++++------------------- mysql-test/t/statistics.test | 22 ++++-- 2 files changed, 107 insertions(+), 87 deletions(-) (limited to 'mysql-test') diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index 59af26014c6..3a83f9ba66c 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -330,35 +330,40 @@ INDEX (Percentage) ) CHARACTER SET utf8 COLLATE utf8_bin; set optimizer_use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; -SELECT * FROM test.table_stat; -db_name table_name cardinality -world Country 239 -world City 4079 -world CountryLanguage 984 -SELECT * FROM test.column_stat; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -world Country Code ABW ZWE 0.0000 3.0000 1.0000 -world Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 -world Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 -world Country Population 0 1277558000 0.0000 4.0000 1.0575 -world Country Capital 1 4074 0.0293 4.0000 1.0000 -world City ID 1 4079 0.0000 4.0000 1.0000 -world City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 -world City Country ABW ZWE 0.0000 3.0000 17.5819 -world City Population 42 10500000 0.0000 4.0000 1.0467 -world CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 -world CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 -world CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 -SELECT * FROM test.index_stat; -db_name table_name index_name prefix_arity avg_frequency -world Country PRIMARY 1 1.0000 -world Country Name 1 1.0000 -world City PRIMARY 1 1.0000 -world City Population 1 1.0467 -world City Country 1 17.5819 -world CountryLanguage PRIMARY 1 4.2232 -world CountryLanguage PRIMARY 2 1.0000 -world CountryLanguage Percentage 1 2.7640 +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM test.table_stat; +UPPER(db_name) UPPER(table_name) cardinality +WORLD COUNTRY 239 +WORLD CITY 4079 +WORLD COUNTRYLANGUAGE 984 +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM test.column_stat; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +WORLD COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD CITY Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +WORLD CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM test.index_stat; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency +WORLD COUNTRY PRIMARY 1 1.0000 +WORLD COUNTRY Name 1 1.0000 +WORLD CITY PRIMARY 1 1.0000 +WORLD CITY Population 1 1.0467 +WORLD CITY Country 1 17.5819 +WORLD COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD COUNTRYLANGUAGE Percentage 1 2.7640 use test; set optimizer_use_stat_tables='never'; CREATE DATABASE world_innodb; @@ -393,58 +398,63 @@ ALTER TABLE City ENGINE=InnoDB; ALTER TABLE CountryLanguage ENGINE=InnoDB; set optimizer_use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; -SELECT * FROM test.table_stat; -db_name table_name cardinality -world Country 239 -world City 4079 -world CountryLanguage 984 -world_innodb Country 239 -world_innodb City 4079 -world_innodb CountryLanguage 984 -SELECT * FROM test.column_stat; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -world Country Code ABW ZWE 0.0000 3.0000 1.0000 -world Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 -world Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 -world Country Population 0 1277558000 0.0000 4.0000 1.0575 -world Country Capital 1 4074 0.0293 4.0000 1.0000 -world City ID 1 4079 0.0000 4.0000 1.0000 -world City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 -world City Country ABW ZWE 0.0000 3.0000 17.5819 -world City Population 42 10500000 0.0000 4.0000 1.0467 -world CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 -world CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 -world CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 -world_innodb Country Code ABW ZWE 0.0000 3.0000 1.0000 -world_innodb Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 -world_innodb Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 -world_innodb Country Population 0 1277558000 0.0000 4.0000 1.0575 -world_innodb Country Capital 1 4074 0.0293 4.0000 1.0000 -world_innodb City ID 1 4079 0.0000 4.0000 1.0000 -world_innodb City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 -world_innodb City Country ABW ZWE 0.0000 3.0000 17.5819 -world_innodb City Population 42 10500000 0.0000 4.0000 1.0467 -world_innodb CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 -world_innodb CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 -world_innodb CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 -SELECT * FROM test.index_stat; -db_name table_name index_name prefix_arity avg_frequency -world Country PRIMARY 1 1.0000 -world Country Name 1 1.0000 -world City PRIMARY 1 1.0000 -world City Population 1 1.0467 -world City Country 1 17.5819 -world CountryLanguage PRIMARY 1 4.2232 -world CountryLanguage PRIMARY 2 1.0000 -world CountryLanguage Percentage 1 2.7640 -world_innodb Country PRIMARY 1 1.0000 -world_innodb Country Name 1 1.0000 -world_innodb City PRIMARY 1 1.0000 -world_innodb City Population 1 1.0467 -world_innodb City Country 1 17.5819 -world_innodb CountryLanguage PRIMARY 1 4.2232 -world_innodb CountryLanguage PRIMARY 2 1.0000 -world_innodb CountryLanguage Percentage 1 2.7640 +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM test.table_stat; +UPPER(db_name) UPPER(table_name) cardinality +WORLD COUNTRY 239 +WORLD CITY 4079 +WORLD COUNTRYLANGUAGE 984 +WORLD_INNODB COUNTRY 239 +WORLD_INNODB CITY 4079 +WORLD_INNODB COUNTRYLANGUAGE 984 +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM test.column_stat; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +WORLD COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD CITY Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +WORLD CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +WORLD_INNODB COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD_INNODB COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD_INNODB COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD_INNODB COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD_INNODB COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD_INNODB CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD_INNODB CITY Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +WORLD_INNODB CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD_INNODB CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD_INNODB COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD_INNODB COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD_INNODB COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM test.index_stat; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency +WORLD COUNTRY PRIMARY 1 1.0000 +WORLD COUNTRY Name 1 1.0000 +WORLD CITY PRIMARY 1 1.0000 +WORLD CITY Population 1 1.0467 +WORLD CITY Country 1 17.5819 +WORLD COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD COUNTRYLANGUAGE Percentage 1 2.7640 +WORLD_INNODB COUNTRY PRIMARY 1 1.0000 +WORLD_INNODB COUNTRY Name 1 1.0000 +WORLD_INNODB CITY PRIMARY 1 1.0000 +WORLD_INNODB CITY Population 1 1.0467 +WORLD_INNODB CITY Country 1 17.5819 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640 use test; DROP DATABASE world; DROP DATABASE world_innodb; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 0a32fcde881..81108c9846d 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -239,9 +239,14 @@ set optimizer_use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; --enable_result_log -SELECT * FROM test.table_stat; -SELECT * FROM test.column_stat; -SELECT * FROM test.index_stat; +SELECT UPPER(db_name), UPPER(table_name), cardinality + FROM test.table_stat; +SELECT UPPER(db_name), UPPER(table_name), + column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency + FROM test.column_stat; +SELECT UPPER(db_name), UPPER(table_name), + index_name, prefix_arity, avg_frequency + FROM test.index_stat; use test; @@ -271,9 +276,14 @@ set optimizer_use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; --enable_result_log -SELECT * FROM test.table_stat; -SELECT * FROM test.column_stat; -SELECT * FROM test.index_stat; +SELECT UPPER(db_name), UPPER(table_name), cardinality + FROM test.table_stat; +SELECT UPPER(db_name), UPPER(table_name), + column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency + FROM test.column_stat; +SELECT UPPER(db_name), UPPER(table_name), + index_name, prefix_arity, avg_frequency + FROM test.index_stat; use test; -- 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. --- mysql-test/r/stat_tables.result | 229 ++++++++++++++++++++++++++++++++ mysql-test/r/stat_tables_innodb.result | 231 +++++++++++++++++++++++++++++++++ mysql-test/t/stat_tables.test | 108 +++++++++++++++ mysql-test/t/stat_tables_innodb.test | 7 + 4 files changed, 575 insertions(+) create mode 100644 mysql-test/r/stat_tables.result create mode 100644 mysql-test/r/stat_tables_innodb.result create mode 100644 mysql-test/t/stat_tables.test create mode 100644 mysql-test/t/stat_tables_innodb.test (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result new file mode 100644 index 00000000000..089c7871506 --- /dev/null +++ b/mysql-test/r/stat_tables.result @@ -0,0 +1,229 @@ +set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; +set optimizer_use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +select * from mysql.table_stat; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1 +dbt3_s001 customer i_c_nationkey 1 6 +dbt3_s001 lineitem PRIMARY 1 4.003333333333333 +dbt3_s001 lineitem PRIMARY 2 1 +dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 +dbt3_s001 lineitem i_l_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey 1 600.5 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 +dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 +dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 +dbt3_s001 nation PRIMARY 1 1 +dbt3_s001 nation i_n_regionkey 1 5 +dbt3_s001 orders PRIMARY 1 1 +dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 +dbt3_s001 orders i_o_custkey 1 15 +dbt3_s001 part PRIMARY 1 1 +dbt3_s001 part i_p_retailprice 1 1 +dbt3_s001 partsupp PRIMARY 1 3.5 +dbt3_s001 partsupp PRIMARY 2 1 +dbt3_s001 partsupp i_ps_partkey 1 3.5 +dbt3_s001 partsupp i_ps_suppkey 1 70 +dbt3_s001 region PRIMARY 1 1 +dbt3_s001 supplier PRIMARY 1 1 +dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 179 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +EXPLAIN select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +o_year mkt_share +1995 0.4495521838895718 +1996 0.024585468215352495 +EXPLAIN select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 Using where; Using temporary; Using filesort +1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8 +1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 +select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +nation o_year sum_profit +ARGENTINA 1997 18247.873399999993 +ARGENTINA 1996 7731.089399999995 +ARGENTINA 1995 134490.5697 +ARGENTINA 1994 36767.101500000004 +ARGENTINA 1993 35857.08 +ARGENTINA 1992 35740 +ETHIOPIA 1998 2758.7801999999992 +ETHIOPIA 1997 19419.294599999997 +ETHIOPIA 1995 51231.87439999999 +ETHIOPIA 1994 3578.9478999999974 +ETHIOPIA 1992 1525.8234999999986 +IRAN 1998 37817.229600000006 +IRAN 1997 52643.77359999999 +IRAN 1996 70143.7761 +IRAN 1995 84094.58260000001 +IRAN 1994 18140.925599999995 +IRAN 1993 78655.1676 +IRAN 1992 87142.23960000002 +IRAQ 1998 22860.8082 +IRAQ 1997 93676.24359999999 +IRAQ 1996 45103.3242 +IRAQ 1994 36010.728599999995 +IRAQ 1993 33221.9399 +IRAQ 1992 47755.05900000001 +KENYA 1998 44194.831999999995 +KENYA 1997 57578.36259999999 +KENYA 1996 59195.90210000001 +KENYA 1995 79262.6278 +KENYA 1994 102360.66609999999 +KENYA 1993 128422.0196 +KENYA 1992 181517.2089 +MOROCCO 1998 41797.823199999984 +MOROCCO 1997 23685.801799999994 +MOROCCO 1996 62115.19579999998 +MOROCCO 1995 42442.64300000001 +MOROCCO 1994 48655.878000000004 +MOROCCO 1993 22926.744400000003 +MOROCCO 1992 32239.8088 +PERU 1998 86999.36459999997 +PERU 1997 121110.41070000001 +PERU 1996 177040.40759999995 +PERU 1995 122247.94520000002 +PERU 1994 88046.25329999998 +PERU 1993 49379.813799999996 +PERU 1992 80646.86050000001 +UNITED KINGDOM 1998 50577.25560000001 +UNITED KINGDOM 1997 114288.8605 +UNITED KINGDOM 1996 147684.46480000002 +UNITED KINGDOM 1995 225267.65759999998 +UNITED KINGDOM 1994 140595.5864 +UNITED KINGDOM 1993 322548.49210000003 +UNITED KINGDOM 1992 67747.88279999999 +UNITED STATES 1998 3957.0431999999996 +UNITED STATES 1997 94729.5704 +UNITED STATES 1996 79297.85670000002 +UNITED STATES 1995 62201.23360000001 +UNITED STATES 1994 43075.629899999985 +UNITED STATES 1993 27168.486199999996 +UNITED STATES 1992 34092.366 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +EXPLAIN select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const 1 +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE part eq_ref PRIMARY,i_p_retailprice PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +o_orderkey p_partkey +5895 200 +set optimizer_switch=@save_optimizer_switch; +DROP DATABASE dbt3_s001; +use test; +set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result new file mode 100644 index 00000000000..005e4c4828e --- /dev/null +++ b/mysql-test/r/stat_tables_innodb.result @@ -0,0 +1,231 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; +set optimizer_use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +select * from mysql.table_stat; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1 +dbt3_s001 customer i_c_nationkey 1 6 +dbt3_s001 lineitem PRIMARY 1 4.003333333333333 +dbt3_s001 lineitem PRIMARY 2 1 +dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 +dbt3_s001 lineitem i_l_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey 1 600.5 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 +dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 +dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 +dbt3_s001 nation PRIMARY 1 1 +dbt3_s001 nation i_n_regionkey 1 5 +dbt3_s001 orders PRIMARY 1 1 +dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 +dbt3_s001 orders i_o_custkey 1 15 +dbt3_s001 part PRIMARY 1 1 +dbt3_s001 part i_p_retailprice 1 1 +dbt3_s001 partsupp PRIMARY 1 3.5 +dbt3_s001 partsupp PRIMARY 2 1 +dbt3_s001 partsupp i_ps_partkey 1 3.5 +dbt3_s001 partsupp i_ps_suppkey 1 70 +dbt3_s001 region PRIMARY 1 1 +dbt3_s001 supplier PRIMARY 1 1 +dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 211 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.customer.c_nationkey 1 Using index +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +EXPLAIN select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +o_year mkt_share +1995 0.4495521838895718 +1996 0.024585468215352495 +EXPLAIN select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE supplier index PRIMARY,i_s_nationkey i_s_nationkey 5 NULL 10 Using where; Using index; Using temporary; Using filesort +1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8 +1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 +select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +nation o_year sum_profit +ARGENTINA 1997 18247.873399999993 +ARGENTINA 1996 7731.089399999995 +ARGENTINA 1995 134490.5697 +ARGENTINA 1994 36767.101500000004 +ARGENTINA 1993 35857.08 +ARGENTINA 1992 35740 +ETHIOPIA 1998 2758.7801999999992 +ETHIOPIA 1997 19419.294599999997 +ETHIOPIA 1995 51231.87439999999 +ETHIOPIA 1994 3578.9478999999974 +ETHIOPIA 1992 1525.8234999999986 +IRAN 1998 37817.229600000006 +IRAN 1997 52643.77359999999 +IRAN 1996 70143.7761 +IRAN 1995 84094.58260000001 +IRAN 1994 18140.925599999995 +IRAN 1993 78655.1676 +IRAN 1992 87142.23960000002 +IRAQ 1998 22860.8082 +IRAQ 1997 93676.24359999999 +IRAQ 1996 45103.3242 +IRAQ 1994 36010.728599999995 +IRAQ 1993 33221.9399 +IRAQ 1992 47755.05900000001 +KENYA 1998 44194.831999999995 +KENYA 1997 57578.36259999999 +KENYA 1996 59195.90210000001 +KENYA 1995 79262.6278 +KENYA 1994 102360.66609999999 +KENYA 1993 128422.0196 +KENYA 1992 181517.2089 +MOROCCO 1998 41797.823199999984 +MOROCCO 1997 23685.801799999994 +MOROCCO 1996 62115.19579999998 +MOROCCO 1995 42442.64300000001 +MOROCCO 1994 48655.878000000004 +MOROCCO 1993 22926.744400000003 +MOROCCO 1992 32239.8088 +PERU 1998 86999.36459999997 +PERU 1997 121110.41070000001 +PERU 1996 177040.40759999995 +PERU 1995 122247.94520000002 +PERU 1994 88046.25329999998 +PERU 1993 49379.813799999996 +PERU 1992 80646.86050000001 +UNITED KINGDOM 1998 50577.25560000001 +UNITED KINGDOM 1997 114288.8605 +UNITED KINGDOM 1996 147684.46480000002 +UNITED KINGDOM 1995 225267.65759999998 +UNITED KINGDOM 1994 140595.5864 +UNITED KINGDOM 1993 322548.49210000003 +UNITED KINGDOM 1992 67747.88279999999 +UNITED STATES 1998 3957.0431999999996 +UNITED STATES 1997 94729.5704 +UNITED STATES 1996 79297.85670000002 +UNITED STATES 1995 62201.23360000001 +UNITED STATES 1994 43075.629899999985 +UNITED STATES 1993 27168.486199999996 +UNITED STATES 1992 34092.366 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +EXPLAIN select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE part range PRIMARY,i_p_retailprice i_p_retailprice 9 NULL 1 Using where; Using index +1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const 1 Using index +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity i_l_partkey 9 dbt3_s001.part.p_partkey,dbt3_s001.orders.o_orderkey 1 Using index +select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +o_orderkey p_partkey +5895 200 +set optimizer_switch=@save_optimizer_switch; +DROP DATABASE dbt3_s001; +use test; +set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test new file mode 100644 index 00000000000..cd896abebe1 --- /dev/null +++ b/mysql-test/t/stat_tables.test @@ -0,0 +1,108 @@ + +set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; + +set optimizer_use_stat_tables='preferably'; + +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc +create index i_p_retailprice on part(p_retailprice); +ANALYZE TABLE +customer, lineitem, nation, orders, part, partsupp, region, supplier; +FLUSH TABLES customer, lineitem, nation, orders, part, partsupp, region, supplier; +--enable_warnings +--enable_result_log +--enable_query_log + +select * from mysql.table_stat; +select * from mysql.index_stat; + + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; + +let $Q5= +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey + and l_suppkey = s_suppkey and c_nationkey = s_nationkey + and s_nationkey = n_nationkey and n_regionkey = r_regionkey + and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; + +eval EXPLAIN $Q5; +eval $Q5; + +set optimizer_switch=@save_optimizer_switch; + + +let $Q8= +select o_year, + sum(case when nation = 'UNITED STATES' then volume else 0 end) / + sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, + l_extendedprice * (1-l_discount) as volume, + n2.n_name as nation + from part, supplier, lineitem, orders, customer, + nation n1, nation n2, region + where p_partkey = l_partkey and s_suppkey = l_suppkey + and l_orderkey = o_orderkey and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey + and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; + +eval EXPLAIN $Q8; +eval $Q8; + + +let $Q9= +select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from part, supplier, lineitem, partsupp, orders, nation + where s_suppkey = l_suppkey and ps_suppkey = l_suppkey + and ps_partkey = l_partkey and p_partkey = l_partkey + and o_orderkey = l_orderkey and s_nationkey = n_nationkey + and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; + +eval EXPLAIN $Q9; +eval $Q9; + + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; + +let $QQ1= +select o_orderkey, p_partkey + from part, lineitem, orders + where p_retailprice > 1100 and o_orderdate='1997-01-01' + and o_orderkey=l_orderkey and p_partkey=l_partkey; + +eval EXPLAIN $QQ1; +eval $QQ1; + +set optimizer_switch=@save_optimizer_switch; + + +DROP DATABASE dbt3_s001; + +use test; + +set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; diff --git a/mysql-test/t/stat_tables_innodb.test b/mysql-test/t/stat_tables_innodb.test new file mode 100644 index 00000000000..e2ed647f49f --- /dev/null +++ b/mysql-test/t/stat_tables_innodb.test @@ -0,0 +1,7 @@ +--source include/have_innodb.inc + +SET SESSION STORAGE_ENGINE='InnoDB'; + +--source stat_tables.test + +SET SESSION STORAGE_ENGINE=DEFAULT; -- cgit v1.2.1 From 906c9a93a0da7df1e27d776d561c84c48ce7ee6d Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sun, 6 May 2012 22:42:14 -0700 Subject: Supported extended keys when collecting and using persistent statistics. --- mysql-test/r/stat_tables.result | 75 +++++++++++++++++++++++++ mysql-test/r/stat_tables_innodb.result | 100 +++++++++++++++++++++++++++++++++ mysql-test/t/stat_tables.test | 31 +++++++++- mysql-test/t/stat_tables_innodb.test | 5 ++ 4 files changed, 210 insertions(+), 1 deletion(-) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 089c7871506..08fb5ee825e 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -3,6 +3,81 @@ set optimizer_use_stat_tables='preferably'; DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stat; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1 +dbt3_s001 customer i_c_nationkey 1 6 +dbt3_s001 lineitem PRIMARY 1 4.003333333333333 +dbt3_s001 lineitem PRIMARY 2 1 +dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 +dbt3_s001 lineitem i_l_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey 1 600.5 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 +dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 +dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 +dbt3_s001 nation PRIMARY 1 1 +dbt3_s001 nation i_n_regionkey 1 5 +dbt3_s001 orders PRIMARY 1 1 +dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 +dbt3_s001 orders i_o_custkey 1 15 +dbt3_s001 part PRIMARY 1 1 +dbt3_s001 part i_p_retailprice 1 1 +dbt3_s001 partsupp PRIMARY 1 3.5 +dbt3_s001 partsupp PRIMARY 2 1 +dbt3_s001 partsupp i_ps_partkey 1 3.5 +dbt3_s001 partsupp i_ps_suppkey 1 70 +dbt3_s001 region PRIMARY 1 1 +dbt3_s001 supplier PRIMARY 1 1 +dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +set optimizer_switch=@save_optimizer_switch; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 179 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +delete from mysql.index_stat; select * from mysql.table_stat; db_name table_name cardinality dbt3_s001 customer 150 diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 005e4c4828e..99e3a2ab083 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -1,9 +1,86 @@ SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; set optimizer_use_stat_tables='preferably'; DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stat; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1 +dbt3_s001 customer i_c_nationkey 1 6 +dbt3_s001 lineitem PRIMARY 1 4.003333333333333 +dbt3_s001 lineitem PRIMARY 2 1 +dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 +dbt3_s001 lineitem i_l_partkey 1 30.025 +dbt3_s001 lineitem i_l_suppkey 1 600.5 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 +dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 +dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 +dbt3_s001 nation PRIMARY 1 1 +dbt3_s001 nation i_n_regionkey 1 5 +dbt3_s001 orders PRIMARY 1 1 +dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 +dbt3_s001 orders i_o_custkey 1 15 +dbt3_s001 part PRIMARY 1 1 +dbt3_s001 part i_p_retailprice 1 1 +dbt3_s001 partsupp PRIMARY 1 3.5 +dbt3_s001 partsupp PRIMARY 2 1 +dbt3_s001 partsupp i_ps_partkey 1 3.5 +dbt3_s001 partsupp i_ps_suppkey 1 70 +dbt3_s001 region PRIMARY 1 1 +dbt3_s001 supplier PRIMARY 1 1 +dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +set optimizer_switch=@save_optimizer_switch; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 211 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.customer.c_nationkey 1 Using index +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +delete from mysql.index_stat; select * from mysql.table_stat; db_name table_name cardinality dbt3_s001 customer 150 @@ -18,32 +95,54 @@ select * from mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency dbt3_s001 customer PRIMARY 1 1 dbt3_s001 customer i_c_nationkey 1 6 +dbt3_s001 customer i_c_nationkey 2 1 dbt3_s001 lineitem PRIMARY 1 4.003333333333333 dbt3_s001 lineitem PRIMARY 2 1 dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 +dbt3_s001 lineitem i_l_shipdate 2 1.014872401554842 +dbt3_s001 lineitem i_l_shipdate 3 1 dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030065141139135 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1 dbt3_s001 lineitem i_l_partkey 1 30.025 +dbt3_s001 lineitem i_l_partkey 2 1.008904569892473 +dbt3_s001 lineitem i_l_partkey 3 1 dbt3_s001 lineitem i_l_suppkey 1 600.5 +dbt3_s001 lineitem i_l_suppkey 2 1.207277844792923 +dbt3_s001 lineitem i_l_suppkey 3 1 dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 +dbt3_s001 lineitem i_l_receiptdate 2 1.0152155536770922 +dbt3_s001 lineitem i_l_receiptdate 3 1 dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 +dbt3_s001 lineitem i_l_orderkey 2 1 dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1 dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 +dbt3_s001 lineitem i_l_commitdate 2 1.036416983085951 +dbt3_s001 lineitem i_l_commitdate 3 1 dbt3_s001 nation PRIMARY 1 1 dbt3_s001 nation i_n_regionkey 1 5 +dbt3_s001 nation i_n_regionkey 2 1 dbt3_s001 orders PRIMARY 1 1 dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 +dbt3_s001 orders i_o_orderdate 2 1 dbt3_s001 orders i_o_custkey 1 15 +dbt3_s001 orders i_o_custkey 2 1 dbt3_s001 part PRIMARY 1 1 dbt3_s001 part i_p_retailprice 1 1 +dbt3_s001 part i_p_retailprice 2 1 dbt3_s001 partsupp PRIMARY 1 3.5 dbt3_s001 partsupp PRIMARY 2 1 dbt3_s001 partsupp i_ps_partkey 1 3.5 +dbt3_s001 partsupp i_ps_partkey 2 1 dbt3_s001 partsupp i_ps_suppkey 1 70 +dbt3_s001 partsupp i_ps_suppkey 2 1 dbt3_s001 region PRIMARY 1 1 dbt3_s001 supplier PRIMARY 1 1 dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +dbt3_s001 supplier i_s_nationkey 2 1 set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue @@ -228,4 +327,5 @@ set optimizer_switch=@save_optimizer_switch; DROP DATABASE dbt3_s001; use test; set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; +set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index cd896abebe1..aecb43fe763 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -10,15 +10,21 @@ DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; --disable_query_log --disable_result_log --disable_warnings --source include/dbt3_s001.inc create index i_p_retailprice on part(p_retailprice); +delete from mysql.table_stat; +delete from mysql.column_stat; +delete from mysql.index_stat; ANALYZE TABLE customer, lineitem, nation, orders, part, partsupp, region, supplier; -FLUSH TABLES customer, lineitem, nation, orders, part, partsupp, region, supplier; +FLUSH TABLE mysql.table_stat, mysql.index_stat; --enable_warnings --enable_result_log --enable_query_log @@ -26,6 +32,7 @@ FLUSH TABLES customer, lineitem, nation, orders, part, partsupp, region, supplie select * from mysql.table_stat; select * from mysql.index_stat; +set optimizer_switch=@save_optimizer_switch; set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; @@ -46,6 +53,28 @@ eval $Q5; set optimizer_switch=@save_optimizer_switch; +delete from mysql.index_stat; + +--disable_query_log +--disable_result_log +--disable_warnings +ANALYZE TABLE +customer, lineitem, nation, orders, part, partsupp, region, supplier; +FLUSH TABLE mysql.table_stat, mysql.index_stat; +--enable_warnings +--enable_result_log +--enable_query_log + +select * from mysql.table_stat; +select * from mysql.index_stat; + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; + +eval EXPLAIN $Q5; +eval $Q5; + +set optimizer_switch=@save_optimizer_switch; let $Q8= select o_year, diff --git a/mysql-test/t/stat_tables_innodb.test b/mysql-test/t/stat_tables_innodb.test index e2ed647f49f..04e81de8f9d 100644 --- a/mysql-test/t/stat_tables_innodb.test +++ b/mysql-test/t/stat_tables_innodb.test @@ -2,6 +2,11 @@ SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; + --source stat_tables.test +set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; + SET SESSION STORAGE_ENGINE=DEFAULT; -- cgit v1.2.1 From 2a1afc29f252fb189f6e93a2e0d3a1939f8220d5 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 8 May 2012 16:42:55 -0700 Subject: Inverted the option --skip-stat-tables for --stat-tables. Set it to 0 by default. Now only the tests that use persistent statistics tables require starting the server with --stat-tables set on. --- mysql-test/include/have_stat_tables.inc | 5 +++++ mysql-test/include/have_stat_tables.opt | 1 + mysql-test/r/mysqld--help.result | 8 ++++---- mysql-test/t/stat_tables.test | 1 + mysql-test/t/statistics.test | 1 + 5 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 mysql-test/include/have_stat_tables.inc create mode 100644 mysql-test/include/have_stat_tables.opt (limited to 'mysql-test') diff --git a/mysql-test/include/have_stat_tables.inc b/mysql-test/include/have_stat_tables.inc new file mode 100644 index 00000000000..97d0e44e39e --- /dev/null +++ b/mysql-test/include/have_stat_tables.inc @@ -0,0 +1,5 @@ +if (`select count(*) < 3 from information_schema.tables + where table_schema = 'mysql' and table_name in ('table_stat','column_stat','index_stat')`) +{ + --skip Needs stat tables +} diff --git a/mysql-test/include/have_stat_tables.opt b/mysql-test/include/have_stat_tables.opt new file mode 100644 index 00000000000..eb8f2d54ff6 --- /dev/null +++ b/mysql-test/include/have_stat_tables.opt @@ -0,0 +1 @@ +--stat-tables diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result index 6b8ff4e5471..83fb6b566e2 100644 --- a/mysql-test/r/mysqld--help.result +++ b/mysql-test/r/mysqld--help.result @@ -720,9 +720,6 @@ The following options may be given as the first argument: --skip-show-database Don't allow 'SHOW DATABASE' commands --skip-slave-start If set, slave is not autostarted. - --skip-stat-tables Start without statistical tables. Statistical data on - table cardinalities, columns and indexes from these - tables become unavailable --skip-thread-priority Don't give threads different priorities. This option is deprecated because it has no effect; the implied behavior @@ -781,6 +778,9 @@ The following options may be given as the first argument: for the complete list of valid sql modes --stack-trace Print a symbolic stack trace on failure (Defaults to on; use --skip-stack-trace to disable.) + --stat-tables Start with statistical tables. Statistical data on table + cardinalities, columns and indexes from these tables + become available --stored-program-cache=# The soft upper limit for number of cached stored routines for one connection. @@ -1057,7 +1057,6 @@ skip-name-resolve FALSE skip-networking FALSE skip-show-database FALSE skip-slave-start FALSE -skip-stat-tables TRUE slave-compressed-protocol FALSE slave-exec-mode STRICT slave-net-timeout 3600 @@ -1070,6 +1069,7 @@ slow-query-log FALSE sort-buffer-size 2097152 sql-mode stack-trace TRUE +stat-tables FALSE stored-program-cache 256 symbolic-links FALSE sync-binlog 0 diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index aecb43fe763..47ec0696552 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -1,3 +1,4 @@ +--source include/have_stat_tables.inc set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 81108c9846d..7d1b207689c 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -1,3 +1,4 @@ +--source include/have_stat_tables.inc --source include/have_innodb.inc --disable_warnings drop table if exists t1,t2; -- cgit v1.2.1 From 9b79feba56d8b0f955447afddbc4ab8b1d4d33c1 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 17 May 2012 16:54:26 -0700 Subject: Fixed the bug that caused displaying incorrect values in the column cardinality of the table information_schema.statistics. --- mysql-test/r/stat_tables.result | 35 ++++++++++++++++++++++++++++++++ mysql-test/r/stat_tables_innodb.result | 37 ++++++++++++++++++++++++++++++++++ mysql-test/t/stat_tables.test | 14 +++++++++++++ 3 files changed, 86 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 08fb5ee825e..df2c61498de 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -118,6 +118,41 @@ dbt3_s001 partsupp i_ps_suppkey 1 70 dbt3_s001 region PRIMARY 1 1 dbt3_s001 supplier PRIMARY 1 1 dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +select * from mysql.table_stat where table_name='orders'; +db_name table_name cardinality +dbt3_s001 orders 1500 +select * from mysql.index_stat where table_name='orders'; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 orders PRIMARY 1 1 +dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 +dbt3_s001 orders i_o_custkey 1 15 +select (select cardinality from mysql.table_stat where table_name='orders') / +(select avg_frequency from mysql.index_stat +where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct; +n_distinct +1126 +select count(distinct o_orderdate) from orders; +count(distinct o_orderdate) +1126 +select (select cardinality from mysql.table_stat where table_name='orders') / +(select avg_frequency from mysql.index_stat +where index_name='i_o_custkey' and prefix_arity=1) as n_distinct; +n_distinct +100 +select count(distinct o_custkey) from orders; +count(distinct o_custkey) +100 +show index from orders; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE +orders 1 i_o_orderdate 1 o_orderDATE A 1127 NULL NULL YES BTREE +orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE +select index_name, column_name, cardinality from information_schema.statistics +where table_name='orders'; +index_name column_name cardinality +PRIMARY o_orderkey 1500 +i_o_orderdate o_orderDATE 1127 +i_o_custkey o_custkey 100 set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 99e3a2ab083..e59aaf1fc66 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -143,6 +143,43 @@ dbt3_s001 region PRIMARY 1 1 dbt3_s001 supplier PRIMARY 1 1 dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 dbt3_s001 supplier i_s_nationkey 2 1 +select * from mysql.table_stat where table_name='orders'; +db_name table_name cardinality +dbt3_s001 orders 1500 +select * from mysql.index_stat where table_name='orders'; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 orders PRIMARY 1 1 +dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 +dbt3_s001 orders i_o_orderdate 2 1 +dbt3_s001 orders i_o_custkey 1 15 +dbt3_s001 orders i_o_custkey 2 1 +select (select cardinality from mysql.table_stat where table_name='orders') / +(select avg_frequency from mysql.index_stat +where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct; +n_distinct +1126 +select count(distinct o_orderdate) from orders; +count(distinct o_orderdate) +1126 +select (select cardinality from mysql.table_stat where table_name='orders') / +(select avg_frequency from mysql.index_stat +where index_name='i_o_custkey' and prefix_arity=1) as n_distinct; +n_distinct +100 +select count(distinct o_custkey) from orders; +count(distinct o_custkey) +100 +show index from orders; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE +orders 1 i_o_orderdate 1 o_orderDATE A 1127 NULL NULL YES BTREE +orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE +select index_name, column_name, cardinality from information_schema.statistics +where table_name='orders'; +index_name column_name cardinality +PRIMARY o_orderkey 1500 +i_o_orderdate o_orderDATE 1127 +i_o_custkey o_custkey 100 set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index 47ec0696552..d85c93b6732 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -69,6 +69,20 @@ FLUSH TABLE mysql.table_stat, mysql.index_stat; select * from mysql.table_stat; select * from mysql.index_stat; +select * from mysql.table_stat where table_name='orders'; +select * from mysql.index_stat where table_name='orders'; +select (select cardinality from mysql.table_stat where table_name='orders') / + (select avg_frequency from mysql.index_stat + where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct; +select count(distinct o_orderdate) from orders; +select (select cardinality from mysql.table_stat where table_name='orders') / + (select avg_frequency from mysql.index_stat + where index_name='i_o_custkey' and prefix_arity=1) as n_distinct; +select count(distinct o_custkey) from orders; +show index from orders; +select index_name, column_name, cardinality from information_schema.statistics + where table_name='orders'; + set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; -- cgit v1.2.1 From 055477ae522b805d3b2e890af9fe520cc1e3290d Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 22 May 2012 20:55:07 -0700 Subject: Support of the extended syntax for ANALYZE. --- mysql-test/r/statistics.result | 59 ++++++++++++++++++++++++++++++++++++++++++ mysql-test/t/statistics.test | 24 +++++++++++++++++ 2 files changed, 83 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index 3a83f9ba66c..e4d6954c745 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -219,6 +219,65 @@ WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 3'; ARITY 1 ARITY 2 ARITY 3 6.2000 1.6875 1.1304 +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(); +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM table_stat; +db_name table_name cardinality +test t1 40 +SELECT * FROM column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +SELECT * FROM index_stat; +db_name table_name index_name prefix_arity avg_frequency +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4); +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM table_stat; +db_name table_name cardinality +test t1 40 +SELECT * FROM column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +SELECT * FROM index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM table_stat; +db_name table_name cardinality +test t1 40 +SELECT * FROM column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 CREATE TABLE t2 LIKE t1; ALTER TABLE t2 ENGINE=InnoDB; INSERT INTO t2 SELECT * FROM t1; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 7d1b207689c..e6764bb5744 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -181,6 +181,30 @@ SELECT WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 3'; +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; + +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(); +SELECT * FROM table_stat; +SELECT * FROM column_stat; +SELECT * FROM index_stat; + +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4); +SELECT * FROM table_stat; +SELECT * FROM column_stat; +SELECT * FROM index_stat; + +DELETE FROM mysql.table_stat; +DELETE FROM mysql.column_stat; +DELETE FROM mysql.index_stat; + +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL; + +SELECT * FROM table_stat; +SELECT * FROM column_stat; +SELECT * FROM index_stat; + CREATE TABLE t2 LIKE t1; ALTER TABLE t2 ENGINE=InnoDB; -- cgit v1.2.1 From f549f495f7f621d2c7e35303ab84392ec519ecb0 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 2 Jun 2012 17:19:01 -0700 Subject: Removed the server option --stat-tables. Renamed the system variable optimizer_use_stat_tables to use_stat_tables. This variable now has only 3 possible values: 'never', 'complementary', 'preferably'. If the server has been launched with --use-stat-tables='complementary'|'preferably' then the statictics tables can be employed by the optimizer and by the ANALYZE command. --- mysql-test/include/have_stat_tables.opt | 2 +- mysql-test/r/mysqld--help.result | 12 +-- mysql-test/r/stat_tables.result | 6 +- mysql-test/r/stat_tables_innodb.result | 6 +- mysql-test/r/statistics.result | 14 +-- .../r/optimizer_use_stat_tables_basic.result | 116 --------------------- .../suite/sys_vars/r/use_stat_tables_basic.result | 95 +++++++++++++++++ .../t/optimizer_use_stat_tables_basic.test | 112 -------------------- .../suite/sys_vars/t/use_stat_tables_basic.test | 100 ++++++++++++++++++ mysql-test/t/stat_tables.test | 6 +- mysql-test/t/statistics.test | 14 +-- 11 files changed, 223 insertions(+), 260 deletions(-) delete mode 100644 mysql-test/suite/sys_vars/r/optimizer_use_stat_tables_basic.result create mode 100644 mysql-test/suite/sys_vars/r/use_stat_tables_basic.result delete mode 100644 mysql-test/suite/sys_vars/t/optimizer_use_stat_tables_basic.test create mode 100644 mysql-test/suite/sys_vars/t/use_stat_tables_basic.test (limited to 'mysql-test') diff --git a/mysql-test/include/have_stat_tables.opt b/mysql-test/include/have_stat_tables.opt index eb8f2d54ff6..addda71619d 100644 --- a/mysql-test/include/have_stat_tables.opt +++ b/mysql-test/include/have_stat_tables.opt @@ -1 +1 @@ ---stat-tables +--use-stat-tables='complementary' diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result index 83fb6b566e2..7f4f220f698 100644 --- a/mysql-test/r/mysqld--help.result +++ b/mysql-test/r/mysqld--help.result @@ -493,9 +493,6 @@ The following options may be given as the first argument: partial_match_table_scan, semijoin, semijoin_with_cache, subquery_cache, table_elimination, extended_keys } and val is one of {on, off, default} - --optimizer-use-stat-tables=name - Specifies how to use system statistics tables. Possible - values are NEVER, COMPLEMENTARY, PREVERABLY, EXCLUSIVELY --performance-schema Enable the performance schema. --performance-schema-events-waits-history-long-size=# @@ -778,9 +775,6 @@ The following options may be given as the first argument: for the complete list of valid sql modes --stack-trace Print a symbolic stack trace on failure (Defaults to on; use --skip-stack-trace to disable.) - --stat-tables Start with statistical tables. Statistical data on table - cardinalities, columns and indexes from these tables - become available --stored-program-cache=# The soft upper limit for number of cached stored routines for one connection. @@ -838,6 +832,9 @@ The following options may be given as the first argument: Prohibit update of a VIEW, which does not contain a key of the underlying table and the query uses a LIMIT clause (usually get from GUI tools) + --use-stat-tables=name + Specifies how to use system statistics tables. Possible + values are NEVER, COMPLEMENTARY, PREVERABLY -u, --user=name Run mysqld daemon as user. --userstat Enables statistics gathering for USER_STATISTICS, CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS @@ -996,7 +993,6 @@ old-style-user-limits FALSE optimizer-prune-level 1 optimizer-search-depth 62 optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on -optimizer-use-stat-tables NEVER performance-schema FALSE performance-schema-events-waits-history-long-size 10000 performance-schema-events-waits-history-size 10 @@ -1069,7 +1065,6 @@ slow-query-log FALSE sort-buffer-size 2097152 sql-mode stack-trace TRUE -stat-tables FALSE stored-program-cache 256 symbolic-links FALSE sync-binlog 0 @@ -1091,6 +1086,7 @@ transaction-alloc-block-size 8192 transaction-isolation REPEATABLE-READ transaction-prealloc-size 4096 updatable-views-with-limit YES +use-stat-tables NEVER userstat FALSE verbose TRUE wait-timeout 28800 diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index df2c61498de..e52efc97c50 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -1,5 +1,5 @@ -set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; -set optimizer_use_stat_tables='preferably'; +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; @@ -336,4 +336,4 @@ o_orderkey p_partkey set optimizer_switch=@save_optimizer_switch; DROP DATABASE dbt3_s001; use test; -set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index e59aaf1fc66..90361099ca2 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -1,8 +1,8 @@ SET SESSION STORAGE_ENGINE='InnoDB'; set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; set optimizer_switch='extended_keys=on'; -set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; -set optimizer_use_stat_tables='preferably'; +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; @@ -363,6 +363,6 @@ o_orderkey p_partkey set optimizer_switch=@save_optimizer_switch; DROP DATABASE dbt3_s001; use test; -set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; +set use_stat_tables=@save_use_stat_tables; set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index e4d6954c745..4e1a5a6733c 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -1,5 +1,5 @@ drop table if exists t1,t2; -set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; +set @save_use_stat_tables=@@use_stat_tables; CREATE VIEW table_stat AS SELECT * FROM mysql.table_stat; CREATE VIEW column_stat AS @@ -16,7 +16,7 @@ CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; -set optimizer_use_stat_tables='preferably'; +set use_stat_tables='preferably'; CREATE TABLE t1 ( a int NOT NULL PRIMARY KEY, b varchar(32), @@ -358,7 +358,7 @@ DROP TABLE t1,t2; DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; -set optimizer_use_stat_tables='never'; +set use_stat_tables='never'; set names utf8; CREATE DATABASE world; use world; @@ -387,7 +387,7 @@ Percentage float(3,1) NOT NULL default '0.0', PRIMARY KEY (Country, Language), INDEX (Percentage) ) CHARACTER SET utf8 COLLATE utf8_bin; -set optimizer_use_stat_tables='preferably'; +set use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; SELECT UPPER(db_name), UPPER(table_name), cardinality FROM test.table_stat; @@ -424,7 +424,7 @@ WORLD COUNTRYLANGUAGE PRIMARY 1 4.2232 WORLD COUNTRYLANGUAGE PRIMARY 2 1.0000 WORLD COUNTRYLANGUAGE Percentage 1 2.7640 use test; -set optimizer_use_stat_tables='never'; +set use_stat_tables='never'; CREATE DATABASE world_innodb; use world_innodb; CREATE TABLE Country ( @@ -455,7 +455,7 @@ INDEX (Percentage) ALTER TABLE Country ENGINE=InnoDB; ALTER TABLE City ENGINE=InnoDB; ALTER TABLE CountryLanguage ENGINE=InnoDB; -set optimizer_use_stat_tables='preferably'; +set use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; SELECT UPPER(db_name), UPPER(table_name), cardinality FROM test.table_stat; @@ -523,4 +523,4 @@ DELETE FROM mysql.index_stat; DROP VIEW test.table_stat; DROP VIEW test.column_stat; DROP VIEW test.index_stat; -set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/suite/sys_vars/r/optimizer_use_stat_tables_basic.result b/mysql-test/suite/sys_vars/r/optimizer_use_stat_tables_basic.result deleted file mode 100644 index 22c6859af62..00000000000 --- a/mysql-test/suite/sys_vars/r/optimizer_use_stat_tables_basic.result +++ /dev/null @@ -1,116 +0,0 @@ -SET @start_global_value = @@global.optimizer_use_stat_tables; -SELECT @start_global_value; -@start_global_value -NEVER -SET @start_session_value = @@session.optimizer_use_stat_tables; -SELECT @start_session_value; -@start_session_value -NEVER -SET @@global.optimizer_use_stat_tables = 2; -SET @@global.optimizer_use_stat_tables = DEFAULT; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -NEVER -SET @@session.optimizer_use_stat_tables = 3; -SET @@session.optimizer_use_stat_tables = DEFAULT; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -NEVER -SET @@global.optimizer_use_stat_tables = 0; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -NEVER -SET @@global.optimizer_use_stat_tables = 1; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -COMPLEMENTARY -SET @@global.optimizer_use_stat_tables = 2; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -PREFERABLY -SET @@global.optimizer_use_stat_tables = 3; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -EXCLUSIVELY -SET @@global.optimizer_use_stat_tables = NEVER; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -NEVER -SET @@global.optimizer_use_stat_tables = COMPLEMENTARY; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -COMPLEMENTARY -SET @@global.optimizer_use_stat_tables = PREFERABLY; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -PREFERABLY -SET @@global.optimizer_use_stat_tables = EXCLUSIVELY; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -EXCLUSIVELY -SET @@session.optimizer_use_stat_tables = 0; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -NEVER -SET @@session.optimizer_use_stat_tables = 1; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -COMPLEMENTARY -SET @@session.optimizer_use_stat_tables = 2; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -PREFERABLY -SET @@session.optimizer_use_stat_tables = 3; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -EXCLUSIVELY -SET @@session.optimizer_use_stat_tables = NEVER; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -NEVER -SET @@session.optimizer_use_stat_tables = PREFERABLY; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -PREFERABLY -SET @@session.optimizer_use_stat_tables = EXCLUSIVELY; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -EXCLUSIVELY -SET @@session.optimizer_use_stat_tables = COMPLEMENTARY; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -COMPLEMENTARY -set sql_mode=TRADITIONAL; -SET @@global.optimizer_use_stat_tables = 10; -ERROR 42000: Variable 'optimizer_use_stat_tables' can't be set to the value of '10' -SET @@global.optimizer_use_stat_tables = -1024; -ERROR 42000: Variable 'optimizer_use_stat_tables' can't be set to the value of '-1024' -SET @@global.optimizer_use_stat_tables = 2.4; -ERROR 42000: Incorrect argument type to variable 'optimizer_use_stat_tables' -SET @@global.optimizer_use_stat_tables = OFF; -ERROR 42000: Variable 'optimizer_use_stat_tables' can't be set to the value of 'OFF' -SET @@session.optimizer_use_stat_tables = 10; -ERROR 42000: Variable 'optimizer_use_stat_tables' can't be set to the value of '10' -SET @@session.optimizer_use_stat_tables = -2; -ERROR 42000: Variable 'optimizer_use_stat_tables' can't be set to the value of '-2' -SET @@session.optimizer_use_stat_tables = 1.2; -ERROR 42000: Incorrect argument type to variable 'optimizer_use_stat_tables' -SET @@session.optimizer_use_stat_tables = ON; -ERROR 42000: Variable 'optimizer_use_stat_tables' can't be set to the value of 'ON' -SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME='optimizer_use_stat_tables'; -VARIABLE_NAME VARIABLE_VALUE -OPTIMIZER_USE_STAT_TABLES EXCLUSIVELY -SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES -WHERE VARIABLE_NAME='optimizer_use_stat_tables'; -VARIABLE_NAME VARIABLE_VALUE -OPTIMIZER_USE_STAT_TABLES COMPLEMENTARY -SET @@global.optimizer_use_stat_tables = @start_global_value; -SELECT @@global.optimizer_use_stat_tables; -@@global.optimizer_use_stat_tables -NEVER -SET @@session.optimizer_use_stat_tables = @start_session_value; -SELECT @@session.optimizer_use_stat_tables; -@@session.optimizer_use_stat_tables -NEVER -set sql_mode=''; diff --git a/mysql-test/suite/sys_vars/r/use_stat_tables_basic.result b/mysql-test/suite/sys_vars/r/use_stat_tables_basic.result new file mode 100644 index 00000000000..64f6d868fa6 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/use_stat_tables_basic.result @@ -0,0 +1,95 @@ +SET @start_global_value = @@global.use_stat_tables; +SELECT @start_global_value; +@start_global_value +NEVER +SET @start_session_value = @@session.use_stat_tables; +SELECT @start_session_value; +@start_session_value +NEVER +SET @@global.use_stat_tables = 2; +SET @@global.use_stat_tables = DEFAULT; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +NEVER +SET @@global.use_stat_tables = 0; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +NEVER +SET @@global.use_stat_tables = 1; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +SET @@global.use_stat_tables = 2; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +PREFERABLY +SET @@global.use_stat_tables = NEVER; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +NEVER +SET @@global.use_stat_tables = COMPLEMENTARY; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +SET @@global.use_stat_tables = PREFERABLY; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +PREFERABLY +SET @@session.use_stat_tables = 0; +SELECT @@session.use_stat_tables; +@@session.use_stat_tables +NEVER +SET @@session.use_stat_tables = 1; +SELECT @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +SET @@session.use_stat_tables = 2; +SELECT @@session.use_stat_tables; +@@session.use_stat_tables +PREFERABLY +SET @@session.use_stat_tables = NEVER; +SELECT @@session.use_stat_tables; +@@session.use_stat_tables +NEVER +SET @@session.use_stat_tables = PREFERABLY; +SELECT @@session.use_stat_tables; +@@session.use_stat_tables +PREFERABLY +SET @@session.use_stat_tables = COMPLEMENTARY; +SELECT @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +set sql_mode=TRADITIONAL; +SET @@global.use_stat_tables = 10; +ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '10' +SET @@global.use_stat_tables = -1024; +ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '-1024' +SET @@global.use_stat_tables = 2.4; +ERROR 42000: Incorrect argument type to variable 'use_stat_tables' +SET @@global.use_stat_tables = OFF; +ERROR 42000: Variable 'use_stat_tables' can't be set to the value of 'OFF' +SET @@session.use_stat_tables = 10; +ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '10' +SET @@session.use_stat_tables = -2; +ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '-2' +SET @@session.use_stat_tables = 1.2; +ERROR 42000: Incorrect argument type to variable 'use_stat_tables' +SET @@session.use_stat_tables = ON; +ERROR 42000: Variable 'use_stat_tables' can't be set to the value of 'ON' +SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='use_stat_tables'; +VARIABLE_NAME VARIABLE_VALUE +USE_STAT_TABLES PREFERABLY +SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='use_stat_tables'; +VARIABLE_NAME VARIABLE_VALUE +USE_STAT_TABLES COMPLEMENTARY +SET @@global.use_stat_tables = @start_global_value; +SELECT @@global.use_stat_tables; +@@global.use_stat_tables +NEVER +SET @@session.use_stat_tables = @start_session_value; +SELECT @@session.use_stat_tables; +@@session.use_stat_tables +NEVER +set sql_mode=''; diff --git a/mysql-test/suite/sys_vars/t/optimizer_use_stat_tables_basic.test b/mysql-test/suite/sys_vars/t/optimizer_use_stat_tables_basic.test deleted file mode 100644 index 6e0a96c403e..00000000000 --- a/mysql-test/suite/sys_vars/t/optimizer_use_stat_tables_basic.test +++ /dev/null @@ -1,112 +0,0 @@ ---source include/load_sysvars.inc - -############################################################# -# Save initial value # -############################################################# - -SET @start_global_value = @@global.optimizer_use_stat_tables; -SELECT @start_global_value; -SET @start_session_value = @@session.optimizer_use_stat_tables; -SELECT @start_session_value; - -############################################################### -# Display the DEFAULT value of optimizer_use_stat_tables # -############################################################### - -SET @@global.optimizer_use_stat_tables = 2; -SET @@global.optimizer_use_stat_tables = DEFAULT; -SELECT @@global.optimizer_use_stat_tables; - -SET @@session.optimizer_use_stat_tables = 3; -SET @@session.optimizer_use_stat_tables = DEFAULT; -SELECT @@session.optimizer_use_stat_tables; - - -################################################################################## -# Change the value ofoptimizer_use_stat_tables to a valid value for GLOBAL Scope # -################################################################################## - -SET @@global.optimizer_use_stat_tables = 0; -SELECT @@global.optimizer_use_stat_tables; -SET @@global.optimizer_use_stat_tables = 1; -SELECT @@global.optimizer_use_stat_tables; -SET @@global.optimizer_use_stat_tables = 2; -SELECT @@global.optimizer_use_stat_tables; -SET @@global.optimizer_use_stat_tables = 3; -SELECT @@global.optimizer_use_stat_tables; - -SET @@global.optimizer_use_stat_tables = NEVER; -SELECT @@global.optimizer_use_stat_tables; -SET @@global.optimizer_use_stat_tables = COMPLEMENTARY; -SELECT @@global.optimizer_use_stat_tables; -SET @@global.optimizer_use_stat_tables = PREFERABLY; -SELECT @@global.optimizer_use_stat_tables; -SET @@global.optimizer_use_stat_tables = EXCLUSIVELY; -SELECT @@global.optimizer_use_stat_tables; - -#################################################################################### -# Change the value of optimizer_use_stat_tables to a valid value for SESSION Scope # -#################################################################################### - -SET @@session.optimizer_use_stat_tables = 0; -SELECT @@session.optimizer_use_stat_tables; -SET @@session.optimizer_use_stat_tables = 1; -SELECT @@session.optimizer_use_stat_tables; -SET @@session.optimizer_use_stat_tables = 2; -SELECT @@session.optimizer_use_stat_tables; -SET @@session.optimizer_use_stat_tables = 3; -SELECT @@session.optimizer_use_stat_tables; - -SET @@session.optimizer_use_stat_tables = NEVER; -SELECT @@session.optimizer_use_stat_tables; -SET @@session.optimizer_use_stat_tables = PREFERABLY; -SELECT @@session.optimizer_use_stat_tables; -SET @@session.optimizer_use_stat_tables = EXCLUSIVELY; -SELECT @@session.optimizer_use_stat_tables; -SET @@session.optimizer_use_stat_tables = COMPLEMENTARY; -SELECT @@session.optimizer_use_stat_tables; - -##################################################################### -# Change the value of optimizer_use_stat_tables to an invalid value # -##################################################################### -set sql_mode=TRADITIONAL; ---Error ER_WRONG_VALUE_FOR_VAR -SET @@global.optimizer_use_stat_tables = 10; ---Error ER_WRONG_VALUE_FOR_VAR -SET @@global.optimizer_use_stat_tables = -1024; ---Error ER_WRONG_TYPE_FOR_VAR -SET @@global.optimizer_use_stat_tables = 2.4; ---Error ER_WRONG_VALUE_FOR_VAR -SET @@global.optimizer_use_stat_tables = OFF; ---Error ER_WRONG_VALUE_FOR_VAR -SET @@session.optimizer_use_stat_tables = 10; ---Error ER_WRONG_VALUE_FOR_VAR -SET @@session.optimizer_use_stat_tables = -2; ---Error ER_WRONG_TYPE_FOR_VAR -SET @@session.optimizer_use_stat_tables = 1.2; ---Error ER_WRONG_VALUE_FOR_VAR -SET @@session.optimizer_use_stat_tables = ON; - -############################################################################### -# Check if the value in GLOBAL & SESSION Tables matches value in variable # -############################################################################### - -SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES -WHERE VARIABLE_NAME='optimizer_use_stat_tables'; - -SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES -WHERE VARIABLE_NAME='optimizer_use_stat_tables'; - -#################################### -# Restore initial value # -#################################### - -SET @@global.optimizer_use_stat_tables = @start_global_value; -SELECT @@global.optimizer_use_stat_tables; -SET @@session.optimizer_use_stat_tables = @start_session_value; -SELECT @@session.optimizer_use_stat_tables; -set sql_mode=''; - -###################################################### -# END OF optimizer_use_stat_tables TESTS # -###################################################### \ No newline at end of file diff --git a/mysql-test/suite/sys_vars/t/use_stat_tables_basic.test b/mysql-test/suite/sys_vars/t/use_stat_tables_basic.test new file mode 100644 index 00000000000..7f526edf206 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/use_stat_tables_basic.test @@ -0,0 +1,100 @@ +--source include/load_sysvars.inc + +############################################################# +# Save initial value # +############################################################# + +SET @start_global_value = @@global.use_stat_tables; +SELECT @start_global_value; +SET @start_session_value = @@session.use_stat_tables; +SELECT @start_session_value; + +############################################################### +# Display the DEFAULT value of use_stat_tables # +############################################################### + +SET @@global.use_stat_tables = 2; +SET @@global.use_stat_tables = DEFAULT; +SELECT @@global.use_stat_tables; + + +################################################################################## +# Change the value of use_stat_tables to a valid value for GLOBAL Scope # +################################################################################## + +SET @@global.use_stat_tables = 0; +SELECT @@global.use_stat_tables; +SET @@global.use_stat_tables = 1; +SELECT @@global.use_stat_tables; +SET @@global.use_stat_tables = 2; +SELECT @@global.use_stat_tables; + +SET @@global.use_stat_tables = NEVER; +SELECT @@global.use_stat_tables; +SET @@global.use_stat_tables = COMPLEMENTARY; +SELECT @@global.use_stat_tables; +SET @@global.use_stat_tables = PREFERABLY; +SELECT @@global.use_stat_tables; + +#################################################################################### +# Change the value of use_stat_tables to a valid value for SESSION Scope # +#################################################################################### + +SET @@session.use_stat_tables = 0; +SELECT @@session.use_stat_tables; +SET @@session.use_stat_tables = 1; +SELECT @@session.use_stat_tables; +SET @@session.use_stat_tables = 2; +SELECT @@session.use_stat_tables; + +SET @@session.use_stat_tables = NEVER; +SELECT @@session.use_stat_tables; +SET @@session.use_stat_tables = PREFERABLY; +SELECT @@session.use_stat_tables; +SET @@session.use_stat_tables = COMPLEMENTARY; +SELECT @@session.use_stat_tables; + +##################################################################### +# Change the value of use_stat_tables to an invalid value # +##################################################################### +set sql_mode=TRADITIONAL; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@global.use_stat_tables = 10; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@global.use_stat_tables = -1024; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.use_stat_tables = 2.4; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@global.use_stat_tables = OFF; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@session.use_stat_tables = 10; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@session.use_stat_tables = -2; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@session.use_stat_tables = 1.2; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@session.use_stat_tables = ON; + +############################################################################### +# Check if the value in GLOBAL & SESSION Tables matches value in variable # +############################################################################### + +SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='use_stat_tables'; + +SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='use_stat_tables'; + +#################################### +# Restore initial value # +#################################### + +SET @@global.use_stat_tables = @start_global_value; +SELECT @@global.use_stat_tables; +SET @@session.use_stat_tables = @start_session_value; +SELECT @@session.use_stat_tables; +set sql_mode=''; + +###################################################### +# END OF use_stat_tables TESTS # +###################################################### \ No newline at end of file diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index d85c93b6732..640f9febc75 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -1,8 +1,8 @@ --source include/have_stat_tables.inc -set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; +set @save_use_stat_tables=@@use_stat_tables; -set optimizer_use_stat_tables='preferably'; +set use_stat_tables='preferably'; --disable_warnings DROP DATABASE IF EXISTS dbt3_s001; @@ -149,4 +149,4 @@ DROP DATABASE dbt3_s001; use test; -set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index e6764bb5744..e4676c7b340 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -4,7 +4,7 @@ drop table if exists t1,t2; --enable_warnings -set @save_optimizer_use_stat_tables=@@optimizer_use_stat_tables; +set @save_use_stat_tables=@@use_stat_tables; CREATE VIEW table_stat AS SELECT * FROM mysql.table_stat; @@ -26,7 +26,7 @@ DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; -set optimizer_use_stat_tables='preferably'; +set use_stat_tables='preferably'; CREATE TABLE t1 ( a int NOT NULL PRIMARY KEY, @@ -240,7 +240,7 @@ DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; -set optimizer_use_stat_tables='never'; +set use_stat_tables='never'; set names utf8; @@ -258,7 +258,7 @@ use world; --enable_result_log --enable_query_log -set optimizer_use_stat_tables='preferably'; +set use_stat_tables='preferably'; --disable_result_log ANALYZE TABLE Country, City, CountryLanguage; @@ -275,7 +275,7 @@ SELECT UPPER(db_name), UPPER(table_name), use test; -set optimizer_use_stat_tables='never'; +set use_stat_tables='never'; CREATE DATABASE world_innodb; @@ -295,7 +295,7 @@ ALTER TABLE CountryLanguage ENGINE=InnoDB; --enable_result_log --enable_query_log -set optimizer_use_stat_tables='preferably'; +set use_stat_tables='preferably'; --disable_result_log ANALYZE TABLE Country, City, CountryLanguage; @@ -323,6 +323,6 @@ DROP VIEW test.table_stat; DROP VIEW test.column_stat; DROP VIEW test.index_stat; -set optimizer_use_stat_tables=@save_optimizer_use_stat_tables; +set use_stat_tables=@save_use_stat_tables; \ No newline at end of file -- cgit v1.2.1 From 4ff6fd34dae6315384d8c38ea69092cde09b78ba Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 25 Jun 2012 22:33:07 -0700 Subject: Changed the type of all double columns in the system statistical tables mysql.column_stat, mysql.table_stat for the type DECIMAL(12,4). When cached the values from these columns are multiplied by factor 10^5 and stored as ulong numbers now. --- mysql-test/r/stat_tables.result | 126 +++++++-------- mysql-test/r/stat_tables_innodb.result | 174 ++++++++++----------- mysql-test/r/statistics.result | 80 ++++------ mysql-test/r/system_mysql_db.result | 8 +- mysql-test/suite/funcs_1/r/is_columns_mysql.result | 18 +-- mysql-test/t/statistics.test | 84 ++++------ 6 files changed, 227 insertions(+), 263 deletions(-) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index e52efc97c50..26f2b602c6b 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -17,34 +17,34 @@ dbt3_s001 region 5 dbt3_s001 supplier 10 select * from mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 customer PRIMARY 1 1 -dbt3_s001 customer i_c_nationkey 1 6 -dbt3_s001 lineitem PRIMARY 1 4.003333333333333 -dbt3_s001 lineitem PRIMARY 2 1 -dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 -dbt3_s001 lineitem i_l_partkey 1 30.025 -dbt3_s001 lineitem i_l_suppkey 1 600.5 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 -dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 -dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 -dbt3_s001 nation PRIMARY 1 1 -dbt3_s001 nation i_n_regionkey 1 5 -dbt3_s001 orders PRIMARY 1 1 -dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 -dbt3_s001 orders i_o_custkey 1 15 -dbt3_s001 part PRIMARY 1 1 -dbt3_s001 part i_p_retailprice 1 1 -dbt3_s001 partsupp PRIMARY 1 3.5 -dbt3_s001 partsupp PRIMARY 2 1 -dbt3_s001 partsupp i_ps_partkey 1 3.5 -dbt3_s001 partsupp i_ps_suppkey 1 70 -dbt3_s001 region PRIMARY 1 1 -dbt3_s001 supplier PRIMARY 1 1 -dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 set optimizer_switch=@save_optimizer_switch; set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; @@ -90,47 +90,47 @@ dbt3_s001 region 5 dbt3_s001 supplier 10 select * from mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 customer PRIMARY 1 1 -dbt3_s001 customer i_c_nationkey 1 6 -dbt3_s001 lineitem PRIMARY 1 4.003333333333333 -dbt3_s001 lineitem PRIMARY 2 1 -dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 -dbt3_s001 lineitem i_l_partkey 1 30.025 -dbt3_s001 lineitem i_l_suppkey 1 600.5 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 -dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 -dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 -dbt3_s001 nation PRIMARY 1 1 -dbt3_s001 nation i_n_regionkey 1 5 -dbt3_s001 orders PRIMARY 1 1 -dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 -dbt3_s001 orders i_o_custkey 1 15 -dbt3_s001 part PRIMARY 1 1 -dbt3_s001 part i_p_retailprice 1 1 -dbt3_s001 partsupp PRIMARY 1 3.5 -dbt3_s001 partsupp PRIMARY 2 1 -dbt3_s001 partsupp i_ps_partkey 1 3.5 -dbt3_s001 partsupp i_ps_suppkey 1 70 -dbt3_s001 region PRIMARY 1 1 -dbt3_s001 supplier PRIMARY 1 1 -dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 select * from mysql.table_stat where table_name='orders'; db_name table_name cardinality dbt3_s001 orders 1500 select * from mysql.index_stat where table_name='orders'; db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 orders PRIMARY 1 1 -dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 -dbt3_s001 orders i_o_custkey 1 15 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 select (select cardinality from mysql.table_stat where table_name='orders') / (select avg_frequency from mysql.index_stat where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct; n_distinct -1126 +1126.0416 select count(distinct o_orderdate) from orders; count(distinct o_orderdate) 1126 @@ -138,20 +138,20 @@ select (select cardinality from mysql.table_stat where table_name='orders') / (select avg_frequency from mysql.index_stat where index_name='i_o_custkey' and prefix_arity=1) as n_distinct; n_distinct -100 +100.0000 select count(distinct o_custkey) from orders; count(distinct o_custkey) 100 show index from orders; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE -orders 1 i_o_orderdate 1 o_orderDATE A 1127 NULL NULL YES BTREE +orders 1 i_o_orderdate 1 o_orderDATE A 1126 NULL NULL YES BTREE orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE select index_name, column_name, cardinality from information_schema.statistics where table_name='orders'; index_name column_name cardinality PRIMARY o_orderkey 1500 -i_o_orderdate o_orderDATE 1127 +i_o_orderdate o_orderDATE 1126 i_o_custkey o_custkey 100 set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 90361099ca2..3d534dcab29 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -20,34 +20,34 @@ dbt3_s001 region 5 dbt3_s001 supplier 10 select * from mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 customer PRIMARY 1 1 -dbt3_s001 customer i_c_nationkey 1 6 -dbt3_s001 lineitem PRIMARY 1 4.003333333333333 -dbt3_s001 lineitem PRIMARY 2 1 -dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 -dbt3_s001 lineitem i_l_partkey 1 30.025 -dbt3_s001 lineitem i_l_suppkey 1 600.5 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 -dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 -dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 -dbt3_s001 nation PRIMARY 1 1 -dbt3_s001 nation i_n_regionkey 1 5 -dbt3_s001 orders PRIMARY 1 1 -dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 -dbt3_s001 orders i_o_custkey 1 15 -dbt3_s001 part PRIMARY 1 1 -dbt3_s001 part i_p_retailprice 1 1 -dbt3_s001 partsupp PRIMARY 1 3.5 -dbt3_s001 partsupp PRIMARY 2 1 -dbt3_s001 partsupp i_ps_partkey 1 3.5 -dbt3_s001 partsupp i_ps_suppkey 1 70 -dbt3_s001 region PRIMARY 1 1 -dbt3_s001 supplier PRIMARY 1 1 -dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 set optimizer_switch=@save_optimizer_switch; set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; @@ -93,71 +93,71 @@ dbt3_s001 region 5 dbt3_s001 supplier 10 select * from mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 customer PRIMARY 1 1 -dbt3_s001 customer i_c_nationkey 1 6 -dbt3_s001 customer i_c_nationkey 2 1 -dbt3_s001 lineitem PRIMARY 1 4.003333333333333 -dbt3_s001 lineitem PRIMARY 2 1 -dbt3_s001 lineitem i_l_shipdate 1 2.650044130626655 -dbt3_s001 lineitem i_l_shipdate 2 1.014872401554842 -dbt3_s001 lineitem i_l_shipdate 3 1 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.025 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.57857142857143 -dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030065141139135 -dbt3_s001 lineitem i_l_suppkey_partkey 4 1 -dbt3_s001 lineitem i_l_partkey 1 30.025 -dbt3_s001 lineitem i_l_partkey 2 1.008904569892473 -dbt3_s001 lineitem i_l_partkey 3 1 -dbt3_s001 lineitem i_l_suppkey 1 600.5 -dbt3_s001 lineitem i_l_suppkey 2 1.207277844792923 -dbt3_s001 lineitem i_l_suppkey 3 1 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477072310405645 -dbt3_s001 lineitem i_l_receiptdate 2 1.0152155536770922 -dbt3_s001 lineitem i_l_receiptdate 3 1 -dbt3_s001 lineitem i_l_orderkey 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey 2 1 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.003333333333333 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0403672903672905 -dbt3_s001 lineitem i_l_orderkey_quantity 3 1 -dbt3_s001 lineitem i_l_commitdate 1 2.7159656264133876 -dbt3_s001 lineitem i_l_commitdate 2 1.036416983085951 -dbt3_s001 lineitem i_l_commitdate 3 1 -dbt3_s001 nation PRIMARY 1 1 -dbt3_s001 nation i_n_regionkey 1 5 -dbt3_s001 nation i_n_regionkey 2 1 -dbt3_s001 orders PRIMARY 1 1 -dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 -dbt3_s001 orders i_o_orderdate 2 1 -dbt3_s001 orders i_o_custkey 1 15 -dbt3_s001 orders i_o_custkey 2 1 -dbt3_s001 part PRIMARY 1 1 -dbt3_s001 part i_p_retailprice 1 1 -dbt3_s001 part i_p_retailprice 2 1 -dbt3_s001 partsupp PRIMARY 1 3.5 -dbt3_s001 partsupp PRIMARY 2 1 -dbt3_s001 partsupp i_ps_partkey 1 3.5 -dbt3_s001 partsupp i_ps_partkey 2 1 -dbt3_s001 partsupp i_ps_suppkey 1 70 -dbt3_s001 partsupp i_ps_suppkey 2 1 -dbt3_s001 region PRIMARY 1 1 -dbt3_s001 supplier PRIMARY 1 1 -dbt3_s001 supplier i_s_nationkey 1 1.1111111111111112 -dbt3_s001 supplier i_s_nationkey 2 1 +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 customer i_c_nationkey 2 1.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_shipdate 2 1.0149 +dbt3_s001 lineitem i_l_shipdate 3 1.0000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_partkey 2 1.0089 +dbt3_s001 lineitem i_l_partkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey 2 1.2073 +dbt3_s001 lineitem i_l_suppkey 3 1.0000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_receiptdate 2 1.0152 +dbt3_s001 lineitem i_l_receiptdate 3 1.0000 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey 2 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_commitdate 2 1.0364 +dbt3_s001 lineitem i_l_commitdate 3 1.0000 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 nation i_n_regionkey 2 1.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_orderdate 2 1.0000 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 orders i_o_custkey 2 1.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 part i_p_retailprice 2 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_partkey 2 1.0000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 partsupp i_ps_suppkey 2 1.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +dbt3_s001 supplier i_s_nationkey 2 1.0000 select * from mysql.table_stat where table_name='orders'; db_name table_name cardinality dbt3_s001 orders 1500 select * from mysql.index_stat where table_name='orders'; db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 orders PRIMARY 1 1 -dbt3_s001 orders i_o_orderdate 1 1.3321492007104796 -dbt3_s001 orders i_o_orderdate 2 1 -dbt3_s001 orders i_o_custkey 1 15 -dbt3_s001 orders i_o_custkey 2 1 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_orderdate 2 1.0000 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 orders i_o_custkey 2 1.0000 select (select cardinality from mysql.table_stat where table_name='orders') / (select avg_frequency from mysql.index_stat where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct; n_distinct -1126 +1126.0416 select count(distinct o_orderdate) from orders; count(distinct o_orderdate) 1126 @@ -165,20 +165,20 @@ select (select cardinality from mysql.table_stat where table_name='orders') / (select avg_frequency from mysql.index_stat where index_name='i_o_custkey' and prefix_arity=1) as n_distinct; n_distinct -100 +100.0000 select count(distinct o_custkey) from orders; count(distinct o_custkey) 100 show index from orders; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE -orders 1 i_o_orderdate 1 o_orderDATE A 1127 NULL NULL YES BTREE +orders 1 i_o_orderdate 1 o_orderDATE A 1126 NULL NULL YES BTREE orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE select index_name, column_name, cardinality from information_schema.statistics where table_name='orders'; index_name column_name cardinality PRIMARY o_orderkey 1500 -i_o_orderdate o_orderDATE 1127 +i_o_orderdate o_orderDATE 1126 i_o_custkey o_custkey 100 set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='index_condition_pushdown=off'; diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index 4e1a5a6733c..99d3c04312b 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -1,18 +1,5 @@ drop table if exists t1,t2; set @save_use_stat_tables=@@use_stat_tables; -CREATE VIEW table_stat AS -SELECT * FROM mysql.table_stat; -CREATE VIEW column_stat AS -SELECT db_name, table_name, column_name, -min_value, max_value, -CAST(nulls_ratio AS decimal(12,4)) AS 'nulls_ratio', -CAST(avg_length AS decimal(12,4)) AS 'avg_length', -CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' - FROM mysql.column_stat; -CREATE VIEW index_stat AS -SELECT db_name, table_name, index_name, prefix_arity, -CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' - FROM mysql.index_stat; DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; @@ -73,10 +60,10 @@ INSERT INTO t1 VALUES ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status OK -SELECT * FROM table_stat; +SELECT * FROM mysql.table_stat; db_name table_name cardinality test t1 40 -SELECT * FROM column_stat; +SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 a 0 49 0.0000 4.0000 1.0000 test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 @@ -84,7 +71,7 @@ test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 test t1 e 0.01 0.112 0.2250 8.0000 6.2000 test t1 f 1 5 0.2000 1.0000 6.4000 -SELECT * FROM index_stat; +SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 test t1 idx1 1 6.4000 @@ -98,7 +85,7 @@ test t1 idx4 3 1.1304 SELECT COUNT(*) FROM t1; COUNT(*) 40 -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='a'; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 a 0 49 0.0000 4.0000 1.0000 @@ -110,7 +97,7 @@ SELECT MIN(t1.a), MAX(t1.a), FROM t1; MIN(t1.a) MAX(t1.a) NULLS_RATIO(t1.a) AVG_FREQUENCY(t1.a) 0 49 0.2000 1.0000 -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='b'; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 @@ -122,7 +109,7 @@ SELECT MIN(t1.b), MAX(t1.b), FROM t1; MIN(t1.b) MAX(t1.b) NULLS_RATIO(t1.b) AVG_FREQUENCY(t1.b) vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='c'; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 @@ -134,7 +121,7 @@ SELECT MIN(t1.c), MAX(t1.c), FROM t1; MIN(t1.c) MAX(t1.c) NULLS_RATIO(t1.c) AVG_FREQUENCY(t1.c) aaaa dddddddd 0.1250 7.0000 -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='d'; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 @@ -146,7 +133,7 @@ SELECT MIN(t1.d), MAX(t1.d), FROM t1; MIN(t1.d) MAX(t1.d) NULLS_RATIO(t1.d) AVG_FREQUENCY(t1.d) 1989-03-12 1999-07-23 0.1500 8.5000 -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='e'; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 e 0.01 0.112 0.2250 8.0000 6.2000 @@ -158,7 +145,7 @@ SELECT MIN(t1.e), MAX(t1.e), FROM t1; MIN(t1.e) MAX(t1.e) NULLS_RATIO(t1.e) AVG_FREQUENCY(t1.e) 0.01 0.112 0.2250 6.2000 -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx1'; db_name table_name index_name prefix_arity avg_frequency test t1 idx1 1 6.4000 @@ -173,7 +160,7 @@ WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) AS 'ARITY 2'; ARITY 1 ARITY 2 6.4000 1.6875 -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx2'; db_name table_name index_name prefix_arity avg_frequency test t1 idx2 1 7.0000 @@ -188,7 +175,7 @@ WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 2'; ARITY 1 ARITY 2 7.0000 2.3846 -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx3'; db_name table_name index_name prefix_arity avg_frequency test t1 idx3 1 8.5000 @@ -198,7 +185,7 @@ SELECT AS 'ARITY 1'; ARITY 1 8.5000 -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx4'; db_name table_name index_name prefix_arity avg_frequency test t1 idx4 1 6.2000 @@ -225,25 +212,25 @@ DELETE FROM mysql.index_stat; ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(); Table Op Msg_type Msg_text test.t1 analyze status Table is already up to date -SELECT * FROM table_stat; +SELECT * FROM mysql.table_stat; db_name table_name cardinality test t1 40 -SELECT * FROM column_stat; +SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -SELECT * FROM index_stat; +SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4); Table Op Msg_type Msg_text test.t1 analyze status Table is already up to date -SELECT * FROM table_stat; +SELECT * FROM mysql.table_stat; db_name table_name cardinality test t1 40 -SELECT * FROM column_stat; +SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -SELECT * FROM index_stat; +SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency test t1 idx2 1 7.0000 test t1 idx2 2 2.3846 @@ -256,10 +243,10 @@ DELETE FROM mysql.index_stat; ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL; Table Op Msg_type Msg_text test.t1 analyze status Table is already up to date -SELECT * FROM table_stat; +SELECT * FROM mysql.table_stat; db_name table_name cardinality test t1 40 -SELECT * FROM column_stat; +SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 a 0 49 0.0000 4.0000 1.0000 test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 @@ -267,7 +254,7 @@ test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 test t1 e 0.01 0.112 0.2250 8.0000 6.2000 test t1 f 1 5 0.2000 1.0000 6.4000 -SELECT * FROM index_stat; +SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 test t1 idx1 1 6.4000 @@ -284,11 +271,11 @@ INSERT INTO t2 SELECT * FROM t1; ANALYZE TABLE t2; Table Op Msg_type Msg_text test.t2 analyze status OK -SELECT * FROM table_stat; +SELECT * FROM mysql.table_stat; db_name table_name cardinality test t1 40 test t2 40 -SELECT * FROM column_stat ORDER BY column_name; +SELECT * FROM mysql.column_stat ORDER BY column_name; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 a 0 49 0.0000 4.0000 1.0000 test t2 a 0 49 0.0000 4.0000 1.0000 @@ -302,7 +289,7 @@ test t1 e 0.01 0.112 0.2250 8.0000 6.2000 test t2 e 0.01 0.112 0.2250 8.0000 6.2000 test t1 f 1 5 0.2000 1.0000 6.4000 test t2 f 1 5 0.2000 1.0000 6.4000 -SELECT * FROM index_stat ORDER BY index_name, prefix_arity, table_name; +SELECT * FROM mysql.index_stat ORDER BY index_name, prefix_arity, table_name; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 test t2 PRIMARY 1 1.0000 @@ -335,7 +322,7 @@ ADD INDEX idx4 (e, b(4), d); ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status OK -SELECT * FROM column_stat; +SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 a 0 49 0.0000 4.0000 1.0000 test t1 b NULL NULL 0.2000 17.1250 NULL @@ -343,7 +330,7 @@ test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 test t1 e 0.01 0.112 0.2250 8.0000 6.2000 test t1 f 1 5 0.2000 1.0000 6.4000 -SELECT * FROM index_stat; +SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 test t1 idx2 1 7.0000 @@ -390,14 +377,14 @@ INDEX (Percentage) set use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; SELECT UPPER(db_name), UPPER(table_name), cardinality -FROM test.table_stat; +FROM mysql.table_stat; UPPER(db_name) UPPER(table_name) cardinality WORLD COUNTRY 239 WORLD CITY 4079 WORLD COUNTRYLANGUAGE 984 SELECT UPPER(db_name), UPPER(table_name), column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency -FROM test.column_stat; +FROM mysql.column_stat; UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency WORLD COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 WORLD COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 @@ -413,7 +400,7 @@ WORLD COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 WORLD COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 SELECT UPPER(db_name), UPPER(table_name), index_name, prefix_arity, avg_frequency -FROM test.index_stat; +FROM mysql.index_stat; UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency WORLD COUNTRY PRIMARY 1 1.0000 WORLD COUNTRY Name 1 1.0000 @@ -458,7 +445,7 @@ ALTER TABLE CountryLanguage ENGINE=InnoDB; set use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; SELECT UPPER(db_name), UPPER(table_name), cardinality -FROM test.table_stat; +FROM mysql.table_stat; UPPER(db_name) UPPER(table_name) cardinality WORLD COUNTRY 239 WORLD CITY 4079 @@ -468,7 +455,7 @@ WORLD_INNODB CITY 4079 WORLD_INNODB COUNTRYLANGUAGE 984 SELECT UPPER(db_name), UPPER(table_name), column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency -FROM test.column_stat; +FROM mysql.column_stat; UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency WORLD COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 WORLD COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 @@ -496,7 +483,7 @@ WORLD_INNODB COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 WORLD_INNODB COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 SELECT UPPER(db_name), UPPER(table_name), index_name, prefix_arity, avg_frequency -FROM test.index_stat; +FROM mysql.index_stat; UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency WORLD COUNTRY PRIMARY 1 1.0000 WORLD COUNTRY Name 1 1.0000 @@ -520,7 +507,4 @@ DROP DATABASE world_innodb; DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; -DROP VIEW test.table_stat; -DROP VIEW test.column_stat; -DROP VIEW test.index_stat; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/system_mysql_db.result b/mysql-test/r/system_mysql_db.result index 985fbd0539d..cf7db8f64ff 100644 --- a/mysql-test/r/system_mysql_db.result +++ b/mysql-test/r/system_mysql_db.result @@ -283,9 +283,9 @@ column_stat CREATE TABLE `column_stat` ( `column_name` varchar(64) COLLATE utf8_bin NOT NULL, `min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, `max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, - `nulls_ratio` double DEFAULT NULL, - `avg_length` double DEFAULT NULL, - `avg_frequency` double DEFAULT NULL, + `nulls_ratio` decimal(12,4) DEFAULT NULL, + `avg_length` decimal(12,4) DEFAULT NULL, + `avg_frequency` decimal(12,4) DEFAULT NULL, PRIMARY KEY (`db_name`,`table_name`,`column_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns' show create table index_stat; @@ -295,7 +295,7 @@ index_stat CREATE TABLE `index_stat` ( `table_name` varchar(64) COLLATE utf8_bin NOT NULL, `index_name` varchar(64) COLLATE utf8_bin NOT NULL, `prefix_arity` int(11) unsigned NOT NULL, - `avg_frequency` double DEFAULT NULL, + `avg_frequency` decimal(12,4) DEFAULT NULL, PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes' show tables; diff --git a/mysql-test/suite/funcs_1/r/is_columns_mysql.result b/mysql-test/suite/funcs_1/r/is_columns_mysql.result index c83f80cd28f..bc8be53d524 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_mysql.result +++ b/mysql-test/suite/funcs_1/r/is_columns_mysql.result @@ -9,13 +9,13 @@ def mysql columns_priv Host 1 NO char 60 180 NULL NULL NULL utf8 utf8_bin char( def mysql columns_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin char(64) PRI select,insert,update,references def mysql columns_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP select,insert,update,references def mysql columns_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references -def mysql column_stat avg_frequency 8 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references -def mysql column_stat avg_length 7 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references +def mysql column_stat avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references +def mysql column_stat avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references def mysql column_stat column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references def mysql column_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references def mysql column_stat max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references def mysql column_stat min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references -def mysql column_stat nulls_ratio 6 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references +def mysql column_stat nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references def mysql column_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references def mysql db Alter_priv 13 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references def mysql db Alter_routine_priv 19 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references @@ -105,7 +105,7 @@ def mysql host Select_priv 3 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci e def mysql host Show_view_priv 16 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references def mysql host Trigger_priv 20 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references def mysql host Update_priv 5 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references -def mysql index_stat avg_frequency 5 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references +def mysql index_stat avg_frequency 5 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references def mysql index_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references def mysql index_stat index_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references def mysql index_stat prefix_arity 4 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned PRI select,insert,update,references @@ -291,7 +291,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML; COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME NULL bigint NULL NULL NULL datetime NULL NULL -NULL double NULL NULL +NULL decimal NULL NULL NULL int NULL NULL NULL smallint NULL NULL NULL time NULL NULL @@ -325,9 +325,9 @@ NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp 3.0000 mysql column_stat column_name varchar 64 192 utf8 utf8_bin varchar(64) 3.0000 mysql column_stat min_value varchar 255 765 utf8 utf8_bin varchar(255) 3.0000 mysql column_stat max_value varchar 255 765 utf8 utf8_bin varchar(255) -NULL mysql column_stat nulls_ratio double NULL NULL NULL NULL double -NULL mysql column_stat avg_length double NULL NULL NULL NULL double -NULL mysql column_stat avg_frequency double NULL NULL NULL NULL double +NULL mysql column_stat nulls_ratio decimal NULL NULL NULL NULL decimal(12,4) +NULL mysql column_stat avg_length decimal NULL NULL NULL NULL decimal(12,4) +NULL mysql column_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4) 3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60) 3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64) 3.0000 mysql db User char 16 48 utf8 utf8_bin char(16) @@ -420,7 +420,7 @@ NULL mysql help_topic help_category_id smallint NULL NULL NULL NULL smallint(5) 3.0000 mysql index_stat table_name varchar 64 192 utf8 utf8_bin varchar(64) 3.0000 mysql index_stat index_name varchar 64 192 utf8 utf8_bin varchar(64) NULL mysql index_stat prefix_arity int NULL NULL NULL NULL int(11) unsigned -NULL mysql index_stat avg_frequency double NULL NULL NULL NULL double +NULL mysql index_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4) NULL mysql ndb_binlog_index Position bigint NULL NULL NULL NULL bigint(20) unsigned 1.0000 mysql ndb_binlog_index File varchar 255 255 latin1 latin1_swedish_ci varchar(255) NULL mysql ndb_binlog_index epoch bigint NULL NULL NULL NULL bigint(20) unsigned diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index e4676c7b340..600c7eff105 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -6,22 +6,6 @@ drop table if exists t1,t2; set @save_use_stat_tables=@@use_stat_tables; -CREATE VIEW table_stat AS -SELECT * FROM mysql.table_stat; - -CREATE VIEW column_stat AS - SELECT db_name, table_name, column_name, - min_value, max_value, - CAST(nulls_ratio AS decimal(12,4)) AS 'nulls_ratio', - CAST(avg_length AS decimal(12,4)) AS 'avg_length', - CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' - FROM mysql.column_stat; - -CREATE VIEW index_stat AS - SELECT db_name, table_name, index_name, prefix_arity, - CAST(avg_frequency AS decimal(12,4)) AS 'avg_frequency' - FROM mysql.index_stat; - DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; @@ -85,13 +69,13 @@ INSERT INTO t1 VALUES ANALYZE TABLE t1; -SELECT * FROM table_stat; -SELECT * FROM column_stat; -SELECT * FROM index_stat; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; SELECT COUNT(*) FROM t1; -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='a'; SELECT MIN(t1.a), MAX(t1.a), (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / @@ -100,7 +84,7 @@ SELECT MIN(t1.a), MAX(t1.a), (SELECT COUNT(DISTINCT t1.a) FROM t1) AS "AVG_FREQUENCY(t1.a)" FROM t1; -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='b'; SELECT MIN(t1.b), MAX(t1.b), (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / @@ -109,7 +93,7 @@ SELECT MIN(t1.b), MAX(t1.b), (SELECT COUNT(DISTINCT t1.b) FROM t1) AS "AVG_FREQUENCY(t1.b)" FROM t1; -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='c'; SELECT MIN(t1.c), MAX(t1.c), (SELECT COUNT(*) FROM t1 WHERE t1.c IS NULL) / @@ -118,7 +102,7 @@ SELECT MIN(t1.c), MAX(t1.c), (SELECT COUNT(DISTINCT t1.c) FROM t1) AS "AVG_FREQUENCY(t1.c)" FROM t1; -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='d'; SELECT MIN(t1.d), MAX(t1.d), (SELECT COUNT(*) FROM t1 WHERE t1.d IS NULL) / @@ -127,7 +111,7 @@ SELECT MIN(t1.d), MAX(t1.d), (SELECT COUNT(DISTINCT t1.d) FROM t1) AS "AVG_FREQUENCY(t1.d)" FROM t1; -SELECT * FROM column_stat +SELECT * FROM mysql.column_stat WHERE db_name='test' AND table_name='t1' AND column_name='e'; SELECT MIN(t1.e), MAX(t1.e), (SELECT COUNT(*) FROM t1 WHERE t1.e IS NULL) / @@ -136,7 +120,7 @@ SELECT MIN(t1.e), MAX(t1.e), (SELECT COUNT(DISTINCT t1.e) FROM t1) AS "AVG_FREQUENCY(t1.e)" FROM t1; -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx1'; SELECT (SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL) / @@ -147,7 +131,7 @@ SELECT WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) AS 'ARITY 2'; -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx2'; SELECT (SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL) / @@ -158,14 +142,14 @@ SELECT WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 2'; -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx3'; SELECT (SELECT COUNT(*) FROM t1 WHERE t1.d IS NOT NULL) / (SELECT COUNT(DISTINCT t1.d) FROM t1 WHERE t1.d IS NOT NULL) AS 'ARITY 1'; -SELECT * FROM index_stat +SELECT * FROM mysql.index_stat WHERE db_name='test' AND table_name='t1' AND index_name='idx4'; SELECT (SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL) / @@ -186,14 +170,14 @@ DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(); -SELECT * FROM table_stat; -SELECT * FROM column_stat; -SELECT * FROM index_stat; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4); -SELECT * FROM table_stat; -SELECT * FROM column_stat; -SELECT * FROM index_stat; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; @@ -201,9 +185,9 @@ DELETE FROM mysql.index_stat; ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL; -SELECT * FROM table_stat; -SELECT * FROM column_stat; -SELECT * FROM index_stat; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; CREATE TABLE t2 LIKE t1; @@ -212,9 +196,9 @@ INSERT INTO t2 SELECT * FROM t1; ANALYZE TABLE t2; -SELECT * FROM table_stat; -SELECT * FROM column_stat ORDER BY column_name; -SELECT * FROM index_stat ORDER BY index_name, prefix_arity, table_name; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat ORDER BY column_name; +SELECT * FROM mysql.index_stat ORDER BY index_name, prefix_arity, table_name; DELETE FROM mysql.table_stat; @@ -231,8 +215,8 @@ ALTER TABLE t1 ANALYZE TABLE t1; -SELECT * FROM column_stat; -SELECT * FROM index_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; DROP TABLE t1,t2; @@ -265,13 +249,13 @@ ANALYZE TABLE Country, City, CountryLanguage; --enable_result_log SELECT UPPER(db_name), UPPER(table_name), cardinality - FROM test.table_stat; + FROM mysql.table_stat; SELECT UPPER(db_name), UPPER(table_name), column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency - FROM test.column_stat; + FROM mysql.column_stat; SELECT UPPER(db_name), UPPER(table_name), index_name, prefix_arity, avg_frequency - FROM test.index_stat; + FROM mysql.index_stat; use test; @@ -302,13 +286,13 @@ ANALYZE TABLE Country, City, CountryLanguage; --enable_result_log SELECT UPPER(db_name), UPPER(table_name), cardinality - FROM test.table_stat; + FROM mysql.table_stat; SELECT UPPER(db_name), UPPER(table_name), column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency - FROM test.column_stat; + FROM mysql.column_stat; SELECT UPPER(db_name), UPPER(table_name), index_name, prefix_arity, avg_frequency - FROM test.index_stat; + FROM mysql.index_stat; use test; @@ -319,10 +303,6 @@ DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; -DROP VIEW test.table_stat; -DROP VIEW test.column_stat; -DROP VIEW test.index_stat; - set use_stat_tables=@save_use_stat_tables; \ No newline at end of file -- cgit v1.2.1 From 47fae7f08fd0437cd555bbd6b2533a4117340c8d Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 10 Jul 2012 16:34:39 -0700 Subject: Added procedures to delete records by keys from statistical tables. Now when a table is dropped the statistics on the table is removed from the statistical tables. If the table is altered in such a way that a column is dropped or the type of the column is changed then statistics on the column is removed from the table column_stat. It also triggers removal of the statistics on the indexes who use this column as its component. Added procedures that changes the names of the tables or columns in the statistical tables for. These procedures are used when tables/columns are renamed. Also partly re-factored the code that introduced the persistent statistical tables. Added test cases into statistics.test to cover the new code. --- mysql-test/r/statistics.result | 705 ++++++++++++++++++++- mysql-test/r/status_user.result | 4 +- .../suite/perfschema/r/myisam_file_io.result | 1 + mysql-test/suite/perfschema/t/myisam_file_io.test | 1 + mysql-test/t/statistics.test | 185 +++++- 5 files changed, 885 insertions(+), 11 deletions(-) (limited to 'mysql-test') diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index 99d3c04312b..a4e60e266d0 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -12,10 +12,10 @@ d date, e double, f bit(3), INDEX idx1 (b, e), -INDEX idx2(c, d), +INDEX idx2 (c, d), INDEX idx3 (d), INDEX idx4 (e, b, d) -); +) ENGINE= MYISAM; INSERT INTO t1 VALUES (0, NULL, NULL, NULL, NULL, NULL), (7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd', '1990-05-15', 0.1, b'100'), @@ -206,6 +206,662 @@ WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 3'; ARITY 1 ARITY 2 ARITY 3 6.2000 1.6875 1.1304 +CREATE TABLE t3 ( +a int NOT NULL PRIMARY KEY, +b varchar(32), +c char(16), +INDEX idx (c) +) ENGINE=MYISAM; +INSERT INTO t3 VALUES +(0, NULL, NULL), +(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd'), +(17, 'vvvvvvvvvvvvv', 'aaaa'), +(1, 'vvvvvvvvvvvvv', NULL), +(12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'), +(23, 'vvvvvvvvvvvvv', 'dddddddd'), +(8, 'vvvvvvvvvvvvv', 'aaaa'), +(22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa'), +(31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa'), +(10, NULL, 'aaaa'), +(5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'), +(15, 'vvvvvvvvvvvvv', 'ccccccccc'), +(30, NULL, 'bbbbbb'), +(38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb'), +(18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc'), +(9, 'yyy', 'bbbbbb'), +(29, 'vvvvvvvvvvvvv', 'dddddddd'); +ANALYZE TABLE t3; +Table Op Msg_type Msg_text +test.t3 analyze status OK +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +test t1 40 +test t3 17 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +test t3 a 0 38 0.0000 4.0000 1.0000 +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t3 PRIMARY 1 1.0000 +test t3 idx 1 3.7500 +ALTER TABLE t1 RENAME TO s1; +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +test s1 40 +test t3 17 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test s1 a 0 49 0.0000 4.0000 1.0000 +test s1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test s1 e 0.01 0.112 0.2250 8.0000 6.2000 +test s1 f 1 5 0.2000 1.0000 6.4000 +test t3 a 0 38 0.0000 4.0000 1.0000 +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test s1 PRIMARY 1 1.0000 +test s1 idx1 1 6.4000 +test s1 idx1 2 1.6875 +test s1 idx2 1 7.0000 +test s1 idx2 2 2.3846 +test s1 idx3 1 8.5000 +test s1 idx4 1 6.2000 +test s1 idx4 2 1.6875 +test s1 idx4 3 1.1304 +test t3 PRIMARY 1 1.0000 +test t3 idx 1 3.7500 +RENAME TABLE s1 TO t1; +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +test t1 40 +test t3 17 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +test t3 a 0 38 0.0000 4.0000 1.0000 +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t3 PRIMARY 1 1.0000 +test t3 idx 1 3.7500 +DROP TABLE t3; +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +CREATE TEMPORARY TABLE t0 ( +a int NOT NULL PRIMARY KEY, +b varchar(32) +); +INSERT INTO t0 SELECT a,b FROM t1; +ALTER TABLE t1 CHANGE COLUMN b x varchar(32), +CHANGE COLUMN e y double; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `x` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `y` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`y`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`y`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 y 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +ALTER TABLE t1 CHANGE COLUMN x b varchar(32), +CHANGE COLUMN y e double; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +ALTER TABLE t1 RENAME TO s1, CHANGE COLUMN b x varchar(32); +SHOW CREATE TABLE s1; +Table Create Table +s1 CREATE TABLE `s1` ( + `a` int(11) NOT NULL, + `x` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +test s1 40 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test s1 a 0 49 0.0000 4.0000 1.0000 +test s1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test s1 e 0.01 0.112 0.2250 8.0000 6.2000 +test s1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test s1 PRIMARY 1 1.0000 +test s1 idx1 1 6.4000 +test s1 idx1 2 1.6875 +test s1 idx2 1 7.0000 +test s1 idx2 2 2.3846 +test s1 idx3 1 8.5000 +test s1 idx4 1 6.2000 +test s1 idx4 2 1.6875 +test s1 idx4 3 1.1304 +ALTER TABLE s1 RENAME TO t1, CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +ALTER TABLE t1 CHANGE COLUMN b x varchar(30); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `x` varchar(30) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +ALTER TABLE t1 CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx4 3 1.1304 +test t1 idx4 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/save_column_stat' + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' + FROM mysql.column_stat WHERE column_name='b'; +SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/save_index_stat' + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' + FROM mysql.index_stat WHERE index_name IN ('idx1', 'idx4'); +ALTER TABLE t1 CHANGE COLUMN b x varchar(30); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `x` varchar(30) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx4 3 1.1304 +test t1 idx4 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +ALTER TABLE t1 CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/save_column_stat' + INTO TABLE mysql.column_stat +FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/save_index_stat' + INTO TABLE mysql.index_stat +FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx4 3 1.1304 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 2 1.6875 +test t1 idx4 1 6.2000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +ALTER TABLE t1 DROP COLUMN b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +DROP INDEX idx2 ON t1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`e`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +DROP INDEX idx1 ON t1; +DROP INDEX idx4 ON t1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD COLUMN b varchar(32); +CREATE INDEX idx1 ON t1(b, e); +CREATE INDEX idx2 ON t1(c, d); +CREATE INDEX idx4 ON t1(e, b, d); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + `b` varchar(32) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b NULL NULL 1.0000 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx1 2 NULL +test t1 idx1 1 NULL +test t1 idx3 1 8.5000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 NULL +test t1 idx4 3 NULL +UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a); +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +test t1 idx3 1 8.5000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +ALTER TABLE t1 DROP COLUMN b, +DROP INDEX idx1, DROP INDEX idx2, DROP INDEX idx4; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +ALTER TABLE t1 ADD COLUMN b varchar(32); +ALTER TABLE t1 +ADD INDEX idx1 (b, e), ADD INDEX idx2 (c, d), ADD INDEX idx4 (e, b, d); +UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + `b` varchar(32) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +test t1 a 0 49 0.0000 4.0000 1.0000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 f 1 5 0.2000 1.0000 6.4000 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx3 1 8.5000 +test t1 idx2 2 2.3846 +test t1 idx2 1 7.0000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +test t1 idx4 3 1.1304 DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; @@ -227,9 +883,9 @@ db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency test t1 idx2 1 7.0000 @@ -249,19 +905,19 @@ test t1 40 SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 test t1 e 0.01 0.112 0.2250 8.0000 6.2000 test t1 f 1 5 0.2000 1.0000 6.4000 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 test t1 idx1 1 6.4000 test t1 idx1 2 1.6875 test t1 idx2 1 7.0000 test t1 idx2 2 2.3846 -test t1 idx3 1 8.5000 test t1 idx4 1 6.2000 test t1 idx4 2 1.6875 test t1 idx4 3 1.1304 @@ -325,17 +981,17 @@ test.t1 analyze status OK SELECT * FROM mysql.column_stat; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b NULL NULL 0.2000 17.1250 NULL test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 test t1 e 0.01 0.112 0.2250 8.0000 6.2000 test t1 f 1 5 0.2000 1.0000 6.4000 +test t1 b NULL NULL 0.2000 17.1250 NULL SELECT * FROM mysql.index_stat; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 test t1 idx2 1 7.0000 test t1 idx2 2 2.3846 -test t1 idx3 1 8.5000 test t1 idx1 1 NULL test t1 idx1 2 NULL test t1 idx4 1 6.2000 @@ -503,7 +1159,42 @@ WORLD_INNODB COUNTRYLANGUAGE PRIMARY 2 1.0000 WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640 use test; DROP DATABASE world; +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +world_innodb Country 239 +world_innodb City 4079 +world_innodb CountryLanguage 984 +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +world_innodb Country Code ABW ZWE 0.0000 3.0000 1.0000 +world_innodb Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +world_innodb Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +world_innodb Country Population 0 1277558000 0.0000 4.0000 1.0575 +world_innodb Country Capital 1 4074 0.0293 4.0000 1.0000 +world_innodb City ID 1 4079 0.0000 4.0000 1.0000 +world_innodb City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +world_innodb City Country ABW ZWE 0.0000 3.0000 17.5819 +world_innodb City Population 42 10500000 0.0000 4.0000 1.0467 +world_innodb CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 +world_innodb CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +world_innodb CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +world_innodb Country PRIMARY 1 1.0000 +world_innodb Country Name 1 1.0000 +world_innodb City PRIMARY 1 1.0000 +world_innodb City Population 1 1.0467 +world_innodb City Country 1 17.5819 +world_innodb CountryLanguage PRIMARY 1 4.2232 +world_innodb CountryLanguage PRIMARY 2 1.0000 +world_innodb CountryLanguage Percentage 1 2.7640 DROP DATABASE world_innodb; +SELECT * FROM mysql.table_stat; +db_name table_name cardinality +SELECT * FROM mysql.column_stat; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index f43e217b8a5..040b2d85a51 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -107,7 +107,7 @@ Handler_mrr_key_refills 0 Handler_mrr_rowid_refills 0 Handler_prepare 18 Handler_read_first 0 -Handler_read_key 3 +Handler_read_key 9 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 @@ -123,7 +123,7 @@ Handler_update 5 Handler_write 7 select variable_value - @global_read_key as "handler_read_key" from information_schema.global_status where variable_name="handler_read_key"; handler_read_key -3 +9 set @@global.userstat=0; select * from information_schema.index_statistics; TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ diff --git a/mysql-test/suite/perfschema/r/myisam_file_io.result b/mysql-test/suite/perfschema/r/myisam_file_io.result index 5cdcf6ac789..eb8b0d6f9f5 100644 --- a/mysql-test/suite/perfschema/r/myisam_file_io.result +++ b/mysql-test/suite/perfschema/r/myisam_file_io.result @@ -17,6 +17,7 @@ substring(object_name, locate("no_index_tab", object_name)) as short_name from performance_schema.events_waits_history_long where operation not like "tell" and event_name like "wait/io/file/myisam/%" + having short_name <> "" order by thread_id, event_id; event_name short_source operation number_of_bytes short_name wait/io/file/myisam/kfile mi_create.c: create NULL no_index_tab.MYI diff --git a/mysql-test/suite/perfschema/t/myisam_file_io.test b/mysql-test/suite/perfschema/t/myisam_file_io.test index 5888c29fe22..d93edd7d3b6 100644 --- a/mysql-test/suite/perfschema/t/myisam_file_io.test +++ b/mysql-test/suite/perfschema/t/myisam_file_io.test @@ -46,6 +46,7 @@ select event_name, from performance_schema.events_waits_history_long where operation not like "tell" and event_name like "wait/io/file/myisam/%" + having short_name <> "" order by thread_id, event_id; # In case of failures, this will tell if file io are lost. diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 600c7eff105..0427c82349c 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -20,10 +20,10 @@ CREATE TABLE t1 ( e double, f bit(3), INDEX idx1 (b, e), - INDEX idx2(c, d), + INDEX idx2 (c, d), INDEX idx3 (d), INDEX idx4 (e, b, d) -); +) ENGINE= MYISAM; INSERT INTO t1 VALUES (0, NULL, NULL, NULL, NULL, NULL), @@ -165,6 +165,180 @@ SELECT WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 3'; +CREATE TABLE t3 ( + a int NOT NULL PRIMARY KEY, + b varchar(32), + c char(16), + INDEX idx (c) +) ENGINE=MYISAM; + +INSERT INTO t3 VALUES + (0, NULL, NULL), + (7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd'), + (17, 'vvvvvvvvvvvvv', 'aaaa'), + (1, 'vvvvvvvvvvvvv', NULL), + (12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'), + (23, 'vvvvvvvvvvvvv', 'dddddddd'), + (8, 'vvvvvvvvvvvvv', 'aaaa'), + (22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa'), + (31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa'), + (10, NULL, 'aaaa'), + (5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'), + (15, 'vvvvvvvvvvvvv', 'ccccccccc'), + (30, NULL, 'bbbbbb'), + (38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb'), + (18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc'), + (9, 'yyy', 'bbbbbb'), + (29, 'vvvvvvvvvvvvv', 'dddddddd'); + +ANALYZE TABLE t3; + +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ALTER TABLE t1 RENAME TO s1; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +RENAME TABLE s1 TO t1; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +DROP TABLE t3; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + + +CREATE TEMPORARY TABLE t0 ( + a int NOT NULL PRIMARY KEY, + b varchar(32) +); +INSERT INTO t0 SELECT a,b FROM t1; + +ALTER TABLE t1 CHANGE COLUMN b x varchar(32), + CHANGE COLUMN e y double; +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; + +ALTER TABLE t1 CHANGE COLUMN x b varchar(32), + CHANGE COLUMN y e double; +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; + +ALTER TABLE t1 RENAME TO s1, CHANGE COLUMN b x varchar(32); +SHOW CREATE TABLE s1; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ALTER TABLE s1 RENAME TO t1, CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ALTER TABLE t1 CHANGE COLUMN b x varchar(30); +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ALTER TABLE t1 CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx4); +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval +SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/save_column_stat' + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' + FROM mysql.column_stat WHERE column_name='b'; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval +SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/save_index_stat' + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' + FROM mysql.index_stat WHERE index_name IN ('idx1', 'idx4'); + +ALTER TABLE t1 CHANGE COLUMN b x varchar(30); +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ALTER TABLE t1 CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval +LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/save_column_stat' + INTO TABLE mysql.column_stat + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval +LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/save_index_stat' + INTO TABLE mysql.index_stat + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; +remove_file $MYSQLTEST_VARDIR/tmp/save_column_stat; +remove_file $MYSQLTEST_VARDIR/tmp/save_index_stat; + + +ALTER TABLE t1 DROP COLUMN b; +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +DROP INDEX idx2 ON t1; +SHOW CREATE TABLE t1; +SELECT * FROM mysql.index_stat; + +DROP INDEX idx1 ON t1; +DROP INDEX idx4 ON t1; +SHOW CREATE TABLE t1; + +ALTER TABLE t1 ADD COLUMN b varchar(32); +CREATE INDEX idx1 ON t1(b, e); +CREATE INDEX idx2 ON t1(c, d); +CREATE INDEX idx4 ON t1(e, b, d); +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a); +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ALTER TABLE t1 DROP COLUMN b, + DROP INDEX idx1, DROP INDEX idx2, DROP INDEX idx4; +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + +ALTER TABLE t1 ADD COLUMN b varchar(32); +ALTER TABLE t1 + ADD INDEX idx1 (b, e), ADD INDEX idx2 (c, d), ADD INDEX idx4 (e, b, d); +UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a); +SHOW CREATE TABLE t1; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; @@ -297,7 +471,14 @@ SELECT UPPER(db_name), UPPER(table_name), use test; DROP DATABASE world; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; + DROP DATABASE world_innodb; +SELECT * FROM mysql.table_stat; +SELECT * FROM mysql.column_stat; +SELECT * FROM mysql.index_stat; DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; -- cgit v1.2.1 From cb0a5c84b63a24d143160e38995cb35268f8eef4 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 10 Jul 2012 22:12:23 -0700 Subject: Made the output of the newly added test cases from statistics.test platform independent. Adjusted results of funcs_1.is_columns_mysql_embedded. --- mysql-test/r/statistics.result | 80 ++++++++++++---------- .../funcs_1/r/is_columns_mysql_embedded.result | 18 ++--- mysql-test/t/statistics.test | 22 ++++-- 3 files changed, 70 insertions(+), 50 deletions(-) (limited to 'mysql-test') diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index a4e60e266d0..680712e5f4a 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -1159,42 +1159,52 @@ WORLD_INNODB COUNTRYLANGUAGE PRIMARY 2 1.0000 WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640 use test; DROP DATABASE world; -SELECT * FROM mysql.table_stat; -db_name table_name cardinality -world_innodb Country 239 -world_innodb City 4079 -world_innodb CountryLanguage 984 -SELECT * FROM mysql.column_stat; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -world_innodb Country Code ABW ZWE 0.0000 3.0000 1.0000 -world_innodb Country Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 -world_innodb Country SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 -world_innodb Country Population 0 1277558000 0.0000 4.0000 1.0575 -world_innodb Country Capital 1 4074 0.0293 4.0000 1.0000 -world_innodb City ID 1 4079 0.0000 4.0000 1.0000 -world_innodb City Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 -world_innodb City Country ABW ZWE 0.0000 3.0000 17.5819 -world_innodb City Population 42 10500000 0.0000 4.0000 1.0467 -world_innodb CountryLanguage Country ABW ZWE 0.0000 3.0000 4.2232 -world_innodb CountryLanguage Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 -world_innodb CountryLanguage Percentage 0.0 99.9 0.0000 4.0000 2.7640 -SELECT * FROM mysql.index_stat; -db_name table_name index_name prefix_arity avg_frequency -world_innodb Country PRIMARY 1 1.0000 -world_innodb Country Name 1 1.0000 -world_innodb City PRIMARY 1 1.0000 -world_innodb City Population 1 1.0467 -world_innodb City Country 1 17.5819 -world_innodb CountryLanguage PRIMARY 1 4.2232 -world_innodb CountryLanguage PRIMARY 2 1.0000 -world_innodb CountryLanguage Percentage 1 2.7640 +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM mysql.table_stat; +UPPER(db_name) UPPER(table_name) cardinality +WORLD_INNODB COUNTRY 239 +WORLD_INNODB CITY 4079 +WORLD_INNODB COUNTRYLANGUAGE 984 +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM mysql.column_stat; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +WORLD_INNODB COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD_INNODB COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD_INNODB COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD_INNODB COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD_INNODB COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD_INNODB CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD_INNODB CITY Name A Coruña (La Coruña) Ürgenc 0.0000 8.6416 1.0195 +WORLD_INNODB CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD_INNODB CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD_INNODB COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD_INNODB COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD_INNODB COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM mysql.index_stat; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency +WORLD_INNODB COUNTRY PRIMARY 1 1.0000 +WORLD_INNODB COUNTRY Name 1 1.0000 +WORLD_INNODB CITY PRIMARY 1 1.0000 +WORLD_INNODB CITY Population 1 1.0467 +WORLD_INNODB CITY Country 1 17.5819 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640 DROP DATABASE world_innodb; -SELECT * FROM mysql.table_stat; -db_name table_name cardinality -SELECT * FROM mysql.column_stat; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -SELECT * FROM mysql.index_stat; -db_name table_name index_name prefix_arity avg_frequency +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM mysql.table_stat; +UPPER(db_name) UPPER(table_name) cardinality +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM mysql.column_stat; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM mysql.index_stat; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; diff --git a/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result index 031d9660e5b..38a4b9b69c6 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result @@ -9,13 +9,13 @@ def mysql columns_priv Host 1 NO char 60 180 NULL NULL NULL utf8 utf8_bin char( def mysql columns_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin char(64) PRI def mysql columns_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP def mysql columns_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI -def mysql column_stat avg_frequency 8 NULL YES double NULL NULL 22 NULL NULL NULL NULL double -def mysql column_stat avg_length 7 NULL YES double NULL NULL 22 NULL NULL NULL NULL double +def mysql column_stat avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) +def mysql column_stat avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) def mysql column_stat column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI def mysql column_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI def mysql column_stat max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) def mysql column_stat min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) -def mysql column_stat nulls_ratio 6 NULL YES double NULL NULL 22 NULL NULL NULL NULL double +def mysql column_stat nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) def mysql column_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI def mysql db Alter_priv 13 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') def mysql db Alter_routine_priv 19 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') @@ -105,7 +105,7 @@ def mysql host Select_priv 3 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci e def mysql host Show_view_priv 16 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') def mysql host Trigger_priv 20 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') def mysql host Update_priv 5 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') -def mysql index_stat avg_frequency 5 NULL YES double NULL NULL 22 NULL NULL NULL NULL double +def mysql index_stat avg_frequency 5 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) def mysql index_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI def mysql index_stat index_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI def mysql index_stat prefix_arity 4 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned PRI @@ -291,7 +291,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML; COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME NULL bigint NULL NULL NULL datetime NULL NULL -NULL double NULL NULL +NULL decimal NULL NULL NULL int NULL NULL NULL smallint NULL NULL NULL time NULL NULL @@ -325,9 +325,9 @@ NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp 3.0000 mysql column_stat column_name varchar 64 192 utf8 utf8_bin varchar(64) 3.0000 mysql column_stat min_value varchar 255 765 utf8 utf8_bin varchar(255) 3.0000 mysql column_stat max_value varchar 255 765 utf8 utf8_bin varchar(255) -NULL mysql column_stat nulls_ratio double NULL NULL NULL NULL double -NULL mysql column_stat avg_length double NULL NULL NULL NULL double -NULL mysql column_stat avg_frequency double NULL NULL NULL NULL double +NULL mysql column_stat nulls_ratio decimal NULL NULL NULL NULL decimal(12,4) +NULL mysql column_stat avg_length decimal NULL NULL NULL NULL decimal(12,4) +NULL mysql column_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4) 3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60) 3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64) 3.0000 mysql db User char 16 48 utf8 utf8_bin char(16) @@ -420,7 +420,7 @@ NULL mysql help_topic help_category_id smallint NULL NULL NULL NULL smallint(5) 3.0000 mysql index_stat table_name varchar 64 192 utf8 utf8_bin varchar(64) 3.0000 mysql index_stat index_name varchar 64 192 utf8 utf8_bin varchar(64) NULL mysql index_stat prefix_arity int NULL NULL NULL NULL int(11) unsigned -NULL mysql index_stat avg_frequency double NULL NULL NULL NULL double +NULL mysql index_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4) NULL mysql ndb_binlog_index Position bigint NULL NULL NULL NULL bigint(20) unsigned 1.0000 mysql ndb_binlog_index File varchar 255 255 latin1 latin1_swedish_ci varchar(255) NULL mysql ndb_binlog_index epoch bigint NULL NULL NULL NULL bigint(20) unsigned diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 0427c82349c..903cf27648c 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -471,14 +471,24 @@ SELECT UPPER(db_name), UPPER(table_name), use test; DROP DATABASE world; -SELECT * FROM mysql.table_stat; -SELECT * FROM mysql.column_stat; -SELECT * FROM mysql.index_stat; +SELECT UPPER(db_name), UPPER(table_name), cardinality + FROM mysql.table_stat; +SELECT UPPER(db_name), UPPER(table_name), + column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency + FROM mysql.column_stat; +SELECT UPPER(db_name), UPPER(table_name), + index_name, prefix_arity, avg_frequency + FROM mysql.index_stat; DROP DATABASE world_innodb; -SELECT * FROM mysql.table_stat; -SELECT * FROM mysql.column_stat; -SELECT * FROM mysql.index_stat; +SELECT UPPER(db_name), UPPER(table_name), cardinality + FROM mysql.table_stat; +SELECT UPPER(db_name), UPPER(table_name), + column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency + FROM mysql.column_stat; +SELECT UPPER(db_name), UPPER(table_name), + index_name, prefix_arity, avg_frequency + FROM mysql.index_stat; DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; -- 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. --- mysql-test/r/stat_tables.result | 116 ++++++++++++++++++++++ mysql-test/r/stat_tables_innodb.result | 172 +++++++++++++++++++++++++++++++++ mysql-test/t/stat_tables.test | 109 +++++++++++++++++++++ 3 files changed, 397 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 26f2b602c6b..09486d4ce0b 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -334,6 +334,122 @@ and o_orderkey=l_orderkey and p_partkey=l_partkey; o_orderkey p_partkey 5895 200 set optimizer_switch=@save_optimizer_switch; +flush table lineitem; +set use_stat_tables='never'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24 ; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +revenue +77949.91860000002 +set use_stat_tables='preferably'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +delete from mysql.index_stat +where table_name='lineitem' and +index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +delete from mysql.index_stat +where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 DROP DATABASE dbt3_s001; use test; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 3d534dcab29..4cb1261b689 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -361,6 +361,178 @@ and o_orderkey=l_orderkey and p_partkey=l_partkey; o_orderkey p_partkey 5895 200 set optimizer_switch=@save_optimizer_switch; +flush table lineitem; +set use_stat_tables='never'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24 ; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +revenue +77949.91860000002 +set use_stat_tables='preferably'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 2 1.0364 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_commitdate 3 1.0000 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey 2 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_partkey 2 1.0089 +dbt3_s001 lineitem i_l_partkey 3 1.0000 +dbt3_s001 lineitem i_l_receiptdate 3 1.0000 +dbt3_s001 lineitem i_l_receiptdate 2 1.0152 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_shipdate 3 1.0000 +dbt3_s001 lineitem i_l_shipdate 2 1.0149 +dbt3_s001 lineitem i_l_suppkey 2 1.2073 +dbt3_s001 lineitem i_l_suppkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +delete from mysql.index_stat +where table_name='lineitem' and +index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 2 1.0364 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_commitdate 3 1.0000 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey 2 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_partkey 2 1.0089 +dbt3_s001 lineitem i_l_partkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 2 1.2073 +dbt3_s001 lineitem i_l_suppkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 2 1.0364 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_commitdate 3 1.0000 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey 2 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 +dbt3_s001 lineitem i_l_partkey 3 1.0000 +dbt3_s001 lineitem i_l_partkey 2 1.0089 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_shipdate 3 1.0000 +dbt3_s001 lineitem i_l_shipdate 2 1.0149 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 2 1.2073 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 +delete from mysql.index_stat +where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 2 1.0364 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_commitdate 3 1.0000 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey 2 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_partkey 2 1.0089 +dbt3_s001 lineitem i_l_partkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 2 1.2073 +dbt3_s001 lineitem i_l_suppkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 2 1.0364 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_commitdate 3 1.0000 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey 2 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 +dbt3_s001 lineitem i_l_partkey 3 1.0000 +dbt3_s001 lineitem i_l_partkey 2 1.0089 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 2 1.2073 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 DROP DATABASE dbt3_s001; use test; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index 640f9febc75..bdb689228b2 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -144,6 +144,115 @@ eval $QQ1; set optimizer_switch=@save_optimizer_switch; +# +# Test for parallel memory allocation for statistical data +# +# assumes that start the code of memory allocation for stats data has this line: +# +# DEBUG_SYNC(thd, "statistics_mem_alloc_start1"); +# DEBUG_SYNC(thd, "statistics_mem_alloc-start2"); +# + +let $Q6= +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' + and l_shipdate < date '1994-01-01' + interval '1' year + and l_discount between 0.06 - 0.01 and 0.06 + 0.01 + and l_quantity < 24; + +flush table lineitem; +set use_stat_tables='never'; +eval $Q6; + +connect (con1, localhost, root,,); +connect (con2, localhost, root,,); + +connection con1; +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send_eval $Q6 + +connection con2; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send_eval $Q6 + +connection con1; +--reap + +connection con2; +--reap + +connection default; +set use_stat_tables='preferably'; +disconnect con1; +disconnect con2; + +# +# Test for parallel statistics collection +# +# assumes that start of stats collection code has this line: +# +# DEBUG_SYNC(thd, "statistics_collection_start1"); +# DEBUG_SYNC(thd, "statistics_collection_start2"); +# + +select * from mysql.index_stat where table_name='lineitem' order by index_name; +delete from mysql.index_stat + where table_name='lineitem' and + index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +--disable_result_log +--disable_warnings +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +--enable_warnings +--enable_result_log +select * from mysql.index_stat where table_name='lineitem' order by index_name; +delete from mysql.index_stat + where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; + +connect (con1, localhost, root,,); +connect (con2, localhost, root,,); + +connection con1; +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send analyze table lineitem persistent for columns() indexes (i_l_shipdate) + +connection con2; +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send analyze table lineitem persistent for columns() indexes (i_l_receiptdate) + +connection con1; +--disable_result_log +--disable_warnings +--reap +--enable_warnings +--enable_result_log + +connection con2; +--disable_result_log +--disable_warnings +--reap +--enable_warnings +--enable_result_log + +connection default; +disconnect con1; +disconnect con2; + +select * from mysql.index_stat where table_name='lineitem' order by index_name; DROP DATABASE dbt3_s001; -- cgit v1.2.1 From 26947f5adb72cd6b8190ee5d5e6d11be6a2448b5 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 27 Jul 2012 12:05:23 -0700 Subject: Added missing declaration of statistics_lock. Replaced bzero with memset. Added missing --source include/have_debug_sync.inc into stat_tables.test. --- mysql-test/r/stat_tables.result | 2 ++ mysql-test/r/stat_tables_innodb.result | 2 ++ mysql-test/t/stat_tables.test | 3 +++ 3 files changed, 7 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 09486d4ce0b..9d62ff357e2 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -369,6 +369,7 @@ revenue revenue 77949.91860000002 set use_stat_tables='preferably'; +set debug_sync='RESET'; select * from mysql.index_stat where table_name='lineitem' order by index_name; db_name table_name index_name prefix_arity avg_frequency dbt3_s001 lineitem PRIMARY 1 4.0033 @@ -436,6 +437,7 @@ set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; use dbt3_s001; set use_stat_tables='preferably'; analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +set debug_sync='RESET'; select * from mysql.index_stat where table_name='lineitem' order by index_name; db_name table_name index_name prefix_arity avg_frequency dbt3_s001 lineitem PRIMARY 1 4.0033 diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 4cb1261b689..59c1aa66790 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -396,6 +396,7 @@ revenue revenue 77949.91860000002 set use_stat_tables='preferably'; +set debug_sync='RESET'; select * from mysql.index_stat where table_name='lineitem' order by index_name; db_name table_name index_name prefix_arity avg_frequency dbt3_s001 lineitem PRIMARY 1 4.0033 @@ -509,6 +510,7 @@ set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; use dbt3_s001; set use_stat_tables='preferably'; analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +set debug_sync='RESET'; select * from mysql.index_stat where table_name='lineitem' order by index_name; db_name table_name index_name prefix_arity avg_frequency dbt3_s001 lineitem PRIMARY 1 4.0033 diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index bdb689228b2..40c4c17c569 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -1,4 +1,5 @@ --source include/have_stat_tables.inc +--source include/have_debug_sync.inc set @save_use_stat_tables=@@use_stat_tables; @@ -192,6 +193,7 @@ connection default; set use_stat_tables='preferably'; disconnect con1; disconnect con2; +set debug_sync='RESET'; # # Test for parallel statistics collection @@ -251,6 +253,7 @@ connection con2; connection default; disconnect con1; disconnect con2; +set debug_sync='RESET'; select * from mysql.index_stat where table_name='lineitem' order by index_name; -- cgit v1.2.1 From 6eace757e94e9236c792d3ba718aebb91c9cce77 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 27 Jul 2012 17:33:23 -0700 Subject: Moved the test cases for parallel execution from stat_tables.test into a separate file stat_tables_par.test because the test cases could not be run with embedded server. --- mysql-test/r/stat_tables.result | 118 ------------------- mysql-test/r/stat_tables_innodb.result | 174 ----------------------------- mysql-test/r/stat_tables_par.result | 167 +++++++++++++++++++++++++++ mysql-test/r/stat_tables_par_innodb.result | 172 ++++++++++++++++++++++++++++ mysql-test/t/stat_tables.test | 112 ------------------- mysql-test/t/stat_tables_par.test | 153 +++++++++++++++++++++++++ mysql-test/t/stat_tables_par_innodb.test | 12 ++ 7 files changed, 504 insertions(+), 404 deletions(-) create mode 100644 mysql-test/r/stat_tables_par.result create mode 100644 mysql-test/r/stat_tables_par_innodb.result create mode 100644 mysql-test/t/stat_tables_par.test create mode 100644 mysql-test/t/stat_tables_par_innodb.test (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 9d62ff357e2..26f2b602c6b 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -334,124 +334,6 @@ and o_orderkey=l_orderkey and p_partkey=l_partkey; o_orderkey p_partkey 5895 200 set optimizer_switch=@save_optimizer_switch; -flush table lineitem; -set use_stat_tables='never'; -select sum(l_extendedprice*l_discount) as revenue -from lineitem -where l_shipdate >= date '1994-01-01' -and l_shipdate < date '1994-01-01' + interval '1' year -and l_discount between 0.06 - 0.01 and 0.06 + 0.01 -and l_quantity < 24; -revenue -77949.91860000002 -set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; -set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -select sum(l_extendedprice*l_discount) as revenue -from lineitem -where l_shipdate >= date '1994-01-01' -and l_shipdate < date '1994-01-01' + interval '1' year -and l_discount between 0.06 - 0.01 and 0.06 + 0.01 -and l_quantity < 24 ; -set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; -set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -select sum(l_extendedprice*l_discount) as revenue -from lineitem -where l_shipdate >= date '1994-01-01' -and l_shipdate < date '1994-01-01' + interval '1' year -and l_discount between 0.06 - 0.01 and 0.06 + 0.01 -and l_quantity < 24; -revenue -77949.91860000002 -revenue -77949.91860000002 -set use_stat_tables='preferably'; -set debug_sync='RESET'; -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477 -dbt3_s001 lineitem i_l_shipdate 1 2.6500 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -delete from mysql.index_stat -where table_name='lineitem' and -index_name in ('i_l_shipdate', 'i_l_receiptdate'); -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -analyze table lineitem persistent for columns() indexes (i_l_shipdate); -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_shipdate 1 2.6500 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -delete from mysql.index_stat -where table_name='lineitem' and index_name= 'i_l_shipdate'; -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; -set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -analyze table lineitem persistent for columns() indexes (i_l_shipdate); -set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; -set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -analyze table lineitem persistent for columns() indexes (i_l_receiptdate); -set debug_sync='RESET'; -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477 -dbt3_s001 lineitem i_l_shipdate 1 2.6500 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 DROP DATABASE dbt3_s001; use test; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 59c1aa66790..3d534dcab29 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -361,180 +361,6 @@ and o_orderkey=l_orderkey and p_partkey=l_partkey; o_orderkey p_partkey 5895 200 set optimizer_switch=@save_optimizer_switch; -flush table lineitem; -set use_stat_tables='never'; -select sum(l_extendedprice*l_discount) as revenue -from lineitem -where l_shipdate >= date '1994-01-01' -and l_shipdate < date '1994-01-01' + interval '1' year -and l_discount between 0.06 - 0.01 and 0.06 + 0.01 -and l_quantity < 24; -revenue -77949.91860000002 -set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; -set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -select sum(l_extendedprice*l_discount) as revenue -from lineitem -where l_shipdate >= date '1994-01-01' -and l_shipdate < date '1994-01-01' + interval '1' year -and l_discount between 0.06 - 0.01 and 0.06 + 0.01 -and l_quantity < 24 ; -set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; -set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -select sum(l_extendedprice*l_discount) as revenue -from lineitem -where l_shipdate >= date '1994-01-01' -and l_shipdate < date '1994-01-01' + interval '1' year -and l_discount between 0.06 - 0.01 and 0.06 + 0.01 -and l_quantity < 24; -revenue -77949.91860000002 -revenue -77949.91860000002 -set use_stat_tables='preferably'; -set debug_sync='RESET'; -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 2 1.0364 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_commitdate 3 1.0000 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey 2 1.0000 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_partkey 2 1.0089 -dbt3_s001 lineitem i_l_partkey 3 1.0000 -dbt3_s001 lineitem i_l_receiptdate 3 1.0000 -dbt3_s001 lineitem i_l_receiptdate 2 1.0152 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477 -dbt3_s001 lineitem i_l_shipdate 1 2.6500 -dbt3_s001 lineitem i_l_shipdate 3 1.0000 -dbt3_s001 lineitem i_l_shipdate 2 1.0149 -dbt3_s001 lineitem i_l_suppkey 2 1.2073 -dbt3_s001 lineitem i_l_suppkey 3 1.0000 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 -dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -delete from mysql.index_stat -where table_name='lineitem' and -index_name in ('i_l_shipdate', 'i_l_receiptdate'); -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 2 1.0364 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_commitdate 3 1.0000 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey 2 1.0000 -dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_partkey 2 1.0089 -dbt3_s001 lineitem i_l_partkey 3 1.0000 -dbt3_s001 lineitem i_l_suppkey 2 1.2073 -dbt3_s001 lineitem i_l_suppkey 3 1.0000 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 -analyze table lineitem persistent for columns() indexes (i_l_shipdate); -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 2 1.0364 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_commitdate 3 1.0000 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey 2 1.0000 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 -dbt3_s001 lineitem i_l_partkey 3 1.0000 -dbt3_s001 lineitem i_l_partkey 2 1.0089 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_shipdate 3 1.0000 -dbt3_s001 lineitem i_l_shipdate 2 1.0149 -dbt3_s001 lineitem i_l_shipdate 1 2.6500 -dbt3_s001 lineitem i_l_suppkey 3 1.0000 -dbt3_s001 lineitem i_l_suppkey 2 1.2073 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 -delete from mysql.index_stat -where table_name='lineitem' and index_name= 'i_l_shipdate'; -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 2 1.0364 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_commitdate 3 1.0000 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey 2 1.0000 -dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_partkey 2 1.0089 -dbt3_s001 lineitem i_l_partkey 3 1.0000 -dbt3_s001 lineitem i_l_suppkey 2 1.2073 -dbt3_s001 lineitem i_l_suppkey 3 1.0000 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 -set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; -set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -analyze table lineitem persistent for columns() indexes (i_l_shipdate); -set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; -set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; -analyze table lineitem persistent for columns() indexes (i_l_receiptdate); -set debug_sync='RESET'; -select * from mysql.index_stat where table_name='lineitem' order by index_name; -db_name table_name index_name prefix_arity avg_frequency -dbt3_s001 lineitem PRIMARY 1 4.0033 -dbt3_s001 lineitem PRIMARY 2 1.0000 -dbt3_s001 lineitem i_l_commitdate 2 1.0364 -dbt3_s001 lineitem i_l_commitdate 1 2.7160 -dbt3_s001 lineitem i_l_commitdate 3 1.0000 -dbt3_s001 lineitem i_l_orderkey 1 4.0033 -dbt3_s001 lineitem i_l_orderkey 2 1.0000 -dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 -dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 -dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 -dbt3_s001 lineitem i_l_partkey 3 1.0000 -dbt3_s001 lineitem i_l_partkey 2 1.0089 -dbt3_s001 lineitem i_l_partkey 1 30.0250 -dbt3_s001 lineitem i_l_receiptdate 1 2.6477 -dbt3_s001 lineitem i_l_shipdate 1 2.6500 -dbt3_s001 lineitem i_l_suppkey 3 1.0000 -dbt3_s001 lineitem i_l_suppkey 2 1.2073 -dbt3_s001 lineitem i_l_suppkey 1 600.5000 -dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 -dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 -dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 -dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 DROP DATABASE dbt3_s001; use test; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_par.result b/mysql-test/r/stat_tables_par.result new file mode 100644 index 00000000000..19ecb907a66 --- /dev/null +++ b/mysql-test/r/stat_tables_par.result @@ -0,0 +1,167 @@ +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stat; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +flush table lineitem; +set use_stat_tables='never'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24 ; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +revenue +77949.91860000002 +set use_stat_tables='preferably'; +set debug_sync='RESET'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +delete from mysql.index_stat +where table_name='lineitem' and +index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +delete from mysql.index_stat +where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +set debug_sync='RESET'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +DROP DATABASE dbt3_s001; +use test; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_par_innodb.result b/mysql-test/r/stat_tables_par_innodb.result new file mode 100644 index 00000000000..dc290c78dd9 --- /dev/null +++ b/mysql-test/r/stat_tables_par_innodb.result @@ -0,0 +1,172 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stat; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +flush table lineitem; +set use_stat_tables='never'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24 ; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +revenue +77949.91860000002 +set use_stat_tables='preferably'; +set debug_sync='RESET'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +delete from mysql.index_stat +where table_name='lineitem' and +index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +delete from mysql.index_stat +where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +set debug_sync='RESET'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +DROP DATABASE dbt3_s001; +use test; +set use_stat_tables=@save_use_stat_tables; +set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index 40c4c17c569..640f9febc75 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -1,5 +1,4 @@ --source include/have_stat_tables.inc ---source include/have_debug_sync.inc set @save_use_stat_tables=@@use_stat_tables; @@ -145,117 +144,6 @@ eval $QQ1; set optimizer_switch=@save_optimizer_switch; -# -# Test for parallel memory allocation for statistical data -# -# assumes that start the code of memory allocation for stats data has this line: -# -# DEBUG_SYNC(thd, "statistics_mem_alloc_start1"); -# DEBUG_SYNC(thd, "statistics_mem_alloc-start2"); -# - -let $Q6= -select sum(l_extendedprice*l_discount) as revenue -from lineitem -where l_shipdate >= date '1994-01-01' - and l_shipdate < date '1994-01-01' + interval '1' year - and l_discount between 0.06 - 0.01 and 0.06 + 0.01 - and l_quantity < 24; - -flush table lineitem; -set use_stat_tables='never'; -eval $Q6; - -connect (con1, localhost, root,,); -connect (con2, localhost, root,,); - -connection con1; -set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; -set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; ---send_eval $Q6 - -connection con2; -set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; -set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; ---send_eval $Q6 - -connection con1; ---reap - -connection con2; ---reap - -connection default; -set use_stat_tables='preferably'; -disconnect con1; -disconnect con2; -set debug_sync='RESET'; - -# -# Test for parallel statistics collection -# -# assumes that start of stats collection code has this line: -# -# DEBUG_SYNC(thd, "statistics_collection_start1"); -# DEBUG_SYNC(thd, "statistics_collection_start2"); -# - -select * from mysql.index_stat where table_name='lineitem' order by index_name; -delete from mysql.index_stat - where table_name='lineitem' and - index_name in ('i_l_shipdate', 'i_l_receiptdate'); -select * from mysql.index_stat where table_name='lineitem' order by index_name; ---disable_result_log ---disable_warnings -analyze table lineitem persistent for columns() indexes (i_l_shipdate); ---enable_warnings ---enable_result_log -select * from mysql.index_stat where table_name='lineitem' order by index_name; -delete from mysql.index_stat - where table_name='lineitem' and index_name= 'i_l_shipdate'; -select * from mysql.index_stat where table_name='lineitem' order by index_name; - -connect (con1, localhost, root,,); -connect (con2, localhost, root,,); - -connection con1; -set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; -set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; ---send analyze table lineitem persistent for columns() indexes (i_l_shipdate) - -connection con2; -set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; -set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; -use dbt3_s001; -set use_stat_tables='preferably'; ---send analyze table lineitem persistent for columns() indexes (i_l_receiptdate) - -connection con1; ---disable_result_log ---disable_warnings ---reap ---enable_warnings ---enable_result_log - -connection con2; ---disable_result_log ---disable_warnings ---reap ---enable_warnings ---enable_result_log - -connection default; -disconnect con1; -disconnect con2; -set debug_sync='RESET'; - -select * from mysql.index_stat where table_name='lineitem' order by index_name; DROP DATABASE dbt3_s001; diff --git a/mysql-test/t/stat_tables_par.test b/mysql-test/t/stat_tables_par.test new file mode 100644 index 00000000000..27507ccf811 --- /dev/null +++ b/mysql-test/t/stat_tables_par.test @@ -0,0 +1,153 @@ +--source include/have_stat_tables.inc +--source include/have_debug_sync.inc +--source include/not_embedded.inc + +set @save_use_stat_tables=@@use_stat_tables; + +set use_stat_tables='preferably'; + +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc +delete from mysql.table_stat; +delete from mysql.column_stat; +delete from mysql.index_stat; +ANALYZE TABLE +customer, lineitem, nation, orders, part, partsupp, region, supplier; +--enable_warnings +--enable_result_log +--enable_query_log + +select * from mysql.table_stat; +select * from mysql.index_stat; + + +# +# Test for parallel memory allocation for statistical data +# +# assumes that start the code of memory allocation for stats data has this line: +# +# DEBUG_SYNC(thd, "statistics_mem_alloc_start1"); +# DEBUG_SYNC(thd, "statistics_mem_alloc-start2"); +# + +let $Q6= +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' + and l_shipdate < date '1994-01-01' + interval '1' year + and l_discount between 0.06 - 0.01 and 0.06 + 0.01 + and l_quantity < 24; + +flush table lineitem; +set use_stat_tables='never'; +eval $Q6; + +connect (con1, localhost, root,,); +connect (con2, localhost, root,,); + +connection con1; +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send_eval $Q6 + +connection con2; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send_eval $Q6 + +connection con1; +--reap + +connection con2; +--reap + +connection default; +set use_stat_tables='preferably'; +disconnect con1; +disconnect con2; +set debug_sync='RESET'; + +# +# Test for parallel statistics collection +# +# assumes that start of stats collection code has this line: +# +# DEBUG_SYNC(thd, "statistics_collection_start1"); +# DEBUG_SYNC(thd, "statistics_collection_start2"); +# + +select * from mysql.index_stat where table_name='lineitem' order by index_name; +delete from mysql.index_stat + where table_name='lineitem' and + index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stat where table_name='lineitem' order by index_name; +--disable_result_log +--disable_warnings +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +--enable_warnings +--enable_result_log +select * from mysql.index_stat where table_name='lineitem' order by index_name; +delete from mysql.index_stat + where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stat where table_name='lineitem' order by index_name; + +connect (con1, localhost, root,,); +connect (con2, localhost, root,,); + +connection con1; +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send analyze table lineitem persistent for columns() indexes (i_l_shipdate) + +connection con2; +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +--send analyze table lineitem persistent for columns() indexes (i_l_receiptdate) + +connection con1; +--disable_result_log +--disable_warnings +--reap +--enable_warnings +--enable_result_log + +connection con2; +--disable_result_log +--disable_warnings +--reap +--enable_warnings +--enable_result_log + +connection default; +disconnect con1; +disconnect con2; +set debug_sync='RESET'; + +select * from mysql.index_stat where table_name='lineitem' order by index_name; + +DROP DATABASE dbt3_s001; + +use test; + +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/t/stat_tables_par_innodb.test b/mysql-test/t/stat_tables_par_innodb.test new file mode 100644 index 00000000000..fd5833e4aaf --- /dev/null +++ b/mysql-test/t/stat_tables_par_innodb.test @@ -0,0 +1,12 @@ +--source include/have_innodb.inc + +SET SESSION STORAGE_ENGINE='InnoDB'; + +set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; + +--source stat_tables_par.test + +set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; + +SET SESSION STORAGE_ENGINE=DEFAULT; -- cgit v1.2.1 From 85db02984f2306691df6acce1caf7f146beb471f Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 17 Aug 2012 13:23:49 -0700 Subject: Fixed bug mdev-464. The value of system variable use_stat_tables was always reset to 0 ('never') by mistake at the launch of the server. --- mysql-test/r/stat_tables.result | 6 ++++++ mysql-test/r/stat_tables_innodb.result | 6 ++++++ mysql-test/t/stat_tables.test | 3 +++ 3 files changed, 15 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 26f2b602c6b..5d098bc9ef9 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -1,3 +1,9 @@ +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY set @save_use_stat_tables=@@use_stat_tables; set use_stat_tables='preferably'; DROP DATABASE IF EXISTS dbt3_s001; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 3d534dcab29..2bdc618b566 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -1,6 +1,12 @@ SET SESSION STORAGE_ENGINE='InnoDB'; set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; set optimizer_switch='extended_keys=on'; +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY set @save_use_stat_tables=@@use_stat_tables; set use_stat_tables='preferably'; DROP DATABASE IF EXISTS dbt3_s001; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index 640f9febc75..2ef915cf12c 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -1,5 +1,8 @@ --source include/have_stat_tables.inc +select @@global.use_stat_tables; +select @@session.use_stat_tables; + set @save_use_stat_tables=@@use_stat_tables; set use_stat_tables='preferably'; -- cgit v1.2.1 From fd7059d20859863a146cd306b88ac6e9817622fd Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 18 Aug 2012 22:18:46 -0700 Subject: Fixed the following problem: the syntax of the ANALYZE command did not returned an error if the list of the specified index names contained the name 'primary'. --- mysql-test/r/statistics.result | 19 +++++++++++++++++++ mysql-test/t/statistics.test | 5 +++++ 2 files changed, 24 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index 680712e5f4a..5a163ca3f84 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -893,6 +893,25 @@ test t1 idx2 2 2.3846 test t1 idx4 1 6.2000 test t1 idx4 2 1.6875 test t1 idx4 3 1.1304 +DELETE FROM mysql.index_stat WHERE table_name='t1' AND index_name='primary'; +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(primary); +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM mysql.index_stat; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t1 PRIMARY 1 1.0000 DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 903cf27648c..30aa335e42d 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -353,6 +353,11 @@ SELECT * FROM mysql.table_stat; SELECT * FROM mysql.column_stat; SELECT * FROM mysql.index_stat; +DELETE FROM mysql.index_stat WHERE table_name='t1' AND index_name='primary'; +SELECT * FROM mysql.index_stat; +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(primary); +SELECT * FROM mysql.index_stat; + DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; -- cgit v1.2.1 From fb69d6426563db40e1558391cecb84ee2eaef8bb Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 20 Aug 2012 12:05:37 -0700 Subject: Fixed bug mdev-463. RBR should be turned off when an ANALYZE TABLE command is executed. --- mysql-test/r/stat_tables_rbr.result | 10 ++++++++++ mysql-test/t/stat_tables_rbr.test | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 mysql-test/r/stat_tables_rbr.result create mode 100644 mysql-test/t/stat_tables_rbr.test (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables_rbr.result b/mysql-test/r/stat_tables_rbr.result new file mode 100644 index 00000000000..7a0d23193e7 --- /dev/null +++ b/mysql-test/r/stat_tables_rbr.result @@ -0,0 +1,10 @@ +# +# Bug mdev-463: assertion failure when running ANALYZE with RBR on +# +SET GLOBAL use_stat_tables = PREFERABLY; +CREATE TABLE t1 (i INT) ENGINE=InnoDB; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; +SET GLOBAL use_stat_tables = DEFAULT; diff --git a/mysql-test/t/stat_tables_rbr.test b/mysql-test/t/stat_tables_rbr.test new file mode 100644 index 00000000000..5297bccf2f4 --- /dev/null +++ b/mysql-test/t/stat_tables_rbr.test @@ -0,0 +1,18 @@ +--source include/have_binlog_format_row.inc +--source include/have_innodb.inc + +--echo # +--echo # Bug mdev-463: assertion failure when running ANALYZE with RBR on +--echo # + +SET GLOBAL use_stat_tables = PREFERABLY; + +--connect (con1,localhost,root,,) +CREATE TABLE t1 (i INT) ENGINE=InnoDB; +ANALYZE TABLE t1; + +# Cleanup +DROP TABLE t1; +SET GLOBAL use_stat_tables = DEFAULT; +--disconnect con1 + -- cgit v1.2.1 From f4631d6f71c19a98eccf4998eccb49dd69897661 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 23 Aug 2012 11:22:26 -0700 Subject: Fixed bug mdev-473. With the new code of mysql-5.5 for metadata locking the function unlock_tables_n_open_system_tables_for_write should not explicitly unlock tables for which external locks have been set and should not explicitly reset thd->lock to 0. --- mysql-test/r/stat_tables.result | 11 +++++++++++ mysql-test/r/stat_tables_innodb.result | 11 +++++++++++ mysql-test/t/stat_tables.test | 15 +++++++++++++++ 3 files changed, 37 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 5d098bc9ef9..4cc486b10ef 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -342,4 +342,15 @@ o_orderkey p_partkey set optimizer_switch=@save_optimizer_switch; DROP DATABASE dbt3_s001; use test; +# +# Bug mdev-473: ANALYZE table locked for write +# +set use_stat_tables='complementary'; +create table t1 (i int); +lock table t1 write; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +alter table t1 add column a varchar(8); +drop table t1; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 2bdc618b566..250f24fee02 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -369,6 +369,17 @@ o_orderkey p_partkey set optimizer_switch=@save_optimizer_switch; DROP DATABASE dbt3_s001; use test; +# +# Bug mdev-473: ANALYZE table locked for write +# +set use_stat_tables='complementary'; +create table t1 (i int); +lock table t1 write; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +alter table t1 add column a varchar(8); +drop table t1; set use_stat_tables=@save_use_stat_tables; set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index 2ef915cf12c..67e66a52a6a 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -152,4 +152,19 @@ DROP DATABASE dbt3_s001; use test; +--echo # +--echo # Bug mdev-473: ANALYZE table locked for write +--echo # + +set use_stat_tables='complementary'; + +create table t1 (i int); + +lock table t1 write; +analyze table t1; +alter table t1 add column a varchar(8); + +drop table t1; + + set use_stat_tables=@save_use_stat_tables; -- cgit v1.2.1 From d0ad93fbc7eca575364e46f67c4613efb0807047 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 27 Aug 2012 14:19:25 -0700 Subject: Fixed bug mdev-487. The function collect_statistics_for_table() when scanning a table did not take into account that the handler function ha_rnd_next could return the code HA_ERR_RECORD_DELETE that should not be considered as an indication of an error. Also fixed a potential memory leak in this function. --- mysql-test/r/stat_tables.result | 11 +++++++++++ mysql-test/r/stat_tables_innodb.result | 11 +++++++++++ mysql-test/t/stat_tables.test | 13 +++++++++++++ 3 files changed, 35 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 4cc486b10ef..3cc650e7050 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -353,4 +353,15 @@ Table Op Msg_type Msg_text test.t1 analyze status Table is already up to date alter table t1 add column a varchar(8); drop table t1; +# +# Bug mdev-487: memory leak in ANALYZE with stat tables +# +SET use_stat_tables = 'preferably'; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +DELETE FROM t1 WHERE a=1; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 250f24fee02..bb0497ee331 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -380,6 +380,17 @@ Table Op Msg_type Msg_text test.t1 analyze status OK alter table t1 add column a varchar(8); drop table t1; +# +# Bug mdev-487: memory leak in ANALYZE with stat tables +# +SET use_stat_tables = 'preferably'; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +DELETE FROM t1 WHERE a=1; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; set use_stat_tables=@save_use_stat_tables; set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index 67e66a52a6a..3ef5b4e9b92 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -166,5 +166,18 @@ alter table t1 add column a varchar(8); drop table t1; +--echo # +--echo # Bug mdev-487: memory leak in ANALYZE with stat tables +--echo # + +SET use_stat_tables = 'preferably'; + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +DELETE FROM t1 WHERE a=1; + +ANALYZE TABLE t1; + +DROP TABLE t1; set use_stat_tables=@save_use_stat_tables; -- cgit v1.2.1 From cfde11fc4f02e701b856311769d70ccc47d16539 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 1 Sep 2012 23:51:47 -0700 Subject: Fixed bug mdev-503. If a table is already in the table cache but without data from persistent statistical tables then the function open_and_process_table should not only allocate memory for this statistical data in the corresponding TABLE_SHARE object, but also should copy the references to the data into certain fields of the TABLE data structure: for each key of the table KEY::read_stats should be copied, and for each column of the table Field::read_stats should be copied. --- mysql-test/r/stat_tables_disabled.result | 70 ++++++++++++++++++++++++++++ mysql-test/t/stat_tables_disabled.test | 78 ++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 mysql-test/r/stat_tables_disabled.result create mode 100644 mysql-test/t/stat_tables_disabled.test (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables_disabled.result b/mysql-test/r/stat_tables_disabled.result new file mode 100644 index 00000000000..f57abc34e0c --- /dev/null +++ b/mysql-test/r/stat_tables_disabled.result @@ -0,0 +1,70 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +select @@global.use_stat_tables; +@@global.use_stat_tables +NEVER +select @@session.use_stat_tables; +@@session.use_stat_tables +NEVER +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +# +# Bug mdev-503: optimizer ignores setting use_stat_tables='preferably' +# +flush tables +customer, lineitem, nation, orders, part, partsupp, region, supplier; +set use_stat_tables='never'; +EXPLAIN select sql_calc_found_rows straight_join +l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, +o_orderdate, o_shippriority +from orders, customer, lineitem +where c_mktsegment = 'BUILDING' and c_custkey = o_custkey +and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by l_orderkey, o_orderdate, o_shippriority +order by revenue desc, o_orderdate +limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL # Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey # Using where +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey # Using where +set use_stat_tables='preferably'; +EXPLAIN select sql_calc_found_rows straight_join +l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, +o_orderdate, o_shippriority +from orders, customer, lineitem +where c_mktsegment = 'BUILDING' and c_custkey = o_custkey +and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by l_orderkey, o_orderdate, o_shippriority +order by revenue desc, o_orderdate +limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +flush tables customer, orders, lineitem; +EXPLAIN select sql_calc_found_rows straight_join +l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, +o_orderdate, o_shippriority +from orders, customer, lineitem +where c_mktsegment = 'BUILDING' and c_custkey = o_custkey +and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by l_orderkey, o_orderdate, o_shippriority +order by revenue desc, o_orderdate +limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +# End of the test case for mdev-503 +set optimizer_switch=@save_optimizer_switch; +DROP DATABASE dbt3_s001; +use test; +set use_stat_tables=@save_use_stat_tables; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/stat_tables_disabled.test b/mysql-test/t/stat_tables_disabled.test new file mode 100644 index 00000000000..d42fed33014 --- /dev/null +++ b/mysql-test/t/stat_tables_disabled.test @@ -0,0 +1,78 @@ +--source include/have_innodb.inc + +SET SESSION STORAGE_ENGINE='InnoDB'; + +select @@global.use_stat_tables; +select @@session.use_stat_tables; + +set @save_use_stat_tables=@@use_stat_tables; + +set use_stat_tables='preferably'; + +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc +delete from mysql.table_stat; +delete from mysql.column_stat; +delete from mysql.index_stat; +ANALYZE TABLE +customer, lineitem, nation, orders, part, partsupp, region, supplier; +--enable_warnings +--enable_result_log +--enable_query_log + +--echo # +--echo # Bug mdev-503: optimizer ignores setting use_stat_tables='preferably' +--echo # + +flush tables +customer, lineitem, nation, orders, part, partsupp, region, supplier; + +let $Q3S= +select sql_calc_found_rows straight_join + l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, + o_orderdate, o_shippriority +from orders, customer, lineitem +where c_mktsegment = 'BUILDING' and c_custkey = o_custkey + and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by l_orderkey, o_orderdate, o_shippriority +order by revenue desc, o_orderdate +limit 10; + +set use_stat_tables='never'; +--replace_column 9 # +eval EXPLAIN $Q3S; + +set use_stat_tables='preferably'; +--replace_result 2 1 +eval EXPLAIN $Q3S; + +flush tables customer, orders, lineitem; +eval EXPLAIN $Q3S; + +--echo # End of the test case for mdev-503 + +set optimizer_switch=@save_optimizer_switch; + + +DROP DATABASE dbt3_s001; + +use test; + +set use_stat_tables=@save_use_stat_tables; + + +SET SESSION STORAGE_ENGINE=DEFAULT; -- cgit v1.2.1 From dab998d0e155edbd38b892eaa1478a9f4a0a85b1 Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Mon, 3 Sep 2012 22:01:52 +0400 Subject: Preliminary test case for MDEV-504 in order to reproduce the problem --- mysql-test/r/mdev-504.result | 21 +++++++++++++ mysql-test/t/mdev-504.test | 75 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 mysql-test/r/mdev-504.result create mode 100644 mysql-test/t/mdev-504.test (limited to 'mysql-test') diff --git a/mysql-test/r/mdev-504.result b/mysql-test/r/mdev-504.result new file mode 100644 index 00000000000..e178127cf2a --- /dev/null +++ b/mysql-test/r/mdev-504.result @@ -0,0 +1,21 @@ +CREATE TABLE A ( +pk INTEGER AUTO_INCREMENT PRIMARY KEY, +fdate DATE +) ENGINE=MyISAM; +CREATE PROCEDURE p_analyze() +BEGIN +DECLARE attempts INTEGER DEFAULT 100; +wl_loop: WHILE attempts > 0 DO +ANALYZE TABLE A; +SET attempts = attempts - 1; +END WHILE wl_loop; +END | +CREATE FUNCTION rnd3() RETURNS INT +BEGIN +RETURN ROUND(3 * RAND() + 0.5); +END | +SET GLOBAL use_stat_tables = PREFERABLY; +DROP TABLE A; +DROP PROCEDURE p_analyze; +DROP FUNCTION rnd3; +SET GLOBAL use_stat_tables = DEFAULT; diff --git a/mysql-test/t/mdev-504.test b/mysql-test/t/mdev-504.test new file mode 100644 index 00000000000..5193581cc47 --- /dev/null +++ b/mysql-test/t/mdev-504.test @@ -0,0 +1,75 @@ +CREATE TABLE A ( + pk INTEGER AUTO_INCREMENT PRIMARY KEY, + fdate DATE +) ENGINE=MyISAM; + +--delimiter | + +CREATE PROCEDURE p_analyze() +BEGIN + DECLARE attempts INTEGER DEFAULT 100; + wl_loop: WHILE attempts > 0 DO + ANALYZE TABLE A; + SET attempts = attempts - 1; + END WHILE wl_loop; +END | + +CREATE FUNCTION rnd3() RETURNS INT +BEGIN + RETURN ROUND(3 * RAND() + 0.5); +END | + +--delimiter ; + +SET GLOBAL use_stat_tables = PREFERABLY; + +--let $trial = 100 + +--disable_query_log +--disable_result_log +--disable_warnings +while ($trial) +{ + + --connect (con1,localhost,root,,) + --send CALL p_analyze() + + --connect (con2,localhost,root,,) + --send CALL p_analyze() + + --let $run = 100 + + while ($run) + { + --connect (con3,localhost,root,,) + + let $query = `SELECT CASE rnd3() + WHEN 1 THEN 'INSERT INTO A (pk) VALUES (NULL)' + WHEN 2 THEN 'DELETE FROM A LIMIT 1' + ELSE 'UPDATE A SET fdate = 2 LIMIT 1' END`; + --eval $query + --disconnect con3 + --dec $run + } + + --connection con2 + --reap + --disconnect con2 + --connection con1 + --reap + --disconnect con1 + + --dec $trial +} + +--enable_query_log +--enable_result_log +--enable_warnings + +# Cleanup +--connection default +DROP TABLE A; +DROP PROCEDURE p_analyze; +DROP FUNCTION rnd3; +SET GLOBAL use_stat_tables = DEFAULT; + -- cgit v1.2.1 From b3f09e8aa04aa3d2d2b86588eddd46badb7e916f Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 8 Sep 2012 12:04:31 -0700 Subject: Fixed bug mdev-504. Opening system statistical tables and reading statistical data from them for a regular table should be done after opening and locking this regular table. No test case is provided with this patch. --- mysql-test/t/stat_tables_par.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mysql-test') diff --git a/mysql-test/t/stat_tables_par.test b/mysql-test/t/stat_tables_par.test index 27507ccf811..1867316b268 100644 --- a/mysql-test/t/stat_tables_par.test +++ b/mysql-test/t/stat_tables_par.test @@ -40,7 +40,7 @@ select * from mysql.index_stat; # assumes that start the code of memory allocation for stats data has this line: # # DEBUG_SYNC(thd, "statistics_mem_alloc_start1"); -# DEBUG_SYNC(thd, "statistics_mem_alloc-start2"); +# DEBUG_SYNC(thd, "statistics_mem_alloc_start2"); # let $Q6= -- cgit v1.2.1 From ff36e9fc518a4f8b463a09aeb9499c4552a27534 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 10 Sep 2012 22:22:57 -0700 Subject: Fixed bug mdev-485. RBR should be turned off when statistical tables are modified in the result of the execution of a DDL statement. Revised the fix for bug mdev-463. Ensured suppression of RBR for the modifications of the statistical tables triggered by the execution of any analyze operation. --- mysql-test/r/stat_tables_rbr.result | 15 ++++++++++ mysql-test/r/stat_tables_repl.result | 41 +++++++++++++++++++++++++ mysql-test/t/stat_tables_rbr.test | 12 ++++++++ mysql-test/t/stat_tables_repl.test | 58 ++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 mysql-test/r/stat_tables_repl.result create mode 100644 mysql-test/t/stat_tables_repl.test (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables_rbr.result b/mysql-test/r/stat_tables_rbr.result index 7a0d23193e7..0bcf5e9cb93 100644 --- a/mysql-test/r/stat_tables_rbr.result +++ b/mysql-test/r/stat_tables_rbr.result @@ -8,3 +8,18 @@ Table Op Msg_type Msg_text test.t1 analyze status OK DROP TABLE t1; SET GLOBAL use_stat_tables = DEFAULT; +SET use_stat_tables = PREFERABLY; +CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2; +ALTER TABLE t1 ANALYZE PARTITION p1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SHOW BINLOG EVENTS; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 4 Format_desc 1 245 Server ver: 5.5.27-MariaDB-debug-log, Binlog ver: 4 +master-bin.000001 245 Query 1 345 use `test`; CREATE TABLE t1 (i INT) ENGINE=InnoDB +master-bin.000001 345 Query 1 424 use `test`; ANALYZE TABLE t1 +master-bin.000001 424 Query 1 528 use `test`; DROP TABLE `t1` /* generated by server */ +master-bin.000001 528 Query 1 664 use `test`; CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2 +master-bin.000001 664 Query 1 762 use `test`; ALTER TABLE t1 ANALYZE PARTITION p1 +SET use_stat_tables = DEFAULT; +DROP TABLE t1; diff --git a/mysql-test/r/stat_tables_repl.result b/mysql-test/r/stat_tables_repl.result new file mode 100644 index 00000000000..370b8c59db1 --- /dev/null +++ b/mysql-test/r/stat_tables_repl.result @@ -0,0 +1,41 @@ +include/master-slave.inc +[connection master] +# +# Bug mdev-485: unexpected failure with replication of DROP/ALTER table +# when RBR is on +# +CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP INDEX idx1 ON t1; +DROP TABLE t1; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +ALTER TABLE t1 DROP COLUMN b; +DROP TABLE t1; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +ALTER TABLE t1 RENAME to s; +DROP TABLE s; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +ALTER TABLE t1 CHANGE COLUMN b c int ; +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/t/stat_tables_rbr.test b/mysql-test/t/stat_tables_rbr.test index 5297bccf2f4..9b08357f36e 100644 --- a/mysql-test/t/stat_tables_rbr.test +++ b/mysql-test/t/stat_tables_rbr.test @@ -1,5 +1,6 @@ --source include/have_binlog_format_row.inc --source include/have_innodb.inc +--source include/have_partition.inc --echo # --echo # Bug mdev-463: assertion failure when running ANALYZE with RBR on @@ -16,3 +17,14 @@ DROP TABLE t1; SET GLOBAL use_stat_tables = DEFAULT; --disconnect con1 +--connection default + +SET use_stat_tables = PREFERABLY; + +CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2; +ALTER TABLE t1 ANALYZE PARTITION p1; +SHOW BINLOG EVENTS; + +SET use_stat_tables = DEFAULT; + +DROP TABLE t1; diff --git a/mysql-test/t/stat_tables_repl.test b/mysql-test/t/stat_tables_repl.test new file mode 100644 index 00000000000..999c49d37cf --- /dev/null +++ b/mysql-test/t/stat_tables_repl.test @@ -0,0 +1,58 @@ +--source include/have_stat_tables.inc +--source include/master-slave.inc +--source include/have_binlog_format_row.inc + +--echo # +--echo # Bug mdev-485: unexpected failure with replication of DROP/ALTER table +--echo # when RBR is on +--echo # + +CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +DROP TABLE t1; + +--sync_slave_with_master +--connection master + +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +DROP INDEX idx1 ON t1; + +--sync_slave_with_master +--connection master + +DROP TABLE t1; + +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +ALTER TABLE t1 DROP COLUMN b; + +--sync_slave_with_master +--connection master + +DROP TABLE t1; + +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +ALTER TABLE t1 RENAME to s; + +--sync_slave_with_master +--connection master + +DROP TABLE s; + +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +ALTER TABLE t1 CHANGE COLUMN b c int ; + +--sync_slave_with_master +--connection master + +DROP TABLE t1; + +--source include/rpl_end.inc -- cgit v1.2.1 From 2bbcec41488ff4506cb848357086e8fb07a9648c Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 11 Sep 2012 22:36:04 -0700 Subject: Fixed bug mdev-518. If some statistical tables are corrupted the server should use the conventional statistical data. --- mysql-test/r/stat_tables.result | 16 ++++++++++++++++ mysql-test/r/stat_tables_innodb.result | 16 ++++++++++++++++ mysql-test/t/stat_tables.test | 24 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index 3cc650e7050..169266fea25 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -364,4 +364,20 @@ ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status OK DROP TABLE t1; +# +# Bug mdev-518: corrupted/missing statistical tables +# +CREATE TABLE t1 (i int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +FLUSH TABLE t1; +SET use_stat_tables='never'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +FLUSH TABLES; +SET use_stat_tables='preferably'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +DROP TABLE t1; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index bb0497ee331..699df08225e 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -391,6 +391,22 @@ ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status OK DROP TABLE t1; +# +# Bug mdev-518: corrupted/missing statistical tables +# +CREATE TABLE t1 (i int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +FLUSH TABLE t1; +SET use_stat_tables='never'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +FLUSH TABLES; +SET use_stat_tables='preferably'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +DROP TABLE t1; set use_stat_tables=@save_use_stat_tables; set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index 3ef5b4e9b92..e3712c8d022 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -180,4 +180,28 @@ ANALYZE TABLE t1; DROP TABLE t1; +--echo # +--echo # Bug mdev-518: corrupted/missing statistical tables +--echo # + +CREATE TABLE t1 (i int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); + +FLUSH TABLE t1; +SET use_stat_tables='never'; +EXPLAIN SELECT * FROM t1; + +--move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD.save + +FLUSH TABLES; +SET use_stat_tables='preferably'; +--disable_warnings +EXPLAIN SELECT * FROM t1; +--enable_warnings + +# Cleanup +--move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD.save $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD +DROP TABLE t1; + set use_stat_tables=@save_use_stat_tables; + -- cgit v1.2.1 From 32443e744d354fbba93c8761486462b5820b74bb Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 12 Sep 2012 15:33:03 -0700 Subject: Made the results from the stat_tables_rbr test to be not dependent on the debug mode. --- mysql-test/r/stat_tables_rbr.result | 2 +- mysql-test/t/stat_tables_rbr.test | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'mysql-test') diff --git a/mysql-test/r/stat_tables_rbr.result b/mysql-test/r/stat_tables_rbr.result index 0bcf5e9cb93..05c5d378bab 100644 --- a/mysql-test/r/stat_tables_rbr.result +++ b/mysql-test/r/stat_tables_rbr.result @@ -15,7 +15,7 @@ Table Op Msg_type Msg_text test.t1 analyze status OK SHOW BINLOG EVENTS; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 4 Format_desc 1 245 Server ver: 5.5.27-MariaDB-debug-log, Binlog ver: 4 +master-bin.000001 4 Format_desc 1 245 Server ver: #, Binlog ver: # master-bin.000001 245 Query 1 345 use `test`; CREATE TABLE t1 (i INT) ENGINE=InnoDB master-bin.000001 345 Query 1 424 use `test`; ANALYZE TABLE t1 master-bin.000001 424 Query 1 528 use `test`; DROP TABLE `t1` /* generated by server */ diff --git a/mysql-test/t/stat_tables_rbr.test b/mysql-test/t/stat_tables_rbr.test index 9b08357f36e..4336c02c34b 100644 --- a/mysql-test/t/stat_tables_rbr.test +++ b/mysql-test/t/stat_tables_rbr.test @@ -23,6 +23,7 @@ SET use_stat_tables = PREFERABLY; CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2; ALTER TABLE t1 ANALYZE PARTITION p1; +--replace_regex /\/\* xid=.* \*\//\/* XID *\// /Server ver: .*, Binlog ver: .*/Server ver: #, Binlog ver: #/ /table_id: [0-9]+/table_id: #/ SHOW BINLOG EVENTS; SET use_stat_tables = DEFAULT; -- cgit v1.2.1