ossc-db / pg_store_plans

Store execution plans like pg_stat_statements does for queries.
http://ossc-db.github.io/pg_store_plans/
Other
53 stars 26 forks source link

Ignore storing of the execution plan for queries executed in CREATE/ALTER EXTENSION. #8

Closed kasaharatt closed 2 years ago

kasaharatt commented 3 years ago

Hi.

As this issue #7 , some EXTENSION script cause significant memory consumption. In CREATE/ALTER EXTENSION, execute_sql_string() would be issued. In this case, queryDesc->sourceText has queries for entire script. So, parse all queries per each query execution in the script at hash_query(). As a result, each store_entry() takes very long time and consume huge memory.

To avoid this, ignore storing of the execution plan for queries executed in CREATE/ALTER EXTENSION. I think execution plans of the queries executed by CREATE/ALTER EXTENSION is not very important, so this workaround might be reasonable...

horiguti commented 2 years ago

The behavior seems reasonable. Based on Kasahara-san's solution, I came up with the following.

https://github.com/horiguti/pg_store_plans/commit/c6de87995e07324d381e287ca9b721287e1a989e

There are two significant differences. The patch makes the behavior configurable using pg_store_plans.track. Another difference is the above patch doesn't change the behavior of nest_level and restore the flag by more reliable way.

horiguti commented 2 years ago

Done.