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

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

From
Peter Eisentraut
Date:
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.