Optimization of partial index creation for a new column

From: Александр Асафов <asafofalexander(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Optimization of partial index creation for a new column
Date: 2025-12-14 20:13:49
Message-ID: CAFscNDDjy-HsfiZuQi8MhPof5200P8u-Ye4=jhvWp6YLmvYs1w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello hackers,
I have a feature suggestion to optimize the creation of a partial
index. In some cases, it is possible to skip a full table scan. For
example:

BEGIN;
ALTER TABLE test ADD COLUMN (newcol int);
CREATE INDEX newindex ON test(newcol) WHERE newcol IS NOT NULL;
COMMIT;

In this case, the values of all columns in the new table will be NULL,
and there is no point in checking the conditions for each row. The
same optimization can be done for default values in NOT NULL columns.

How complex would a patch with this optimization be? Will it be
necessary to add any attributes to the table metadata, or can we check
that the previous command was CREATE TABLE when creating an index?

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sadeq Dousti 2025-12-14 21:05:21 Re: psql \dh: List High-Level (Root) Tables and Indexes
Previous Message Corey Huinker 2025-12-14 20:01:35 Re: Import Statistics in postgres_fdw before resorting to sampling.