Performance difference between postgREST filtering and native WHERE clause #3755
-
I have a plpgsql function serving an endpoint under When I use postgREST filtering such as Is this difference in performance expected? I am not sure of exactly how the postgREST filtering works under the hood. My tables look like this:
And the function (very bulky, the variables are in the WHERE at the end):
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes, because the arguments are applied on the query inside the function, while the non-argument filters are applied on the result outside of the function. Since your function is a plpgsql, volatile function it is not inline-able and PostgreSQL can't push your conditions into the inner query. Thus the query inside the function runs to completion and is filtered afterwards. It seems your function can be marked |
Beta Was this translation helpful? Give feedback.
Yes, because the arguments are applied on the query inside the function, while the non-argument filters are applied on the result outside of the function. Since your function is a plpgsql, volatile function it is not inline-able and PostgreSQL can't push your conditions into the inner query. Thus the query inside the function runs to completion and is filtered afterwards.
It seems your function can be marked
STABLE
. Also replace it with a pureSQL
function instead ofplpgsql
. This should give you a chance of inlining the function call - you can then see whether the=eq.
style request performs better. If it doesn't, make sure to look at the exp…