drop table if exists t1,t2; set @save_use_stat_tables=@@use_stat_tables; DELETE FROM mysql.table_stat; DELETE FROM mysql.column_stat; DELETE FROM mysql.index_stat; set 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) ) ENGINE= MYISAM; 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 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 SELECT COUNT(*) FROM t1; COUNT(*) 40 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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; 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 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 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 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 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 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 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 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 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; ANALYZE TABLE t2; Table Op Msg_type Msg_text test.t2 analyze status OK SELECT * FROM mysql.table_stat; db_name table_name cardinality test t1 40 test t2 40 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 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 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 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 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 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 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 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 use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; SELECT UPPER(db_name), UPPER(table_name), cardinality 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 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 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 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 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 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 use_stat_tables='preferably'; ANALYZE TABLE Country, City, CountryLanguage; SELECT UPPER(db_name), UPPER(table_name), cardinality FROM mysql.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 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 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 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 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; 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 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; set use_stat_tables=@save_use_stat_tables;