Re: [HACKERS] [PATCH] Push limit to sort through a subquery - Mailing list pgsql-hackers

From Konstantin Knizhnik
Subject Re: [HACKERS] [PATCH] Push limit to sort through a subquery
Date
Msg-id 712fe4f7-3707-5147-f73a-31c6a72a54b2@postgrespro.ru
Whole thread Raw
In response to [HACKERS] [PATCH] Push limit to sort through a subquery  (Douglas Doole <dougdoole@gmail.com>)
Responses Re: [HACKERS] [PATCH] Push limit to sort through a subquery  (Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>)
List 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 

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [HACKERS] Explicit relation name in VACUUM VERBOSE log
Next
From: Andres Freund
Date:
Subject: Re: [HACKERS] Regression stoping PostgreSQL 9.4.13 if a walsender isrunning