diff options
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 218 |
1 files changed, 108 insertions, 110 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 01cc5e45b39..b5f3744d510 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -9,41 +9,41 @@ #include "pgstat.h" -extern Datum pg_stat_get_numscans(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_tuples_returned(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS); - -extern Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS); - -extern Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS); -extern Datum pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_numscans(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_tuples_returned(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS); + +extern Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS); + +extern Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS); Datum pg_stat_get_numscans(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->numscans); + result = (int64) (tabentry->numscans); PG_RETURN_INT64(result); } @@ -52,16 +52,16 @@ pg_stat_get_numscans(PG_FUNCTION_ARGS) Datum pg_stat_get_tuples_returned(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->tuples_returned); + result = (int64) (tabentry->tuples_returned); PG_RETURN_INT64(result); } @@ -70,16 +70,16 @@ pg_stat_get_tuples_returned(PG_FUNCTION_ARGS) Datum pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->tuples_fetched); + result = (int64) (tabentry->tuples_fetched); PG_RETURN_INT64(result); } @@ -88,16 +88,16 @@ pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS) Datum pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->tuples_inserted); + result = (int64) (tabentry->tuples_inserted); PG_RETURN_INT64(result); } @@ -106,16 +106,16 @@ pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS) Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->tuples_updated); + result = (int64) (tabentry->tuples_updated); PG_RETURN_INT64(result); } @@ -124,16 +124,16 @@ pg_stat_get_tuples_updated(PG_FUNCTION_ARGS) Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->tuples_deleted); + result = (int64) (tabentry->tuples_deleted); PG_RETURN_INT64(result); } @@ -142,16 +142,16 @@ pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS) Datum pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->blocks_fetched); + result = (int64) (tabentry->blocks_fetched); PG_RETURN_INT64(result); } @@ -160,16 +160,16 @@ pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS) Datum pg_stat_get_blocks_hit(PG_FUNCTION_ARGS) { - PgStat_StatTabEntry *tabentry; - Oid relid; - int64 result; + PgStat_StatTabEntry *tabentry; + Oid relid; + int64 result; - relid = PG_GETARG_OID(0); + relid = PG_GETARG_OID(0); if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else - result = (int64)(tabentry->blocks_hit); + result = (int64) (tabentry->blocks_hit); PG_RETURN_INT64(result); } @@ -178,8 +178,8 @@ pg_stat_get_blocks_hit(PG_FUNCTION_ARGS) Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS) { - FmgrInfo *fmgr_info = fcinfo->flinfo; - int32 result; + FmgrInfo *fmgr_info = fcinfo->flinfo; + int32 result; if (fcinfo->resultinfo == NULL || !IsA(fcinfo->resultinfo, ReturnSetInfo)) @@ -191,22 +191,22 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS) elog(ERROR, "No function memory context in set-function"); fmgr_info->fn_extra = MemoryContextAlloc(fmgr_info->fn_mcxt, 2 * sizeof(int)); - ((int *)(fmgr_info->fn_extra))[0] = 0; - ((int *)(fmgr_info->fn_extra))[1] = pgstat_fetch_stat_numbackends(); + ((int *) (fmgr_info->fn_extra))[0] = 0; + ((int *) (fmgr_info->fn_extra))[1] = pgstat_fetch_stat_numbackends(); } - ((int *)(fmgr_info->fn_extra))[0] += 1; - result = ((int *)(fmgr_info->fn_extra))[0]; + ((int *) (fmgr_info->fn_extra))[0] += 1; + result = ((int *) (fmgr_info->fn_extra))[0]; - if (result > ((int *)(fmgr_info->fn_extra))[1]) + if (result > ((int *) (fmgr_info->fn_extra))[1]) { pfree(fmgr_info->fn_extra); fmgr_info->fn_extra = NULL; - ((ReturnSetInfo *)(fcinfo->resultinfo))->isDone = ExprEndResult; + ((ReturnSetInfo *) (fcinfo->resultinfo))->isDone = ExprEndResult; PG_RETURN_NULL(); } - ((ReturnSetInfo *)(fcinfo->resultinfo))->isDone = ExprMultipleResult; + ((ReturnSetInfo *) (fcinfo->resultinfo))->isDone = ExprMultipleResult; PG_RETURN_INT32(result); } @@ -214,10 +214,10 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS) Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS) { - PgStat_StatBeEntry *beentry; - int32 beid; + PgStat_StatBeEntry *beentry; + int32 beid; - beid = PG_GETARG_INT32(0); + beid = PG_GETARG_INT32(0); if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL) PG_RETURN_NULL(); @@ -229,10 +229,10 @@ pg_stat_get_backend_pid(PG_FUNCTION_ARGS) Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS) { - PgStat_StatBeEntry *beentry; - int32 beid; + PgStat_StatBeEntry *beentry; + int32 beid; - beid = PG_GETARG_INT32(0); + beid = PG_GETARG_INT32(0); if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL) PG_RETURN_NULL(); @@ -244,10 +244,10 @@ pg_stat_get_backend_dbid(PG_FUNCTION_ARGS) Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS) { - PgStat_StatBeEntry *beentry; - int32 beid; + PgStat_StatBeEntry *beentry; + int32 beid; - beid = PG_GETARG_INT32(0); + beid = PG_GETARG_INT32(0); if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL) PG_RETURN_NULL(); @@ -259,15 +259,15 @@ pg_stat_get_backend_userid(PG_FUNCTION_ARGS) Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS) { - PgStat_StatBeEntry *beentry; - int32 beid; - int len; - text *result; + PgStat_StatBeEntry *beentry; + int32 beid; + int len; + text *result; if (!superuser()) PG_RETURN_NULL(); - beid = PG_GETARG_INT32(0); + beid = PG_GETARG_INT32(0); if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL) PG_RETURN_NULL(); @@ -284,16 +284,16 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS) Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS) { - PgStat_StatDBEntry *dbentry; - Oid dbid; - int32 result; + PgStat_StatDBEntry *dbentry; + Oid dbid; + int32 result; - dbid = PG_GETARG_OID(0); + dbid = PG_GETARG_OID(0); if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) result = 0; else - result = (int32)(dbentry->n_backends); + result = (int32) (dbentry->n_backends); PG_RETURN_INT32(result); } @@ -302,16 +302,16 @@ pg_stat_get_db_numbackends(PG_FUNCTION_ARGS) Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS) { - PgStat_StatDBEntry *dbentry; - Oid dbid; - int64 result; + PgStat_StatDBEntry *dbentry; + Oid dbid; + int64 result; - dbid = PG_GETARG_OID(0); + dbid = PG_GETARG_OID(0); if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) result = 0; else - result = (int64)(dbentry->n_xact_commit); + result = (int64) (dbentry->n_xact_commit); PG_RETURN_INT64(result); } @@ -320,16 +320,16 @@ pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS) Datum pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS) { - PgStat_StatDBEntry *dbentry; - Oid dbid; - int64 result; + PgStat_StatDBEntry *dbentry; + Oid dbid; + int64 result; - dbid = PG_GETARG_OID(0); + dbid = PG_GETARG_OID(0); if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) result = 0; else - result = (int64)(dbentry->n_xact_rollback); + result = (int64) (dbentry->n_xact_rollback); PG_RETURN_INT64(result); } @@ -338,16 +338,16 @@ pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS) Datum pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS) { - PgStat_StatDBEntry *dbentry; - Oid dbid; - int64 result; + PgStat_StatDBEntry *dbentry; + Oid dbid; + int64 result; - dbid = PG_GETARG_OID(0); + dbid = PG_GETARG_OID(0); if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) result = 0; else - result = (int64)(dbentry->n_blocks_fetched); + result = (int64) (dbentry->n_blocks_fetched); PG_RETURN_INT64(result); } @@ -356,18 +356,16 @@ pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS) Datum pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS) { - PgStat_StatDBEntry *dbentry; - Oid dbid; - int64 result; + PgStat_StatDBEntry *dbentry; + Oid dbid; + int64 result; - dbid = PG_GETARG_OID(0); + dbid = PG_GETARG_OID(0); if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL) result = 0; else - result = (int64)(dbentry->n_blocks_hit); + result = (int64) (dbentry->n_blocks_hit); PG_RETURN_INT64(result); } - - |