diff options
| author | Fujii Masao | 2020-07-20 02:55:50 +0000 |
|---|---|---|
| committer | Fujii Masao | 2020-07-20 02:55:50 +0000 |
| commit | d05b172a760e0ccb3008a2144f96053720000b12 (patch) | |
| tree | 8acef7bc05b6485a04613c58ae2c3dce50c6701e /src/backend/utils/cache | |
| parent | 044dc7b964147ec6303d59320fb743693b22af30 (diff) | |
Add generic_plans and custom_plans fields into pg_prepared_statements.
There was no easy way to find how many times generic and custom plans
have been executed for a prepared statement. This commit exposes those
numbers of times in pg_prepared_statements view.
Author: Atsushi Torikoshi, Kyotaro Horiguchi
Reviewed-by: Tatsuro Yamada, Masahiro Ikeda, Fujii Masao
Discussion: https://postgr.es/m/CACZ0uYHZ4M=NZpofH6JuPHeX=__5xcDELF8hT8_2T+R55w4RQw@mail.gmail.com
Diffstat (limited to 'src/backend/utils/cache')
| -rw-r--r-- | src/backend/utils/cache/plancache.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index 75b475c179b..50d6ad28b4c 100644 --- a/src/backend/utils/cache/plancache.c +++ b/src/backend/utils/cache/plancache.c @@ -218,6 +218,7 @@ CreateCachedPlan(RawStmt *raw_parse_tree, plansource->generation = 0; plansource->generic_cost = -1; plansource->total_custom_cost = 0; + plansource->num_generic_plans = 0; plansource->num_custom_plans = 0; MemoryContextSwitchTo(oldcxt); @@ -285,6 +286,7 @@ CreateOneShotCachedPlan(RawStmt *raw_parse_tree, plansource->generation = 0; plansource->generic_cost = -1; plansource->total_custom_cost = 0; + plansource->num_generic_plans = 0; plansource->num_custom_plans = 0; return plansource; @@ -1213,12 +1215,14 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, { /* Build a custom plan */ plan = BuildCachedPlan(plansource, qlist, boundParams, queryEnv); - /* Accumulate total costs of custom plans, but 'ware overflow */ - if (plansource->num_custom_plans < INT_MAX) - { - plansource->total_custom_cost += cached_plan_cost(plan, true); - plansource->num_custom_plans++; - } + /* Accumulate total costs of custom plans */ + plansource->total_custom_cost += cached_plan_cost(plan, true); + + plansource->num_custom_plans++; + } + else + { + plansource->num_generic_plans++; } Assert(plan != NULL); @@ -1574,6 +1578,7 @@ CopyCachedPlan(CachedPlanSource *plansource) /* We may as well copy any acquired cost knowledge */ newsource->generic_cost = plansource->generic_cost; newsource->total_custom_cost = plansource->total_custom_cost; + newsource->num_generic_plans = plansource->num_generic_plans; newsource->num_custom_plans = plansource->num_custom_plans; MemoryContextSwitchTo(oldcxt); |
