BUG #18637: CREATE INDEX won't look up operator classes in search_path if PARTITION BY is specified

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: usamoi(at)outlook(dot)com
Subject: BUG #18637: CREATE INDEX won't look up operator classes in search_path if PARTITION BY is specified
Date: 2024-09-27 14:31:54
Message-ID: 18637-f51e314546e3ba2a@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18637
Logged by: CREATE INDEX won&#x27;t look up operator classes in search_path if PARTITION BY
is specified
Email address: usamoi(at)outlook(dot)com
PostgreSQL version: 17.0
Operating system: Linux 6.10
Description:

This SQL works in PostgreSQL 16.4 but not in PostgreSQL 17.0. Here
`vector_l2_ops` is an operator class in schema `vectors`.
```
SET search_path TO public, vectors;
CREATE TABLE items (val vector(3), category_id int) PARTITION BY
LIST(category_id);
CREATE TABLE id_123 PARTITION OF items FOR VALUES IN (1, 2, 3);
CREATE TABLE id_456 PARTITION OF items FOR VALUES IN (4, 5, 6);
CREATE TABLE id_789 PARTITION OF items FOR VALUES IN (7, 8, 9);
CREATE INDEX ON items USING vectors (val vector_l2_ops);
```
The error message is: `ERROR: operator class "vector_l2_ops" does not exist
for access method "vectors"`

If I do not use PARTITION BY and CREATE TABLE OF, it works and the message
is `CREATE INDEX`.

After debugging, I find that `DefineIndex` would call `RestrictSearchPath`
in `indexcmds.c:1234` and `indexcmds.c:1334` before entering recursion, so
that the nested `DefineIndex` would be only able to look up operator classes
in `pg_catalog, pg_temp`.

Since the behavior between `CREATE INDEX` and `CREATE INDEX PARTITION BY` is
different, it should be a bug.

Browse pgsql-bugs by date

  From Date Subject
Next Message Dean Rasheed 2024-09-27 15:06:12 Re: BUG #18634: Wrong varnullingrels with merge ... when not matched by source
Previous Message Laurenz Albe 2024-09-27 14:00:08 Re: BUG #18636: I am seeing a difference in behavior between 13.12 and 15.6 for full text searching