Re: Replace magic numbers with strategy numbers for B-tree indexes

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Daniil Davydov <3danissimo(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Replace magic numbers with strategy numbers for B-tree indexes
Date: 2025-07-02 11:24:02
Message-ID: 3bb2d82c-33ea-427f-b756-9777f070d2c8@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 30.06.25 05:21, Daniil Davydov wrote:
> Hi,
> I noticed that some asserts and cycles use magic numbers 1 and 0
> instead of BTLessStrategyNumber and InvalidStrategy.
> At the same time, the BTMaxStrategyNumber macro is used there.
> I suggest using appropriate macros for 1 and 0 values.

This code, both the original and your changes, make a lot of assumptions
about the btree strategy numbers, such as that BTLessStrategyNumber is
the smallest valid one, that InvalidStrategy is smaller than all of
them, and that all numbers between the smallest and BTMaxStrategyNumber
are assigned.

However, some of the code actually does require that, because it fills
in array fields for consecutive strategy numbers. So hiding that fact
by changing 1 to BTLessStrategyNumber introduces more mystery.

I think if we want to abstract all that away, this would need a deeper
approach somehow.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-07-02 11:33:09 Re: Explicitly enable meson features in CI
Previous Message Dean Rasheed 2025-07-02 10:57:41 Re: Binary operators for cubes