Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-09-05 Thread zengman
Attempt to clear the compilation warning, overwrite the plpgsql.out file, and update the patch. 002_cleanup_spl_funccache_v2.patch Description: Binary data

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-21 Thread 章晨曦
It seems not an easy task. And here is my new work of such task. The main idea is register a sys cache callback in cached_function_compile when not registered. So it will effect for all SPL. And also introduce a new hash table to track the function for cache inval callback. The procedure in callbac

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-20 Thread Tom Lane
Vladlen Popolitov writes: > What do you mean, when speak about function cache? What I'm thinking about is the function parse-tree, which not incidentally contains a bunch of links to cached plans (via SPI). Looking at plpgsql_free_function_memory might clarify things for you.

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-20 Thread Vladlen Popolitov
章晨曦 писал(а) 2025-08-19 12:31: I think you misunderstand Man's meaning. In Man's example, the func cache neither dropped (will cause memory leak) nor reused. So the question here: 1. Drop the cache when func dropped 2. Keep the cache and reused when func recreate I prefer the 2ed solution. Re

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread Tom Lane
"=?utf-8?B?56ug5pmo5pum?=" writes: > I think you misunderstand Man's meaning. In Man's example, the func cache > neither dropped (will cause memory leak) nor reused. So the question here: > 1. Drop the cache when func dropped > 2. Keep the cache and reused when func recreate > I prefer the 2ed sol

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread 章晨曦
Vladlen Popolitov 2025-08-19 08:39:50 wrote:> Hi! > >   In your example function will be compiled (the tree is created in the > memory) > and executed. >   During execution this function creates a plan for very simple query 1 > and stores it in the cache, than it creates a plan for query 10 and >

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread Vladlen Popolitov
Man Zeng писал(а) 2025-08-19 11:28: So in my opinion, the cached plan will not be reused but will constantly occupy resources. regards, Zeng Man Hi! In your example function will be compiled (the tree is created in the memory) and executed. During execution this function creates a plan fo

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread Man Zeng
So in my opinion, the cached plan will not be reused but will constantly occupy resources. regards, Zeng Man

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread Man Zeng
When a function or stored procedure is created, called, and then dropped, the resulting CachedPlan is never released and can only be freed by exiting the session. Meanwhile, if you create another function or stored procedure with the same name and parameters, and then call it, you'll be able t

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread Vladlen Popolitov
Man Zeng писал(а) 2025-08-19 10:50: https://www.postgresql.org/message-id/flat/tencent_0ba97862026bc74e75238...@qq.com The new status of this patch is: Needs review Hi! I read from the beginning till this email and did not find the description what exactly you are going to fix. Could you pro

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread Man Zeng
https://www.postgresql.org/message-id/flat/tencent_0ba97862026bc74e75238...@qq.com The new status of this patch is: Needs review

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-19 Thread zengman
This patch only addresses the plan cache release for plpgsql (the procedural language) and does not cover SQL functions. Since the src/backend/utils/cache/funccache.c file was introduced in PostgreSQL 18, I will first upgrade to version 18,  then figure out how to extend the benefit to SQL funct

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-18 Thread Man Zeng
That's correct—this is a simple and blunt patch, and it fails to account for many factors. Initially, I wasn't even sure if this qualified as a distinct issue. Your solution is far more reasonable, and I will rethink the new implementation thoroughly based on your approach. Thanks, Zeng Man Th

Re: Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-18 Thread zengman
That's correct??this is a simple and blunt patch, and it fails to account for many factors. Initially, I wasn't even sure if this qualified as a distinct issue. Your solution is far more reasonable, and I will rethink the new implementation thoroughly based on your approach. Thanks, Zeng Man

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-18 Thread Tom Lane
Matthias van de Meent writes: > I'm trying to figure out how this patch is supposed to handle > concurrent sessions dropping a procedure that has cached plans. It doesn't, which is (one reason) why it's just a crude hack. A more appropriate solution would be to make plpgsql install a shared-cach

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-18 Thread Matthias van de Meent
On Mon, 18 Aug 2025 at 08:51, zengman wrote: > > Hi, hackers > > I have observed an issue where the CachedPlan corresponding to a > function/procedure is not released when we execute the "DROP > FUNCTION\PROCEDURE" command. A patch to resolve this problem is attached. I'm trying to figure out h

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-18 Thread zengman
Sorry for the garbled characters. I am resending the original test results as an attachment. case.txt Description: Binary data

Re: When deleting the plpgsql function, release the CachedPlan of the function

2025-08-18 Thread zengman
Sorry for the garbled characters. I am resending the original test results as an attachment. result.pdf Description: Binary data

When deleting the plpgsql function, release the CachedPlan of the function

2025-08-17 Thread zengman
Hi, hackers I have observed an issue where the CachedPlan corresponding to a function/procedure is not released when we execute the "DROP FUNCTION\PROCEDURE" command. A patch to resolve this problem is attached. A simple test case is as follows: Step 1 ?? create or replace procedure test_pr