Get index direction from information schema in MySQL

若如初见. 提交于 2020-06-26 05:56:51

问题


Suppose I created index with descending order

CREATE INDEX `MyTable.MyIndex`
USING BTREE ON `MyTable` (`DateFrom` DESC, `DateTo` DESC);

I want to get information about it from information_schema.

According to documentation information_schema.statistics table does the job. However I can't find any information about column order for indexes (i.e. ASC or DESC).

How can I find that information?


回答1:


Where is it written in the documentation that the table statistics does the job ?

Furthermore, I found in the create index doc this:

An index_col_name specification can end with ASC or DESC.
These keywords are permitted for future extensions for specifying ascending or descending index value storage.
Currently, they are parsed but ignored; index values are always stored in ascending order.




回答2:


try this query ....

SELECT   non_unique,
         index_name,
         seq_in_index,
         column_name,
         collation,
         cardinality,
         sub_part,
         packed,
         nullable,
         index_type,
         comment
FROM     information_schema.STATISTICS
WHERE    table_schema = schema()
AND      table_name   = 'MyTable'
ORDER BY index_name,
         seq_in_index


来源:https://stackoverflow.com/questions/10947197/get-index-direction-from-information-schema-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!