Re: allowing extensions to control planner behavior

From: Joe Conway <mail(at)joeconway(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: allowing extensions to control planner behavior
Date: 2024-08-27 15:56:59
Message-ID: af25a72d-e8c7-4a2f-9e7b-11d6f749855d@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 8/27/24 11:45, Robert Haas wrote:
> On Mon, Aug 26, 2024 at 3:28 PM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> Well, I agree that this doesn't address everything you might want to
>> do, ... I will very happily propose more things to
>> address the other problems that I know about ...
>
> In that vein, here's a new patch set where I've added a second patch
> that allows extensions to control choice of index. It's 3 lines of new
> code, plus 7 lines of comments and whitespace. Feeling inspired, I
> also included a contrib module, initial_vowels_are_evil, to
> demonstrate how this can be used by an extension that wants to disable
> certain indexes but not others. This is obviously quite silly and we
> might (or might not) want a more serious example in contrib, but it
> demonstrates how easy this can be with just a tiny bit of core
> infrastructure:
>
> robert.haas=# load 'initial_vowels_are_evil';
> LOAD
> robert.haas=# explain select count(*) from pgbench_accounts;
> QUERY PLAN
> -----------------------------------------------------------------------------------------------------------------
> Aggregate (cost=2854.29..2854.30 rows=1 width=8)
> -> Index Only Scan using pgbench_accounts_pkey on pgbench_accounts
> (cost=0.29..2604.29 rows=100000 width=0)
> (2 rows)
> robert.haas=# alter index pgbench_accounts_pkey rename to
> evil_pgbench_accounts_pkey;
> ALTER INDEX
> robert.haas=# explain select count(*) from pgbench_accounts;
> QUERY PLAN
> ------------------------------------------------------------------------------
> Aggregate (cost=2890.00..2890.01 rows=1 width=8)
> -> Seq Scan on pgbench_accounts (cost=0.00..2640.00 rows=100000 width=0)
> (2 rows)
> robert.haas=#

Nice!

On the one hand, excluding indexes by initial vowels is definitely
silly. On the other, I can see how it might be useful for an extension
to exclude indexes based on a regex match of the index name or something
similar, at least for testing.

--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2024-08-27 16:11:18 Re: allowing extensions to control planner behavior
Previous Message Robert Haas 2024-08-27 15:45:00 Re: allowing extensions to control planner behavior