* Updates the ApiCatalogSchemaName.collection_indexes metadata table with the requested updates */
| 653 | * Updates the ApiCatalogSchemaName.collection_indexes metadata table with the requested updates |
| 654 | */ |
| 655 | static void |
| 656 | ModifyIndexSpecsInCollection(const MongoCollection *collection, |
| 657 | const CollModIndexOptions *indexOption, |
| 658 | const CollModSpecFlags *specFlags, |
| 659 | pgbson_writer *writer) |
| 660 | { |
| 661 | StringInfo cmdStr = makeStringInfo(); |
| 662 | bool searchWithName = *specFlags & HAS_INDEX_OPTION_NAME; |
| 663 | appendStringInfo(cmdStr, |
| 664 | "SELECT index_id, index_spec, index_is_valid " |
| 665 | "FROM %s.collection_indexes " |
| 666 | "WHERE collection_id = $2 AND (index_spec).%s = $1;", |
| 667 | ApiCatalogSchemaName, |
| 668 | searchWithName ? "index_name" : "index_key"); |
| 669 | |
| 670 | int argCount = 2; |
| 671 | Oid argTypes[2]; |
| 672 | Datum argValues[2]; |
| 673 | |
| 674 | if (searchWithName) |
| 675 | { |
| 676 | argTypes[0] = TEXTOID; |
| 677 | argValues[0] = CStringGetTextDatum(indexOption->name); |
| 678 | } |
| 679 | else |
| 680 | { |
| 681 | argTypes[0] = BsonTypeId(); |
| 682 | argValues[0] = PointerGetDatum(indexOption->keyPattern); |
| 683 | } |
| 684 | |
| 685 | argTypes[1] = INT8OID; |
| 686 | argValues[1] = UInt64GetDatum(collection->collectionId); |
| 687 | |
| 688 | /* all args are non-null */ |
| 689 | char *argNulls = NULL; |
| 690 | bool readOnly = true; |
| 691 | int numValues = 3; |
| 692 | bool isNull[3]; |
| 693 | Datum results[3]; |
| 694 | ExtensionExecuteMultiValueQueryWithArgsViaSPI(cmdStr->data, argCount, argTypes, |
| 695 | argValues, argNulls, readOnly, |
| 696 | SPI_OK_SELECT, results, isNull, |
| 697 | numValues); |
| 698 | if (isNull[0]) |
| 699 | { |
| 700 | /* No matching index found with the criteria */ |
| 701 | ereport(ERROR, |
| 702 | (errcode(ERRCODE_DOCUMENTDB_INDEXNOTFOUND), |
| 703 | errmsg("cannot find index %s for ns %s.%s", |
| 704 | searchWithName ? indexOption->name : PgbsonToJsonForLogging( |
| 705 | indexOption->keyPattern), |
| 706 | collection->name.databaseName, collection->name.collectionName))); |
| 707 | } |
| 708 | |
| 709 | IndexDetails indexDetails = { 0 }; |
| 710 | indexDetails.indexId = DatumGetInt32(results[0]); |
| 711 | indexDetails.indexSpec = *DatumGetIndexSpec(results[1]); |
| 712 | indexDetails.collectionId = collection->collectionId; |
no test coverage detected