Feed: Planet PostgreSQL.
This blog is about my work on the Postgres open source
database, and is published on Planet PostgreSQL.
PgLife allows monitoring of
all Postgres community activity.
Global Indexes
Wednesday, July 1, 2020
Postgres indexes can only be defined on single tables. Why would you want to have indexes that reference multiple tables, i.e., global indexes?
This email covers some of the reasons why global indexes can be useful. One big use-case is
the ability to create indexes on partitioned tables that index all its child tables, rather than requiring a separate index on each child
table. This would allow references to partitioned tables as foreign keys without requiring the partition key to be part of the foreign key
reference; Postgres 12 allows such foreign keys if they match partition keys.
A second use-case for global indexes is the ability to add a uniqueness constraint to a partitioned table where the unique columns are not part of the partition key. A third use-case is the ability to
index values that only appear in a few partitions, and are not part of the partition key. A global index would avoid having to check each partition table’s index for the desired value.
It is still unclear if these use-cases justify the architectural changes needed to enable global indexes. Some of these features can be simulated using triggers and user lookup tables. A large global
index might also reintroduce problems that prompted the creation of partitioning in the first place.