* command_create_indexes is the implementation of the internal logic for * ApiSchema.create_indexes(). */
| 643 | * ApiSchema.create_indexes(). |
| 644 | */ |
| 645 | void |
| 646 | command_create_indexes(const CallStmt *callStmt, ProcessUtilityContext context, |
| 647 | const ParamListInfo params, DestReceiver *destReceiver) |
| 648 | { |
| 649 | /* must name it as "fcinfo" to be able to use PG_ARG/PG_GETARG functions */ |
| 650 | LOCAL_FCINFO(fcinfo, FUNC_MAX_ARGS); |
| 651 | InitFCInfoForCallStmt(fcinfo, callStmt, context, params); |
| 652 | |
| 653 | if (PG_ARGISNULL(1)) |
| 654 | { |
| 655 | ereport(ERROR, (errmsg("arg cannot be NULL"))); |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * Deduplicate elements of given bson object recursively so that we don't |
| 660 | * have multiple definitions for any bson field at any level. |
| 661 | * |
| 662 | * That way, we will not throw an error; |
| 663 | * - if we encounter with definition of a field more than once, or |
| 664 | * - if there is a syntax error in the prior definitions. e.g.: |
| 665 | * {"createIndexes": 1, "createIndexes": "my_collection_name"} |
| 666 | */ |
| 667 | pgbson *arg = PgbsonDeduplicateFields(PG_GETARG_PGBSON(1)); |
| 668 | Datum dbNameDatum = PG_ARGISNULL(0) ? (Datum) 0 : PG_GETARG_DATUM(0); |
| 669 | |
| 670 | bool buildAsUniqueForPrepareUnique = false; |
| 671 | CreateIndexesArg createIndexesArg = ParseCreateIndexesArg(&dbNameDatum, |
| 672 | arg, |
| 673 | buildAsUniqueForPrepareUnique); |
| 674 | |
| 675 | if (dbNameDatum == (Datum) 0) |
| 676 | { |
| 677 | ereport(ERROR, (errmsg("dbName cannot be NULL"))); |
| 678 | } |
| 679 | bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL); |
| 680 | bool buildIndexesConcurrently = !IsInTransactionBlock(isTopLevel); |
| 681 | buildIndexesConcurrently &= !createIndexesArg.blocking; |
| 682 | bool skipCheckCollectionCreate = createIndexesArg.blocking; |
| 683 | bool uniqueIndexOnly = false; |
| 684 | CreateIndexesResult result = buildIndexesConcurrently ? |
| 685 | create_indexes_concurrently(dbNameDatum, |
| 686 | createIndexesArg, |
| 687 | uniqueIndexOnly) : |
| 688 | create_indexes_non_concurrently(dbNameDatum, |
| 689 | createIndexesArg, |
| 690 | skipCheckCollectionCreate, |
| 691 | uniqueIndexOnly); |
| 692 | |
| 693 | SendCreateIndexesResultToClientAsBson(fcinfo, &result, destReceiver); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | /* |
nothing calls this directly
no test coverage detected