* GetDocumentsCountRunTime returns document count by counting the documents in the * given collection at runtime. It always returns accurate count. */
| 1091 | * given collection at runtime. It always returns accurate count. |
| 1092 | */ |
| 1093 | static int64 |
| 1094 | GetDocumentsCountRunTime(MongoCollection *collection) |
| 1095 | { |
| 1096 | StringInfo cmdStr = makeStringInfo(); |
| 1097 | appendStringInfo(cmdStr, |
| 1098 | "SELECT COUNT(*) FROM %s.documents_" UINT64_FORMAT, |
| 1099 | ApiDataSchemaName, collection->collectionId); |
| 1100 | bool isNull = true; |
| 1101 | bool readOnly = true; |
| 1102 | Datum resultDatum = ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, SPI_OK_SELECT, |
| 1103 | &isNull); |
| 1104 | if (isNull) |
| 1105 | { |
| 1106 | return 0; |
| 1107 | } |
| 1108 | return DatumGetInt64(resultDatum); |
| 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | /* |
no test coverage detected