PostgREST / postgrest

REST API for any Postgres database
https://postgrest.org
MIT License
22.65k stars 1k forks source link

Bypass `db-max-rows` for RPC #3576

Open steve-chavez opened 2 weeks ago

steve-chavez commented 2 weeks ago

Problem

https://postgrest.org/en/v12/references/configuration.html#db-max-rows is enforced for all endpoints, even for RPC.

RPC already offers escape hatches with function settings, but not for this.

Solution

Use the function ROWS setting as a way to surpass db-max-rows. Having a db-max-rows=1000, this:

CREATE FUNCTION my_func() RETURNS SETOF projects ROWS 100_000

Would surpass the 1000 global limit for /rpc/my_fun.

Note: we already use ROWS for https://postgrest.org/en/v12/references/api/resource_embedding.html#computed-relationships

wolfgangwalther commented 2 weeks ago

We should be very careful here. ROWS does influence the planner. You want my_func to possibly return 100_000 rows, but the planner assumes this function will return that many rows. If you return only a handful of rows, you might get a different plan, which is muss less efficient, because it assumes you will return many rows.