From: ritojoao (@ritojoao) <noreply+ritojoao@github.com>
To: reorg/pg_repack <noreply+reorg-pg_repack@github.com>
Subject: Re: [reorg/pg_repack] PR #493: Use format() and pg_catalog-qualified catalog tables in pg_repack.sql.in
Date: Thu, 12 Nov 2026 10:18:43 +0000
Message-ID: <gh-reorg-pg_repack-493-c6820915970@github.com> (raw)
In-Reply-To: <gh-reorg-pg_repack-493@github.com>
References: <gh-reorg-pg_repack-493@github.com>
Hi @CyberDem0n, thank you for the review.
I pushed two commits (the second one fixes a problem the first one caused).
1. `SET search_path = pg_catalog, pg_temp` is now on every function in `lib/pg_repack.sql.in` that did not have it (`oid2text` had `pg_catalog` only and now has `pg_catalog, pg_temp`): the SQL and PL/pgSQL helpers (`oid2text`, `get_*`, `create_*`, `conflicted_triggers`) and the C functions (`repack_apply`, `repack_swap`, `repack_drop`, `repack_index_swap`, `repack_indexdef`, `disable_autovacuum`, `get_order_by`, `get_table_and_inheritors`). `repack_trigger` already had it. Only `version()` and `version_sql()` are left without it, because they touch nothing. With the SET, every name in these functions now resolves through `pg_catalog`, whatever the caller's search_path is. I also schema-qualified one `pg_class` lookup done through SPI in `repack_index_swap()`.
2. While testing I found that the SET broke `repack.get_order_by()` for a non-default btree operator class that lives outside `pg_catalog`. `pg_get_indexdef()` then prints the class with its schema (for example `public.my_ops`), and the old code looked that string up by name and failed with `cache lookup failed for opclass 0`. The second commit reads the operator family and input type from the index itself instead of looking up the name. I added a regression case for it in `get_order_by`.
What I ran (PostgreSQL 18, local server):
- With only the first commit, `pg_repack -t t` on a table clustered on an index that uses a custom operator class in `public` fails with `cache lookup failed for opclass 0`. Without either commit it works, and with both commits it works again.
- `make installcheck`: all 13 tests pass with both commits, including the new case.
- Hostile setup: database search_path `evil, pg_catalog, public`, where `evil` has fake `quote_ident`, `quote_literal`, `format_type`, `array_to_string`, a table `h`, and tables `pg_class`, `pg_index` and `pg_attribute`. I called the helpers directly, before and after. Before, `get_index_columns()` returned `evil, evil` and `get_create_trigger()` produced `repack_trigger(evil)`. After, they return the real column list. `get_order_by()` and `repack_indexdef()` were not affected by the fake objects in either run. `repack_indexdef()` now prints the operator class with its schema (`public.hostile_int4_ops`), which is still valid for the client.
- `pg_proc.proconfig` shows the setting on every function in the `repack` schema except `version` and `version_sql`.
Not tested: PostgreSQL versions other than 18, and `repack_index_swap()` with a hostile search_path (not run on its own, only as part of installcheck).
Please tell me if you would prefer to leave the C functions out of this PR.