* Given a List of bsons that were dispatched by the query workers, * and a given collection & scale, merges the results into the target * CollStatsResult struct. */
| 388 | * CollStatsResult struct. |
| 389 | */ |
| 390 | static void |
| 391 | MergeWorkerResults(CollStatsResult *result, MongoCollection *collection, |
| 392 | List *workerResults, int scale, CollStatsAggMode mode) |
| 393 | { |
| 394 | /* To merge the results, we apply each shard's results consecutively until we have everything |
| 395 | * each field is processed by its intent |
| 396 | */ |
| 397 | |
| 398 | ListCell *workerCell; |
| 399 | |
| 400 | result->totalSize = 0; |
| 401 | result->storageSize = 0; |
| 402 | int64 totalDocCount = 0; |
| 403 | int64 totalDocCountFromStats = 0; |
| 404 | int64 totalDocColumnSize = 0; |
| 405 | int64 totalDocColumnSizeFromStats = 0; |
| 406 | List *indexDocs = NIL; |
| 407 | |
| 408 | foreach(workerCell, workerResults) |
| 409 | { |
| 410 | pgbson *workerBson = lfirst(workerCell); |
| 411 | bson_iter_t workerIter; |
| 412 | PgbsonInitIterator(workerBson, &workerIter); |
| 413 | |
| 414 | int64 workerTotalDocCount = 0; |
| 415 | int64 workerTotalDocCountFromStats = 0; |
| 416 | int32 averageDocSize = 0; |
| 417 | |
| 418 | int errorCode = 0; |
| 419 | const char *errorMessage = NULL; |
| 420 | |
| 421 | while (bson_iter_next(&workerIter)) |
| 422 | { |
| 423 | const char *key = bson_iter_key(&workerIter); |
| 424 | if (strcmp(key, ErrCodeKey) == 0) |
| 425 | { |
| 426 | errorCode = BsonValueAsInt32(bson_iter_value(&workerIter)); |
| 427 | } |
| 428 | else if (strcmp(key, ErrMsgKey) == 0) |
| 429 | { |
| 430 | const char *string = bson_iter_utf8(&workerIter, NULL); |
| 431 | errorMessage = pstrdup(string); |
| 432 | } |
| 433 | else if (strcmp(key, "total_rel_size") == 0) |
| 434 | { |
| 435 | /* associative - sum up across nodes */ |
| 436 | int64 value = BsonValueAsInt64(bson_iter_value(&workerIter)); |
| 437 | result->totalSize += value; |
| 438 | } |
| 439 | else if (strcmp(key, "total_tbl_size") == 0) |
| 440 | { |
| 441 | /* associative - sum up across nodes */ |
| 442 | int64 value = BsonValueAsInt64(bson_iter_value(&workerIter)); |
| 443 | result->storageSize += value; |
| 444 | } |
| 445 | else if (strcmp(key, "total_doc_count") == 0) |
| 446 | { |
| 447 | /* |
no test coverage detected