Planet PostgreSQL

Planet PostgreSQL -

Anthony Sotolongo León: Limitations in Postgres Index definition

Introduction Indexes are a core RDBMS component and Postgres ain’t an exception. Furthermore, Postgres indexing capabilities aren’t tied to the available native-supported mechanisms. Aside from the available 6 types of native indexes (B-tree, Hash, GiST, SP-GiST, GIN, BRIN) it is even possible to extend index capabilities using the Access Method Extensions Interface for customizing and building your own. There is a subcategory of index types that are classified according to their expressions and definitions, and they can use custom operators to extend the usage of more advanced data types. Those subcategories can be Multicolumn, Unique, Expressional, Partial, and Covering Indexes. Note: It is possible to implement other types of indexes and add them to PostgreSQL as extensions for example: https://www.postgresql.org/docs/current/bloom.html or https://github.com/postgrespro/rum Nevertheless, under certain circumstances, there are certain limitations on index definitions. This is precisely the objective of the current blog: to show under what circumstances you can not create indexes. Index functions must be IMMUTABLE The following error is very likely to be the most common one of this type of restriction, and it is in response to the restriction that when you use a function in an index expression, this function must be IMMUTABLE, this is one of “Function Volatility Categories”, please read the documentation to understand the differences between categories. mydatabase=>CREATE INDEX CONCURRENTLY idx_test on table_test (test_id, to_char(create_time, 'YYYY-MM-DD') ); ERROR: functions in index expression must be marked IMMUTABLE If it describes the to_char function is possible to see that this function is marked as STABLE mydatabase=>\df+ to_char Schema | pg_catalog Name | to_char Result data type | text Argument data types | timestamp with time zone, text Type | func Volatility | stable Parallel | safe Owner [...]

本文介绍了PostgreSQL索引定义的限制,包括函数必须是IMMUTABLE的,不能索引系统列、目录表和FDW表等。建议在数据库设计和查询中注意这些限制,以避免性能问题。

IMMUTABLE PostgreSQL postgres 性能问题 索引 限制

相关推荐 去reddit讨论

热榜 Top10

最近读过

  1. Anthony Sotolongo León: Limitations in Postgres Index definition - 约读过
  2. MicroBlocks 无线编程(BLE) - 约读过
  3. 3 predictions for open source in confidential computing - 约读过
  4. Michael Paquier: Postgres - Fun with LWLocks - 约读过
  5. 恶意挖矿木马防范指南 - 约读过
  6. 2024 年邯郸少年杀人案: 勿以恶小而为之 - 约读过
  7. 可解释的医学诊断变压器原型 - 约读过
  8. DVWA靶场命令注入高级源码分析详解 - 约读过
  9. sessionStorage:提供浏览会话数据的存储 - 约读过
  10. Scaleway IPV6 server 申请及使用攻略 - 约读过
Dify.AI
Dify.AI
eolink
eolink
观测云
观测云
LigaAI
LigaAI

推荐或自荐