怎么理解PostgreSQL的PG Index Properties
本篇内容介绍了“怎么理解PostgreSQL的PG Index Properties”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
在PostgreSQL 9.6之后,PG提供了三个函数来判定Index AM/Index/Index Column是否具备某些属性,包括pg_indexam_has_property/pg_index_has_property/pg_index_column_has_property.
pg_indexam_has_property
test whether an index access method has a specified property
下面是本机AM的查询结果,其中heap是堆AM/blackhole_am是先前介绍过的黑洞AM.
testdb=#selecta.amname,p.name,pg_indexam_has_property(a.oid,p.name)testdb-#frompg_ama,testdb-#unnest(array['can_order','can_unique','can_multi_col','can_exclude'])p(name)testdb-#orderbya.amname;amname|name|pg_indexam_has_property--------------+---------------+-------------------------blackhole_am|can_unique|blackhole_am|can_exclude|blackhole_am|can_multi_col|blackhole_am|can_order|brin|can_order|fbrin|can_exclude|fbrin|can_multi_col|tbrin|can_unique|fbtree|can_order|tbtree|can_unique|tbtree|can_multi_col|tbtree|can_exclude|tgin|can_unique|fgin|can_order|fgin|can_multi_col|tgin|can_exclude|fgist|can_unique|fgist|can_multi_col|tgist|can_exclude|tgist|can_order|fhash|can_order|fhash|can_unique|fhash|can_multi_col|fhash|can_exclude|theap|can_multi_col|heap|can_unique|heap|can_order|heap|can_exclude|spgist|can_multi_col|fspgist|can_exclude|tspgist|can_unique|fspgist|can_order|f(32rows)
PostgreSQL根据上述属性判断在创建索引时指定的option,如Hash索引不能是唯一索引(hash | can_unique | f):
testdb=#createuniqueindexidx_t_idx1_idont_idx1usinghash(id);psql:ERROR:accessmethod"hash"doesnotsupportuniqueindexes
pg_index_has_property
test whether an index has a specified property
创建hash索引,查询该索引的相关属性
testdb=#createindexidx_t_idx1_idont_idx1usinghash(id);CREATEINDEXtestdb=#selectp.name,pg_index_has_property('idx_t_idx1_id'::regclass,p.name)testdb-#fromunnest(array[testdb(#'clusterable','index_scan','bitmap_scan','backward_scan'testdb(#])p(name);name|pg_index_has_property---------------+-----------------------clusterable|findex_scan|tbitmap_scan|tbackward_scan|t(4rows)
pg_index_column_has_property
test whether an index column has a specified property
查询hash索引列的相关属性(全为f - false)
testdb=#selectp.name,testdb-#pg_index_column_has_property('idx_t_idx1_id'::regclass,1,p.name)testdb-#fromunnest(array[testdb(#'asc','desc','nulls_first','nulls_last','orderable','distance_orderable',testdb(#'returnable','search_array','search_nulls'testdb(#])p(name);name|pg_index_column_has_property--------------------+------------------------------asc|fdesc|fnulls_first|fnulls_last|forderable|fdistance_orderable|freturnable|fsearch_array|fsearch_nulls|f(9rows)
“怎么理解PostgreSQL的PG Index Properties”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。