Re: FETCH FIRST clause WITH TIES option

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Surafel Temesgen <surafel3000(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Subject: Re: FETCH FIRST clause WITH TIES option
Date: 2019-11-25 20:34:42
Message-ID: 20191125203442.GA30191@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-Nov-11, Alvaro Herrera wrote:

> I'm not sure the proposed changes to gram.y are all that great, though.

Here's a proposed simplification of the gram.y changes. There are two
things here:

1. cosmetic: we don't need the LimitClause struct; we can use just
SelectLimit, and return that from limit_clause; that can be
complemented using the offset_clause if there's any at select_limit

2. there's a gratuituous palloc() in opt_select_limit when there's no
clause, that seems to be there just so that NULLs can be returned.
That's one extra palloc for SELECTs parsed using one the affected
productions ... it's not every single select, but it seems bad enough
it's worth fixing.

I fixed #2 by just checking whether the return from opt_select_limit is
NULL. ISTM it'd be better to pass the SelectLimit pointer to
insertSelectOptions instead (which is a static function in gram.y anyway
so there's no difficulty there).

Álvaro Herrera
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
with_ties_gram.patch text/x-diff 5.2 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2019-11-25 20:53:36 Re: FETCH FIRST clause WITH TIES option
Previous Message Pavel Stehule 2019-11-25 20:23:12 Re: GROUPING SETS and SQL standard