Re: heapgettup() with NoMovementScanDirection unused in core?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: heapgettup() with NoMovementScanDirection unused in core?
Date: 2023-01-27 23:15:50
Message-ID: 3584648.1674861350@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Melanie Plageman <melanieplageman(at)gmail(dot)com> writes:
> On Fri, Jan 27, 2023 at 05:05:16PM -0500, Tom Lane wrote:
>> AFAIR, there is noplace today that depends on the exact encoding
>> of ForwardScanDirection and BackwardScanDirection, and I'm not
>> sure that we want to introduce such a dependency.

> I think you mean the enum value when you say encoding? I actually
> started using the ScanDirection value in the refactor of heapgettup()
> and heapgettup_pagemode() which I proposed here [1]. Why wouldn't we
> want to introduce such a dependency?

It's just that in general, depending on the numeric values of an
enum isn't a great coding practice.

After thinking about it for awhile, I'd be happier if we added
something like this to sdir.h, and then used it rather than
directly depending on multiplication:

/*
* Determine the net effect of two direction specifications.
* This relies on having ForwardScanDirection = +1, BackwardScanDirection = -1,
* and will probably not do what you want if applied to any other values.
*/
#define CombineScanDirections(a, b) ((a) * (b))

The main thing this'd buy us is being able to grep for uses of the
trick. If it's written as just multiplication, good luck being
able to find what's depending on that, should you ever need to.

>> 4. I don't think the proposed test case is worth the cycles.

> Just the one I wrote or any test case?

I think that all this code is quite well-tested already, so I'm
not sure what's the point of adding another test for it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2023-01-27 23:23:39 Add n_tup_newpage_upd to pg_stat table views
Previous Message Nathan Bossart 2023-01-27 23:15:07 Re: improving user.c error messages