Reverse collations (initially for making keyset pagination cover more cases)

From: David Fetter <david(at)fetter(dot)org>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Reverse collations (initially for making keyset pagination cover more cases)
Date: 2019-11-17 18:24:08
Message-ID: 20191117182408.GA13566@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Folks,

Please find attached a patch for $Subject.

Motivation:

When people are doing keyset pagination, the simple cases redound to
adding a WHERE that looks like

(a, b, c) > (most_recent_a, most_recent_b, most_recent_c)

which corresponds to an ORDER BY clause that looks like

ORDER BY a, b, c

The fun starts when there are mixes of ASC and DESC in the ORDER BY
clause. Reverse collations make this simpler by inverting the meaning
of > (or similar), which makes the rowtypes still sortable in a new
dictionary order, so the pagination would look like:

(a, b, c) > (most_recent_a, most_recent_b COLLATE "C_backwards", most_recent_c)

with an ORDER BY like:

ORDER BY a, b DESC, c

What say?

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachment Content-Type Size
v1-0001-Reverse-collations.patch text/x-diff 17.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-11-17 19:30:35 Re: Reverse collations (initially for making keyset pagination cover more cases)
Previous Message Alexander Korotkov 2019-11-17 18:18:43 Re: Connections hang indefinitely while taking a gin index's LWLock buffer_content lock(PG10.7)