Re: BUG #19049: Assert failure when using skip arrays on an index key with DESC order

From: Natalya Aksman <natalya(at)tigerdata(dot)com>
To: Peter Geoghegan <pg(at)bowt(dot)ie>
Cc: natalya(at)timescale(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19049: Assert failure when using skip arrays on an index key with DESC order
Date: 2025-09-11 17:08:55
Message-ID: CAJumhcjhatJone9OLXiyMC8RVbtUGNP87vYVbgUiM7uR8mL8Fg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The patch looks good and fixes our failing tests.

Thank you,
Natalya Aksman.

On Thu, Sep 11, 2025 at 12:48 PM Peter Geoghegan <pg(at)bowt(dot)ie> wrote:

> On Thu, Sep 11, 2025 at 10:35 AM PG Bug reporting form
> <noreply(at)postgresql(dot)org> wrote:
> > Assert is:
> > if (ScanDirectionIsForward(dir) && array->low_compare)
> > Assert(DatumGetBool(FunctionCall2Coll(&array->low_compare->sk_func,
> > array->low_compare->sk_collation,
> > tupdatum,
> > array->low_compare->sk_argument)));
> >
> > The problem is "array->low_compare" changing "t1<10" to "t1>10" because
> t1
> > order is DESC.
>
> This explanation is correct: I simply neglected to account for the way
> that DESC column scalar keys (used as a skip array's
> low_compare/high_compare) will have already had their operator
> strategy inverted, at the point where preprocessing converts a
> low_compare > into an equivalent >= (and/or a high_compare < into an
> equivalent <=) as an optimization. As Tom pointed out, this is a bug
> in the mechanism added by commit b3f1a13f (not the main skip scan
> commit)
>
> A draft fix is attached. This fixes the crash that your test case
> exhibits, and passes all of my existing tests. I'll commit something
> along these lines within the next few days, barring any objections.
>
> I'm going to revisit my test coverage for DESC columns in light of
> this issue. I didn't add support for DESC columns in my fuzz testing
> scripts, which now seems like an oversight -- I'd definitely have
> caught this problem myself, had I done that from the start.
>
> --
> Peter Geoghegan
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Geoghegan 2025-09-11 17:16:11 Re: BUG #19049: Assert failure when using skip arrays on an index key with DESC order
Previous Message Peter Geoghegan 2025-09-11 16:48:06 Re: BUG #19049: Assert failure when using skip arrays on an index key with DESC order