69
69
#include "utils/acl.h"
70
70
#include "utils/builtins.h"
71
71
#include "utils/memutils.h"
72
+ #include "utils/plancache.h"
72
73
#include "utils/timestamp.h"
73
74
74
75
PG_MODULE_MAGIC_EXT (
@@ -114,6 +115,7 @@ typedef enum pgssVersion
114
115
PGSS_V1_10 ,
115
116
PGSS_V1_11 ,
116
117
PGSS_V1_12 ,
118
+ PGSS_V1_13 ,
117
119
} pgssVersion ;
118
120
119
121
typedef enum pgssStoreKind
@@ -210,6 +212,8 @@ typedef struct Counters
210
212
* to be launched */
211
213
int64 parallel_workers_launched ; /* # of parallel workers actually
212
214
* launched */
215
+ int64 generic_plan_calls ; /* number of calls using a generic plan */
216
+ int64 custom_plan_calls ; /* number of calls using a custom plan */
213
217
} Counters ;
214
218
215
219
/*
@@ -323,6 +327,7 @@ PG_FUNCTION_INFO_V1(pg_stat_statements_1_9);
323
327
PG_FUNCTION_INFO_V1 (pg_stat_statements_1_10 );
324
328
PG_FUNCTION_INFO_V1 (pg_stat_statements_1_11 );
325
329
PG_FUNCTION_INFO_V1 (pg_stat_statements_1_12 );
330
+ PG_FUNCTION_INFO_V1 (pg_stat_statements_1_13 );
326
331
PG_FUNCTION_INFO_V1 (pg_stat_statements );
327
332
PG_FUNCTION_INFO_V1 (pg_stat_statements_info );
328
333
@@ -355,7 +360,8 @@ static void pgss_store(const char *query, uint64 queryId,
355
360
const struct JitInstrumentation * jitusage ,
356
361
JumbleState * jstate ,
357
362
int parallel_workers_to_launch ,
358
- int parallel_workers_launched );
363
+ int parallel_workers_launched ,
364
+ CachedPlan * cplan );
359
365
static void pg_stat_statements_internal (FunctionCallInfo fcinfo ,
360
366
pgssVersion api_version ,
361
367
bool showtext );
@@ -877,7 +883,8 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate)
877
883
NULL ,
878
884
jstate ,
879
885
0 ,
880
- 0 );
886
+ 0 ,
887
+ NULL );
881
888
}
882
889
883
890
/*
@@ -957,7 +964,8 @@ pgss_planner(Query *parse,
957
964
NULL ,
958
965
NULL ,
959
966
0 ,
960
- 0 );
967
+ 0 ,
968
+ NULL );
961
969
}
962
970
else
963
971
{
@@ -1099,7 +1107,8 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
1099
1107
queryDesc -> estate -> es_jit ? & queryDesc -> estate -> es_jit -> instr : NULL ,
1100
1108
NULL ,
1101
1109
queryDesc -> estate -> es_parallel_workers_to_launch ,
1102
- queryDesc -> estate -> es_parallel_workers_launched );
1110
+ queryDesc -> estate -> es_parallel_workers_launched ,
1111
+ queryDesc -> cplan );
1103
1112
}
1104
1113
1105
1114
if (prev_ExecutorEnd )
@@ -1232,7 +1241,8 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
1232
1241
NULL ,
1233
1242
NULL ,
1234
1243
0 ,
1235
- 0 );
1244
+ 0 ,
1245
+ NULL );
1236
1246
}
1237
1247
else
1238
1248
{
@@ -1295,7 +1305,8 @@ pgss_store(const char *query, uint64 queryId,
1295
1305
const struct JitInstrumentation * jitusage ,
1296
1306
JumbleState * jstate ,
1297
1307
int parallel_workers_to_launch ,
1298
- int parallel_workers_launched )
1308
+ int parallel_workers_launched ,
1309
+ CachedPlan * cplan )
1299
1310
{
1300
1311
pgssHashKey key ;
1301
1312
pgssEntry * entry ;
@@ -1503,6 +1514,15 @@ pgss_store(const char *query, uint64 queryId,
1503
1514
entry -> counters .parallel_workers_to_launch += parallel_workers_to_launch ;
1504
1515
entry -> counters .parallel_workers_launched += parallel_workers_launched ;
1505
1516
1517
+ if (cplan )
1518
+ {
1519
+ if (cplan -> status == PLAN_CACHE_STATUS_GENERIC_PLAN_BUILD ||
1520
+ cplan -> status == PLAN_CACHE_STATUS_GENERIC_PLAN_REUSE )
1521
+ entry -> counters .generic_plan_calls ++ ;
1522
+ if (cplan -> status == PLAN_CACHE_STATUS_CUSTOM_PLAN )
1523
+ entry -> counters .custom_plan_calls ++ ;
1524
+ }
1525
+
1506
1526
SpinLockRelease (& entry -> mutex );
1507
1527
}
1508
1528
@@ -1570,7 +1590,8 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
1570
1590
#define PG_STAT_STATEMENTS_COLS_V1_10 43
1571
1591
#define PG_STAT_STATEMENTS_COLS_V1_11 49
1572
1592
#define PG_STAT_STATEMENTS_COLS_V1_12 52
1573
- #define PG_STAT_STATEMENTS_COLS 52 /* maximum of above */
1593
+ #define PG_STAT_STATEMENTS_COLS_V1_13 54
1594
+ #define PG_STAT_STATEMENTS_COLS 54 /* maximum of above */
1574
1595
1575
1596
/*
1576
1597
* Retrieve statement statistics.
@@ -1582,6 +1603,16 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
1582
1603
* expected API version is identified by embedding it in the C name of the
1583
1604
* function. Unfortunately we weren't bright enough to do that for 1.1.
1584
1605
*/
1606
+ Datum
1607
+ pg_stat_statements_1_13 (PG_FUNCTION_ARGS )
1608
+ {
1609
+ bool showtext = PG_GETARG_BOOL (0 );
1610
+
1611
+ pg_stat_statements_internal (fcinfo , PGSS_V1_13 , showtext );
1612
+
1613
+ return (Datum ) 0 ;
1614
+ }
1615
+
1585
1616
Datum
1586
1617
pg_stat_statements_1_12 (PG_FUNCTION_ARGS )
1587
1618
{
@@ -1740,6 +1771,10 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
1740
1771
if (api_version != PGSS_V1_12 )
1741
1772
elog (ERROR , "incorrect number of output arguments" );
1742
1773
break ;
1774
+ case PG_STAT_STATEMENTS_COLS_V1_13 :
1775
+ if (api_version != PGSS_V1_13 )
1776
+ elog (ERROR , "incorrect number of output arguments" );
1777
+ break ;
1743
1778
default :
1744
1779
elog (ERROR , "incorrect number of output arguments" );
1745
1780
}
@@ -1997,6 +2032,11 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
1997
2032
values [i ++ ] = TimestampTzGetDatum (stats_since );
1998
2033
values [i ++ ] = TimestampTzGetDatum (minmax_stats_since );
1999
2034
}
2035
+ if (api_version >= PGSS_V1_13 )
2036
+ {
2037
+ values [i ++ ] = Int64GetDatumFast (tmp .generic_plan_calls );
2038
+ values [i ++ ] = Int64GetDatumFast (tmp .custom_plan_calls );
2039
+ }
2000
2040
2001
2041
Assert (i == (api_version == PGSS_V1_0 ? PG_STAT_STATEMENTS_COLS_V1_0 :
2002
2042
api_version == PGSS_V1_1 ? PG_STAT_STATEMENTS_COLS_V1_1 :
@@ -2007,6 +2047,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
2007
2047
api_version == PGSS_V1_10 ? PG_STAT_STATEMENTS_COLS_V1_10 :
2008
2048
api_version == PGSS_V1_11 ? PG_STAT_STATEMENTS_COLS_V1_11 :
2009
2049
api_version == PGSS_V1_12 ? PG_STAT_STATEMENTS_COLS_V1_12 :
2050
+ api_version == PGSS_V1_13 ? PG_STAT_STATEMENTS_COLS_V1_13 :
2010
2051
-1 /* fail if you forget to update this assert */ ));
2011
2052
2012
2053
tuplestore_putvalues (rsinfo -> setResult , rsinfo -> setDesc , values , nulls );
0 commit comments