* This is the core logic for coll_stats that executes on * every node in the cluster. */
| 661 | * every node in the cluster. |
| 662 | */ |
| 663 | static pgbson * |
| 664 | CollStatsWorker(void *fcinfoPointer) |
| 665 | { |
| 666 | PG_FUNCTION_ARGS = fcinfoPointer; |
| 667 | Datum databaseName = PG_GETARG_DATUM(0); |
| 668 | Datum collectionName = PG_GETARG_DATUM(1); |
| 669 | |
| 670 | double modeArgument = PG_GETARG_FLOAT8(2); |
| 671 | |
| 672 | |
| 673 | /* Consider this mode in filtering below - but this requires |
| 674 | * the coordinator in a multi-node setup to be on the latest version. |
| 675 | */ |
| 676 | CollStatsAggMode mode = CollStatsAggMode_CountAndStorage; |
| 677 | |
| 678 | /* Ensure proper conversion to enum */ |
| 679 | int argAsInt = (int) floor(modeArgument); |
| 680 | if (argAsInt > CollStatsAggMode_None && |
| 681 | argAsInt <= CollStatsAggMode_Max) |
| 682 | { |
| 683 | mode = argAsInt; |
| 684 | } |
| 685 | |
| 686 | MongoCollection *collection = |
| 687 | GetMongoCollectionByNameDatum(databaseName, |
| 688 | collectionName, |
| 689 | AccessShareLock); |
| 690 | |
| 691 | if (collection == NULL) |
| 692 | { |
| 693 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), |
| 694 | errmsg("Collection could not be found"))); |
| 695 | } |
| 696 | |
| 697 | /* First step, get the relevant shards on this node (We're already in the query worker) */ |
| 698 | ArrayType *shardNames = NULL; |
| 699 | ArrayType *shardOids = NULL; |
| 700 | |
| 701 | /* Next get the relation and table size */ |
| 702 | pgbson_writer writer; |
| 703 | PgbsonWriterInit(&writer); |
| 704 | |
| 705 | /* Only do work if there are shards */ |
| 706 | if (GetMongoCollectionShardOidsAndNames(collection, &shardOids, &shardNames)) |
| 707 | { |
| 708 | Assert(shardNames != NULL); |
| 709 | |
| 710 | /* |
| 711 | * Next get statistics details: Fetch document count from statistics |
| 712 | * We don't do runtime counts here - instead we do it in the coordinator |
| 713 | * if it's needed. |
| 714 | */ |
| 715 | bool isSmallCollection = false; |
| 716 | int64 documentCount = GetPostgresDocumentCountStats(shardOids, |
| 717 | &isSmallCollection); |
| 718 | |
| 719 | PgbsonWriterAppendInt64(&writer, "total_doc_count", 15, documentCount); |
| 720 |
nothing calls this directly
no test coverage detected