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

Function GetPostgresRelationSizes

pg_documentdb/src/commands/db_stats.c:801–831  ·  view source on GitHub ↗

* Gets the sum of the relation sizes and table sizes for the shards located on the current node * for a given relationIds. (the relationIds can be of different collections) */

Source from the content-addressed store, hash-verified

799 * for a given relationIds. (the relationIds can be of different collections)
800 */
801static void
802GetPostgresRelationSizes(ArrayType *relationIds, int64 *totalRelationSize,
803 int64 *totalTableSize)
804{
805 const char *query =
806 "SELECT SUM(pg_catalog.pg_total_relation_size(r))::int8, SUM(pg_catalog.pg_table_size(r))::int8 FROM unnest($1) r";
807
808 int nargs = 1;
809 Oid argTypes[1] = { OIDARRAYOID };
810 Datum argValues[1] = { PointerGetDatum(relationIds) };
811
812 bool readOnly = true;
813 Datum resultValues[2];
814 bool nullValues[2];
815 int numResults = 2;
816 ExtensionExecuteMultiValueQueryWithArgsViaSPI(query, nargs, argTypes, argValues, NULL,
817 readOnly,
818 SPI_OK_SELECT, resultValues, nullValues,
819 numResults);
820
821 *totalRelationSize = 0;
822 *totalTableSize = 0;
823
824 if (nullValues[0] || nullValues[1])
825 {
826 return;
827 }
828
829 *totalRelationSize = DatumGetInt64(resultValues[0]);
830 *totalTableSize = DatumGetInt64(resultValues[1]);
831}
832
833
834/*

Callers 1

DbStatsWorkerFunction · 0.70

Tested by

no test coverage detected