在 PostgreSQL 中,我们如何判断表的每个索引是否是聚簇的?
这对应于在MySQL中,我们如何判断表的索引是否是聚集索引? https://stackoverflow.com/questions/51182951/in-mysql-how-can-we-tell-if-an-index-of-a-table-is-clustered-or-not
Thanks.
Postgres 不支持像 MySql 那样的聚集索引。可能有一个用于对表进行聚簇的索引。您可以通过查询该列来检查这一点indisclustered
在系统目录中pg_index。 https://www.postgresql.org/docs/current/static/catalog-pg-index.html
indisclustered - 如果为 true,则表最后在此索引上聚集
Example:
create table my_table(id serial primary key, str text unique);
select relname, indisclustered
from pg_index i
join pg_class c on c.oid = indexrelid
where indrelid = 'public.my_table'::regclass
relname | indisclustered
------------------+----------------
my_table_str_key | f
my_table_pkey | f
(2 rows)
cluster my_table using my_table_str_key;
select relname, indisclustered
from pg_index i
join pg_class c on c.oid = indexrelid
where indrelid = 'public.my_table'::regclass
relname | indisclustered
------------------+----------------
my_table_str_key | t
my_table_pkey | f
(2 rows)
阅读有关的文档CLUSTER: https://www.postgresql.org/docs/current/static/sql-cluster.html
当表被聚集时,它会根据索引信息进行物理重新排序。集群是一种一次性操作:当表随后更新时,更改不会集群。也就是说,不会尝试根据索引顺序存储新的或更新的行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)