Re: [PATCH] Push limit to sort through a subquery

From: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Push limit to sort through a subquery
Date: 2017-08-23 07:26:20
Message-ID: 712fe4f7-3707-5147-f73a-31c6a72a54b2@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 22.08.2017 17:27, Konstantin Knizhnik wrote:
>
>
> On 18.08.2017 04:33, Robert Haas wrote:
>>
>> It seems like a somewhat ad-hoc approach; it supposes that we can
>> take any query produced by deparseSelectStmtForRel() and stick a
>> LIMIT clause onto the very end and all will be well. Maybe that's
>> not a problematic assumption, not sure. The grammar happens to allow
>> both FOR UPDATE LIMIT n and LIMIT n FOR UPDATE even though only the
>> latter syntax is documented.
>>
>> --
>> Robert Haas
>> EnterpriseDB: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>
>
> I am not absolutely sure that it is possible to append any query which
> can be constructed by postgres_fdw for foreign scan with "LIMIT n" clause.
> But I also do not know example when it is not possible. As you have
> mentioned, "FOR UPDATE LIMIT n" is currently recognized by Postgres.
>

I have inspected deparseSelectStmtForRel function and now I am sure that
appending LIMIT to the SQL statement generated by this function will not
cause any problems.
It can produce only the following subset of SELECT:

select <target-list> FROM <table-list> [GROUP BY ... [ HAVING ... ]] [
OREDER BY ... ] [ FOR UPDATE ... ];

The only suspicious clause is FOR UPDATE, but I have checked that "FOR
UPDATE ... LIMIT n" is really accepted by Postgres parser.

--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2017-08-23 07:34:41 Re: Regression stoping PostgreSQL 9.4.13 if a walsender is running
Previous Message Michael Paquier 2017-08-23 07:18:01 Re: Explicit relation name in VACUUM VERBOSE log