| From: | Chauhan Dhruv <chauhandhruv351(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Cc: | tgl(at)sss(dot)pgh(dot)pa(dot)us, "robertmhaas(at)gmail(dot)com" <robertmhaas(at)gmail(dot)com> |
| Subject: | Expression index can get an empty generated column name |
| Date: | 2026-07-27 19:27:43 |
| Message-ID: | CANWwWcp_DCJjq8pomeqp6W=fbygvzXXQO028VDJ9_6sLPjQnVA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
If you CREATE INDEX on an expression without naming the index, Postgres
generates a name for the index column from that expression. For some
expressions the generated name comes out empty, so the index column is
left with an empty attname.
Example (a whole-row reference):
CREATE TABLE t (a int, b int);
CREATE INDEX ON t ((t IS NOT NULL));
SELECT attname, length(attname)
FROM pg_attribute
WHERE attrelid = 't__idx'::regclass AND attnum = 1;
attname | length
---------+--------
| 0
(1 row)
The index is named "t__idx" -- the doubled underscore is where the
empty column name landed.
Cause: ChooseIndexExpressionName() builds the name from the Vars,
Consts, and function names in the expression. A whole-row Var is
skipped and a punctuation-only Const is stripped away, so such
expressions contribute no text and the result is empty. Before commit
181b6185c7, expression columns were always named "expr" (giving
"t_expr_idx" here).
Fix (attached): if the walk finds nothing usable, fall back to "expr".
Ordinary expressions are unaffected. Includes a regression test; make
check is green. Against the master.
Patch is attached.
Thanks,
Dhruv Chauhan
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Avoid-generating-an-empty-name-for-an-expression-.patch | text/x-patch | 3.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Euler Taveira | 2026-07-27 19:36:39 | doc: fast access to server parameters |
| Previous Message | solai v | 2026-07-27 19:25:11 | Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass |