A rather hackish POC for alternative implementation of WITH TIES

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Surafel Temesgen <surafel3000(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Subject: A rather hackish POC for alternative implementation of WITH TIES
Date: 2019-11-29 05:39:57
Message-ID: 87o8wvz253.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This patch is a rather hacky implementation of the basic idea for
implementing FETCH ... WITH TIES, and potentially also PERCENT, by using
a window function expression to compute a stopping point.

Large chunks of this (the parser/ruleutils changes, docs, tests) are
taken from Surafel Temesgen's patch. The difference is that the executor
change in my version is minimal: Limit allows a boolean column in the
input to signal the point at which to stop. The planner inserts a
WindowAgg node to compute the necessary condition using the rank()
function.

The way this is done in the planner isn't (IMO) the best and should
probably be improved; in particular it currently misses some possible
optimizations (most notably constant-folding of the offset+limit
subexpression). I also haven't tested it properly to see whether I broke
anything, though it does pass regression.

--
Andrew (irc:RhodiumToad)

Attachment Content-Type Size
with_ties_window.patch text/x-patch 33.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2019-11-29 05:56:07 Re: pgbench - add \aset to store results of a combined query
Previous Message nagaura.ryohei@fujitsu.com 2019-11-29 05:22:01 RE: [patch]socket_timeout in interfaces/libpq