New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Computed overload with "returning" #1473
Computed overload with "returning" #1473
Conversation
Just a note on this: That would actually make sense, because those columns are exactly what will be read from the query, no matter whether its read, write or proc. And the readRequest will be available in every case anyways: in mutateRequest (and therefore in mutateRequestToQuery), in readRequestToQuery and possibly in requestToCallProcQuery. Although the latter should probably move "out" to where readSqlParts and mutateSqlParts are and have a similiar thing like invokeSqlParts or something. Doing this would also allow to give the read request a similiar structure: so just have a Just some thoughts on how to maybe make all those cases more similiar to each other, as that difference between those queries was the source for the problem with the computed columns in the first place. |
@wolfgangwalther Nice and succinct fix! Also, congrats on learning Haskell for making this PR! Your ideas about simplifying However your change is pretty minimal so I think a refactor could be done in a next PR. Could you add an entry to the CHANGELOG? I'll merge after that. Really appreciate the wording corrections btw :) |
@wolfgangwalther @steve-chavez the absence of CTEs (as much as possible) in read request was by design, a lot of the time they introduce performance problems (at least in older versions of PG). Their presence (CTEs) in the write requests are because of a "need", not "want", so trying to make the "read" query more like "write" query is the opposite of the original intention. The primary objective is to have performant queries, nice haskell code structure is secondary to that. |
The https://github.com/PostgREST/postgrest/blob/master/test/QueryCost.hs test suite is already in place for testing the query cost. I don't think a major change was being suggested here but some tests could definitely be added. |
Changing the query shape is the biggest change in this sort of tool. That test only includes rpc calls if i am reading it right. Also these type of tests (query cost over a table with 10 rows) will not detect much. The types of performance issues i am mentioning come up when joining multiple tables with millions of rows (which is not an uncommon case)
… On 7 Apr 2020, at 19:43, Steve Chavez ***@***.***> wrote:
The https://github.com/PostgREST/postgrest/blob/master/test/QueryCost.hs test suite is already in place for testing the query cost. I don't think a major change was being suggested here but some tests could definitely be added.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@ruslantalpa Thanks for the hint about CTEs and performance. I looked that up a bit and learned a few things about Postgres CTEs being "optimization fences". The gist is: Before postgres 12 conditions couldn't be pushed into / out of CTEs. CTEs act more or less like a temp table. Postgres 12 introduces Refactoring the statements would have to take this into account, as this could potentially a big performance kille, if done wrong. Although the current solution is not affected by this. |
* fix some typos and spelling * fix pg_source CTE name should be prefixed with pgrst_ * added tests for overloaded computed columns on patch calls
* fix some typos and spelling * fix pg_source CTE name should be prefixed with pgrst_ * added tests for overloaded computed columns on patch calls
While working on #1464 I understood the codebase a bit more. Even though mutate queries do have a similiar query to the RPC regarding the
pgrst_source
CTE, overloaded computed columns work there properly.While this is the basic structure of an RPC query:
A mutation query looks like this
Note that the outer select is created by the
{selectQuery}
- the same as in the RPC case. It's just that the column names - including the computed one - are repeated on the inner query (RETURNING
). So while on the inner queryanything.computed_overload
is really the function call, for the outer select it's a "real" column now.Compared to #1464 there is now a solution that is a lot easier: Just use the same code that generates the
RETURNING
column names and put those into the inner query for RPC calls, so that the result is:The first commits in here are just the tests taken from the other PR. The last commit implements that. Probably needs some improvements here and there, but it works great.