Bug in abbreviated keys abort handling (found with amcheck)

From: Peter Geoghegan <pg(at)heroku(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Bug in abbreviated keys abort handling (found with amcheck)
Date: 2016-08-19 22:07:02
Message-ID: CAM3SWZS=v8UW2Jkd99QD5XpuCiVUp0sb7fzBG_NZ3HWqNTa+iQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I found another bug as a result of using amcheck on Heroku customer
databases. This time, the bug is in core Postgres. It's one of mine.

There was a thinko in tuplesort's abbreviation abort logic, causing
certain SortTuples to be spuriously marked NULL (and so, subsequently
sorted as a NULL tuple, despite not actually changing anything about
the representation of caller tuples). The attached patch fixes this
bug.

I noticed this following a complaint by amcheck about a tuple in the
wrong order on a leaf page in some random text index. The leaf page
was entirely full of NULL values, aside from this one tuple at some
seemingly random position. All non-NULL index tuples were of the kind
that you'd expect to trigger abbreviation to abort (many distinct
values, but with little entropy at the beginning).

I believe that this particular problem has been observed on a tiny
fraction of all databases tested, so I don't think it's very common in
the wild.

I'd be surprised if amcheck does not bring more bugs like this to my
attention before too long. We should work on improving it, so that we
have greater visibility into problems that occur in the field.
--
Peter Geoghegan

Attachment Content-Type Size
0001-Fix-thinko-in-abbreviated-key-abort-code.patch text/x-patch 1.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Piotr Stefaniak 2016-08-19 22:07:49 Re: Re: PROPOSAL: make PostgreSQL sanitizers-friendly (and prevent information disclosure)
Previous Message Tom Lane 2016-08-19 21:55:25 Re: Re: PROPOSAL: make PostgreSQL sanitizers-friendly (and prevent information disclosure)