Commit df1fab9d authored by unknown's avatar unknown
Browse files

Fix for BUG#7519: Index statistics is not displayed after ANALYZE for temporary tables:

Call file->extra() with HA_STATUS_CONST in mysqld_show_keys.
The fix will not be merged into 4.1/5.0 because they don't have this problem already.


mysql-test/r/show_check.result:
  Testcase for BUG#7519
mysql-test/t/show_check.test:
  Testcase for BUG#7519
sql/sql_show.cc:
  Fix for BUG#7519: Index statistics is not displayed after ANALYZE for temporary tables:
  When handling "SHOW INDEX" the call file->extra(HA_STATUS_CONST | ...) is made for regular tables 
  but bypassed for temporary tables. 
  Call file->extra() with HA_STATUS_CONST in mysqld_show_keys to make sure we're always using the 
  current index cardinality values.
parent d4ac4cb1
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -233,3 +233,25 @@ c decimal(4,3) YES NULL
d	double(4,3)	YES		NULL	
f	float(4,3)	YES		NULL	
drop table t1;
CREATE TABLE t1 ( a VARCHAR(20) );
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
CREATE TEMPORARY TABLE t2 ( index (a(20)) ) SELECT a FROM t1 GROUP BY a;
SHOW INDEX FROM t2;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
t2	X	a	X	X	X	NULL	X	X	X	BTREE	
ANALYZE TABLE t2;
Table	Op	Msg_type	Msg_text
test.t2	analyze	status	OK
SHOW INDEX FROM t2;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
t2	X	a	X	X	X	5	X	X	X	BTREE	
SHOW CREATE TABLE t2;
Table	Create Table
t2	CREATE TEMPORARY TABLE `t2` (
  `a` varchar(20) default NULL,
  KEY `a` (`a`)
) TYPE=MyISAM
SHOW INDEX FROM t2;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
t2	X	a	X	X	X	5	X	X	X	BTREE	
DROP TEMPORARY TABLE t2;
+16 −0
Original line number Diff line number Diff line
@@ -131,3 +131,19 @@ drop table t1;
create table t1 (c decimal(3,3), d double(3,3), f float(3,3));
show columns from t1;
drop table t1;

# Fix for BUG#7519: For temporary tables, SHOW INDEX doesn't display index 
# cardinality after ANALYZE.
CREATE TABLE t1 ( a VARCHAR(20) );
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
CREATE TEMPORARY TABLE t2 ( index (a(20)) ) SELECT a FROM t1 GROUP BY a;
--replace_column 2 X 4 X 5 X 6 X 8 X 9 X 10 X 
SHOW INDEX FROM t2;
ANALYZE TABLE t2;
--replace_column 2 X 4 X 5 X 6 X 8 X 9 X 10 X 
SHOW INDEX FROM t2;
SHOW CREATE TABLE t2;
--replace_column 2 X 4 X 5 X 6 X 8 X 9 X 10 X 
SHOW INDEX FROM t2;
DROP TEMPORARY TABLE t2;
+2 −1
Original line number Diff line number Diff line
@@ -686,7 +686,8 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list)

  String *packet= &thd->packet;
  KEY *key_info=table->key_info;
  table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
  table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME | 
                    HA_STATUS_CONST);
  for (uint i=0 ; i < table->keys ; i++,key_info++)
  {
    KEY_PART_INFO *key_part= key_info->key_part;