比如这个表
create table user(
id int primary key,
age int,
height int,
weight int,
name varchar(32)
)engine = innoDb;
创建一个联合索引:
create index idx_obj on user(age asc,height asc,weight asc)
我想看一下这个表中每一条数据对应的具体的索引值是多少? 怎么搞?
我试过用命令
mysql> SELECT * FROM mysql.innodb_index_stats a WHERE a.database_name = 'learn_sql' and a.table_name like '%user%';
+---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+
| database_name | table_name | index_name | last_update | stat_name | stat_value | sample_size | stat_description |
+---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+
| learn_sql | user | PRIMARY | 2019-12-13 10:18:16 | n_diff_pfx01 | 5 | 1 | id |
| learn_sql | user | PRIMARY | 2019-12-13 10:18:16 | n_leaf_pages | 1 | NULL | Number of leaf pages in the index |
| learn_sql | user | PRIMARY | 2019-12-13 10:18:16 | size | 1 | NULL | Number of pages in the index |
| learn_sql | user | idx_obj | 2019-12-13 15:47:28 | n_diff_pfx01 | 4 | 1 | age |
| learn_sql | user | idx_obj | 2019-12-13 15:47:28 | n_diff_pfx02 | 5 | 1 | age,height |
| learn_sql | user | idx_obj | 2019-12-13 15:47:28 | n_diff_pfx03 | 5 | 1 | age,height,weight |
| learn_sql | user | idx_obj | 2019-12-13 15:47:28 | n_diff_pfx04 | 5 | 1 | age,height,weight,id |
| learn_sql | user | idx_obj | 2019-12-13 15:47:28 | n_leaf_pages | 1 | NULL | Number of leaf pages in the index |
| learn_sql | user | idx_obj | 2019-12-13 15:47:28 | size | 1 | NULL | Number of pages in the index |
+---------------+------------+------------+---------------------+--------------+------------+-------------+-----------------------------------+
9 rows in set (0.00 sec)
mysql>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.