Re: Replace magic numbers with strategy numbers for B-tree indexes - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Replace magic numbers with strategy numbers for B-tree indexes
Date
Msg-id 3bb2d82c-33ea-427f-b756-9777f070d2c8@eisentraut.org
Whole thread Raw
List 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.




pgsql-hackers by date:

Previous
From: Anthonin Bonnefoy
Date:
Subject: Don't keep closed WAL segment in page cache after replay
Next
From: Peter Eisentraut
Date:
Subject: Re: Explicitly enable meson features in CI