* This takes the output from each worker and creates an aggregated view * which dumps one row per index in the wire compatible format */
| 337 | * which dumps one row per index in the wire compatible format |
| 338 | */ |
| 339 | static void |
| 340 | MergeWorkerResults(MongoCollection *collection, List *workerResults, |
| 341 | Tuplestorestate *tupleStore, TupleDesc tupleDescriptor) |
| 342 | { |
| 343 | List *indexDocs = ParseWorkerResults(workerResults); |
| 344 | |
| 345 | bool excludeIdIndex = false; |
| 346 | |
| 347 | /* Since index_stats can be executed in a $lookup/$unionWith |
| 348 | * It can run on a worker querying the coordinator - we would need |
| 349 | * nested distributed execution. |
| 350 | */ |
| 351 | bool enableNestedDistribution = true; |
| 352 | List *indexes = CollectionIdGetIndexes(collection->collectionId, excludeIdIndex, |
| 353 | enableNestedDistribution); |
| 354 | |
| 355 | HTAB *bsonElementHash = CreatePgbsonElementHashSet(); |
| 356 | |
| 357 | /* First run through the worker index docs - |
| 358 | * For each doc, add the { "indexName": (int64)indexAccesses } |
| 359 | * into the bsonElement hash. If the entry for that indexName |
| 360 | * already exists, add to the existing size. |
| 361 | */ |
| 362 | ListCell *indexCell; |
| 363 | foreach(indexCell, indexDocs) |
| 364 | { |
| 365 | bson_value_t *value = lfirst(indexCell); |
| 366 | bson_iter_t indexDocIter; |
| 367 | BsonValueInitIterator(value, &indexDocIter); |
| 368 | |
| 369 | while (bson_iter_next(&indexDocIter)) |
| 370 | { |
| 371 | pgbsonelement element = { 0 }; |
| 372 | element.path = bson_iter_key(&indexDocIter); |
| 373 | element.pathLength = bson_iter_key_len(&indexDocIter); |
| 374 | element.bsonValue = *bson_iter_value(&indexDocIter); |
| 375 | |
| 376 | bool found = false; |
| 377 | pgbsonelement *foundVal = hash_search(bsonElementHash, &element, HASH_ENTER, |
| 378 | &found); |
| 379 | if (found) |
| 380 | { |
| 381 | bool overflowedIgnore = false; |
| 382 | AddNumberToBsonValue(&foundVal->bsonValue, &element.bsonValue, |
| 383 | &overflowedIgnore); |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /* Extract postmaster start time */ |
| 389 | TimestampTz timestamp = PgStartTime; |
| 390 | |
| 391 | bson_value_t startTimeValue = { 0 }; |
| 392 | startTimeValue.value_type = BSON_TYPE_DATE_TIME; |
| 393 | startTimeValue.value.v_datetime = GetDateTimeFromTimestamp(timestamp); |
| 394 | |
| 395 | /* Now write one row per index based on the collection indexes */ |
| 396 | ListCell *cell; |
no test coverage detected