MCPcopy Create free account
hub / github.com/documentdb/documentdb / command_db_stats

Function command_db_stats

pg_documentdb/src/commands/db_stats.c:81–119  ·  view source on GitHub ↗

* command_db_stats is the implementation of the internal logic for * dbcommand/dbStats. */

Source from the content-addressed store, hash-verified

79 * dbcommand/dbStats.
80 */
81Datum
82command_db_stats(PG_FUNCTION_ARGS)
83{
84 if (PG_ARGISNULL(0))
85 {
86 ereport(ERROR, (errmsg("Database name must not be NULL")));
87 }
88 Datum databaseName = PG_GETARG_DATUM(0);
89
90 if (PG_ARGISNULL(1))
91 {
92 /* Scale is optional in the dbStats command but here
93 * the sql method must provide scale to this C func */
94 ereport(ERROR, (errmsg("scale cannot be NULL")));
95 }
96 double scaleDouble = PG_GETARG_FLOAT8(1);
97
98 if (PG_ARGISNULL(2))
99 {
100 /* freeStorage is optional in the dbStats command but here
101 * the sql method must provide freeStorage to this C func */
102 ereport(ERROR, (errmsg("freeStorage cannot be NULL")));
103 }
104
105 /* We don't yet support freeStrorage statistics, so skip reading freeStorage value */
106
107 ReportFeatureUsage(FEATURE_COMMAND_DBSTATS);
108
109 /* Truncate the fractional part of the scale */
110 scaleDouble = trunc(scaleDouble);
111
112 /* The 'scale' value is capped to int32 for compatibility with expected behavior */
113 int32 scale = scaleDouble > INT32_MAX ? INT32_MAX :
114 scaleDouble < INT32_MIN ? INT32_MIN :
115 (int32) scaleDouble;
116
117 pgbson *response = DbStatsCoordinator(databaseName, scale);
118 PG_RETURN_POINTER(response);
119}
120
121
122/*

Callers

nothing calls this directly

Calls 2

ReportFeatureUsageFunction · 0.85
DbStatsCoordinatorFunction · 0.85

Tested by

no test coverage detected