Re: support create index on virtual generated column.

From: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, chengpeng_yan <chengpeng_yan(at)outlook(dot)com>, guofenglinux <guofenglinux(at)gmail(dot)com>, 我自己的邮箱 <44973863(at)qq(dot)com>
Subject: Re: support create index on virtual generated column.
Date: 2026-07-22 13:02:27
Message-ID: tencent_0C0B9EAACD88167CA2FCFBC2128B9AA1D105@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>Hi everyone,
>
>While revisiting the discussion for `CF6749 — Disallow whole-row index references with virtual generated columns? `
>Based on version V7, I’ve added support for whole-row references within partial indexes, attached V8 patch.
>
>There is one point I may have overlooked: the current implementation appears to only work for btree indexes.
>
>I welcome everyone’s thoughts and look forward to your feedback.
>
>Below are the test results:
>-- test creation of a predicate index with a whole-row expression
>DROP TABLE IF EXISTS test_pg_wholerow;
>NOTICE: table "test_pg_wholerow" does not exist, skipping
>CREATE TABLE test_pg_wholerow(a int, b int GENERATED ALWAYS AS (a * 2) VIRTUAL, c text);
>CREATE UNIQUE INDEX test_pg_wholerow_pred_idx ON test_pg_wholerow(a) WHERE test_pg_wholerow IS NOT NULL;
>INSERT INTO test_pg_wholerow(a,c) SELECT NULL, NULL FROM generate_series(1, 1000);
>INSERT INTO test_pg_wholerow(a,c) SELECT 1, '1';
>ANALYZE test_pg_wholerow;
>SELECT relname,reltuples FROM pg_catalog.pg_class WHERE relname IN ('test_pg_wholerow', 'test_pg_wholerow_pred_idx') ORDER BY OID;
> relname | reltuples
>---------------------------+-----------
> test_pg_wholerow | 1001
> test_pg_wholerow_pred_idx | 1
>(2 rows)
>
>EXPLAIN (COSTS OFF) SELECT * FROM test_pg_wholerow WHERE test_pg_wholerow IS NOT NULL;
> QUERY PLAN
>----------------------------------------------------------------
> Index Scan using test_pg_wholerow_pred_idx on test_pg_wholerow
>(1 row)
>
>EXPLAIN (COSTS OFF) SELECT a FROM test_pg_wholerow WHERE test_pg_wholerow IS NOT NULL;
> QUERY PLAN
>---------------------------------------------------------------------
> Index Only Scan using test_pg_wholerow_pred_idx on test_pg_wholerow
>(1 row)
>
>EXPLAIN (COSTS OFF) SELECT a,b FROM test_pg_wholerow WHERE test_pg_wholerow IS NOT NULL;
> QUERY PLAN
>---------------------------------------------------------------------
> Index Only Scan using test_pg_wholerow_pred_idx on test_pg_wholerow
>(1 row)
>
>
>regards,
>--
>ZizhuanLiu (X-MAN)
>44973863(at)qq(dot)com

Hi, everyone

Rebase V8 to V9.

regards,
--
ZizhuanLiu (X-MAN) 
44973863(at)qq(dot)com

Attachment Content-Type Size
v9-0001-v9-enhance-index-support-for-virtual-generated-co.patch application/octet-stream 59.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-07-22 13:06:44 Re: convert various variables to atomics
Previous Message Fujii Masao 2026-07-22 12:59:25 Incorrect check in 037_except.pl?