在查询INFORMATION_SCHEMA.STATISTICS索引名称时,我看到了一些奇怪的结果。当我做“SELECT * ...”时,我看到2个索引,但是“SELECT COUNT(*)...”它表示count(*)为0.任何人都知道为什么?有没有更好的方法来获取表上的索引,理想情况下不是特定于MySQL的?
示例:
mysql> SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE
table_schema = 'mifostest' AND table_name ='CUSTOMER' AND INDEX_NAME =
'CUSTOMER_BRANCH_SEARCH_IDX';
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
...然而
mysql> SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema =
'mifostest' AND table_name ='CUSTOMER' AND INDEX_NAME =
'CUSTOMER_BRANCH_SEARCH_IDX'\G
*************************** 1. row ***************************
TABLE_CATALOG: NULL
TABLE_SCHEMA: mifostest
TABLE_NAME: CUSTOMER
NON_UNIQUE: 1
INDEX_SCHEMA: mifostest
INDEX_NAME: CUSTOMER_BRANCH_SEARCH_IDX
SEQ_IN_INDEX: 1
COLUMN_NAME: BRANCH_ID
COLLATION: A
CARDINALITY: 0
SUB_PART: NULL
PACKED: NULL
NULLABLE: YES
INDEX_TYPE: BTREE
COMMENT:
*************************** 2. row ***************************
TABLE_CATALOG: NULL
TABLE_SCHEMA: mifostest
TABLE_NAME: CUSTOMER
NON_UNIQUE: 1
INDEX_SCHEMA: mifostest
INDEX_NAME: CUSTOMER_BRANCH_SEARCH_IDX
SEQ_IN_INDEX: 2
COLUMN_NAME: SEARCH_ID
COLLATION: A
CARDINALITY: 0
SUB_PART: NULL
PACKED: NULL
NULLABLE: YES
INDEX_TYPE: BTREE
COMMENT:
2 rows in set (0.00 sec)
更多信息:
谢谢! - 亚当
答案 0 :(得分:2)
ANSI / ISO SQL标准没有任何关于索引的说法,所以我怀疑有一种“不是MySQL特定的”方式来查询它们。标准的INFORMATION_SCHEMA包括许多基表中的CONSTRAINTS,ASSERTIONS和KEY_COLUMN_USAGE,但索引没有任何内容。我甚至没有在标准中提到过STATISTICS。
你报告的内容对我来说听起来像个错误。如果SELECT *返回行,则SELECT COUNT(*)不应返回零。也许有this bug的回归。