PostgreSQL Indexes on Partition tables
When we CREATE INDEX
in a partitioned table, PostgreSQL automatically "recursively" creates the same index on all its partitions.
As this operation could take a while we can specify the ONLY
parameter to the main table index to avoid the index to be created on all partitions and later creating the same index on each partition individually.
CREATE INDEX index_users_on_country ON ONLY users USING btree (country);
CREATE INDEX users_shard_0_country_idx ON users_shard_0 USING btree (country);
CREATE INDEX users_shard_1_country_idx ON users_shard_0 USING btree (country);
Tweet