-
Notifications
You must be signed in to change notification settings - Fork 2
Comparing changes
Open a pull request
base repository: postgresql-cfbot/postgresql
base: cf/5695~1
head repository: postgresql-cfbot/postgresql
compare: cf/5695
- 6 commits
- 1 file changed
- 2 contributors
Commits on Apr 17, 2025
-
Minor performance improvement for SQL-language functions.
Late in the development of commit 0dca5d6, I added a step to copy the result tlist we extract from the cached final query, because I was afraid that that might not last as long as the JunkFilter that we're passing it off to. However, that turns out to cost a noticeable number of cycles, and it's really quite unnecessary because the JunkFilter will not examine that tlist after it's been created. (ExecFindJunkAttribute would use it, but we don't use that function on this JunkFilter.) Hence, remove the copy step. For safety, reset the might-become-dangling jf_targetList pointer to NIL. In passing, remove DR_sqlfunction.cxt, which we don't use anymore; it's confusing because it's not entirely clear which context it ought to point at.
Configuration menu - View commit details
-
Copy full SHA for 8255d09 - Browse repository at this point
Copy the full SHA 8255d09View commit details -
Make functions.c mostly run in a short-lived memory context.
Previously, much of this code ran with CurrentMemoryContext set to be the function's fcontext, so that we tended to leak a lot of stuff there. Commit 0dca5d6 dealt with that by releasing the fcontext at the completion of each SQL function call, but we'd like to go back to the previous approach of allowing the fcontext to be query-lifespan. To control the leakage problem, rearrange the code so that we mostly run in the memory context that fmgr_sql is called in (which we expect to be short-lived). Notably, this means that parsing/planning is all done in the short-lived context and doesn't leak cruft into fcontext. This patch also fixes the allocation of execution_state records so that we don't leak them across executions. I set that up with a re-usable array that contains at least as many execution_state structs as we need for the current querytree. The chain structure is still there, but it's not really doing much for us, and maybe somebody will be motivated to get rid of it. I'm not though. This incidentally also moves the call of BlessTupleDesc to be with the code that creates the JunkFilter. That doesn't make much difference now, but a later patch will reduce the number of times the JunkFilter gets made, and we needn't bless the results any more often than that. We still leak a fair amount in fcontext, particularly when executing utility statements, but that's material for a separate patch step; the point here is only to get rid of unintentional allocations in fcontext.
Configuration menu - View commit details
-
Copy full SHA for 12abcdd - Browse repository at this point
Copy the full SHA 12abcddView commit details -
Split some storage out to separate subcontexts of fcontext.
Put the JunkFilter and its result slot (and thence also some subsidiary data such as the result tupledesc) into a separate subcontext "jfcontext". This doesn't accomplish a lot at this point, because we make a new JunkFilter each time through the SQL function. However, the plan is to make the fcontext live longer, and that raises the possibility that we'll need a new JunkFilter because the plan for the result-generating query changes. A separate context makes it easy to free the obsoleted data when that happens. Also, instead of always running the sub-executor in fcontext, make a separate context for it if we're doing lazy eval of a SRF, and otherwise just run it inside CurrentMemoryContext. The combination of these steps reduces the expected size of fcontext enough that we can use ALLOCSET_SMALL_SIZES.
Configuration menu - View commit details
-
Copy full SHA for 69d3852 - Browse repository at this point
Copy the full SHA 69d3852View commit details -
Make SQLFunctionCache long-lived again.
At this point, the only data structures we allocate directly in fcontext are the SQLFunctionCache struct itself, the ParamListInfo struct, and the execution_state array, all of which are small and perfectly capable of being re-used across executions of the same FmgrInfo. Hence, let's give them the same lifespan as the FmgrInfo. This step gets rid of the separate SQLFunctionLink struct and makes fn_extra point to SQLFunctionCache again. We also get rid of the separate fcontext memory context and allocate these items directly in fn_mcxt. For notational simplicity, SQLFunctionCache still has an fcontext field, but it's just a copy of fn_mcxt. The motivation for this is to allow these structures to live as long as the FmgrInfo and be re-used across calls, restoring the original design without its propensity for memory leaks. This gets rid of some per-call overhead that we added in 0dca5d6. We also make an effort to re-use the JunkFilter and result slot. Those might need to change if the function definition changes, so we compromise by rebuilding them if the cached plan changes. This also moves the tuplestore into fn_mcxt so that it can be re-used across calls, again undoing a change made in 0dca5d6.
Configuration menu - View commit details
-
Copy full SHA for 199f028 - Browse repository at this point
Copy the full SHA 199f028View commit details -
Cache typlens of a SQL function's input arguments.
This gets rid of repetitive get_typlen() calls in postquel_sub_params, which show up as costing 1% or so of the runtime in simple test cases.
Configuration menu - View commit details
-
Copy full SHA for afde2b3 - Browse repository at this point
Copy the full SHA afde2b3View commit details -
[CF 5695] v1 - Performance issues with v18 SQL-language-function changes
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5695 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/[email protected] Author(s): Tom Lane
Commitfest Bot committedApr 17, 2025 Configuration menu - View commit details
-
Copy full SHA for e5210c9 - Browse repository at this point
Copy the full SHA e5210c9View commit details
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff cf/5695~1...cf/5695