diff --git a/pg_documentdb/include/commands/insert.h b/pg_documentdb/include/commands/insert.h index b3de1ad2..b515c4cb 100644 --- a/pg_documentdb/include/commands/insert.h +++ b/pg_documentdb/include/commands/insert.h @@ -21,9 +21,4 @@ bool InsertDocument(uint64 collectionId, const char *shardTableName, int64 shard bool InsertOrReplaceDocument(uint64 collectionId, const char *shardTableName, int64 shardKeyValue, pgbson *objectId, pgbson *document); - -bool InsertDocumentToTempCollection(MongoCollection *collection, int64 shardKeyValue, - pgbson *document); -bool TryInsertOne(MongoCollection *collection, pgbson *document, int64 shardKeyHash, bool - sameSourceAndTarget, WriteError *writeError); #endif diff --git a/pg_documentdb/src/commands/insert.c b/pg_documentdb/src/commands/insert.c index 4d7f7a4f..7fa67054 100644 --- a/pg_documentdb/src/commands/insert.c +++ b/pg_documentdb/src/commands/insert.c @@ -1040,58 +1040,6 @@ CallInsertWorkerForInsertOne(MongoCollection *collection, int64 shardKeyHash, } -bool -TryInsertOne(MongoCollection *collection, pgbson *document, int64 shardKeyHash, bool - sameSourceAndTarget, WriteError *writeError) -{ - volatile bool rowsInserted = false; - MemoryContext oldContext = CurrentMemoryContext; - ResourceOwner oldOwner = CurrentResourceOwner; - - BeginInternalSubTransaction(NULL); - - PG_TRY(); - { - if (sameSourceAndTarget) - { - rowsInserted = InsertDocumentToTempCollection(collection, - shardKeyHash, document); - } - else - { - rowsInserted = InsertDocument(collection->collectionId, - collection->shardTableName, - shardKeyHash, PgbsonGetDocumentId(document), - document); - } - ReleaseCurrentSubTransaction(); - MemoryContextSwitchTo(oldContext); - CurrentResourceOwner = oldOwner; - } - PG_CATCH(); - { - MemoryContextSwitchTo(oldContext); - - ErrorData *errorData = CopyErrorDataAndFlush(); - if (writeError != NULL) - { - writeError->code = errorData->sqlerrcode; - writeError->errmsg = errorData->message; - } - - /* Abort the inner transaction */ - RollbackAndReleaseCurrentSubTransaction(); - MemoryContextSwitchTo(oldContext); - CurrentResourceOwner = oldOwner; - - rowsInserted = false; - } - PG_END_TRY(); - - return rowsInserted; -} - - /* * command_insert_one is the internal implementation of the db.collection.insertOne() API. */ @@ -1302,44 +1250,6 @@ InsertOrReplaceDocument(uint64 collectionId, const char *shardTableName, int64 } -bool -InsertDocumentToTempCollection(MongoCollection *collection, int64 shardKeyValue, - pgbson *document) -{ - const int argCount = 3; - Oid argTypes[3]; - Datum argValues[3]; - pgbson *objectId = PgbsonGetDocumentId(document); - StringInfoData query; - int spiStatus PG_USED_FOR_ASSERTS_ONLY = 0; - - SPI_connect(); - initStringInfo(&query); - appendStringInfo(&query, - "INSERT INTO \"%s\"" - " (shard_key_value, object_id, document) " - " VALUES ($1, %s.bson_from_bytea($2), " - "%s.bson_from_bytea($3))", collection->tableName, - CoreSchemaName, CoreSchemaName); - argTypes[0] = INT8OID; - argValues[0] = Int64GetDatum(shardKeyValue); - argTypes[1] = BYTEAOID; - argValues[1] = PointerGetDatum(CastPgbsonToBytea(objectId)); - argTypes[2] = BYTEAOID; - argValues[2] = PointerGetDatum(CastPgbsonToBytea(document)); - - SPIPlanPtr plan = GetSPIQueryPlan(collection->collectionId, QUERY_ID_INSERT, - query.data, argTypes, argCount); - - spiStatus = SPI_execute_plan(plan, argValues, NULL, false, 1); - pfree(query.data); - - SPI_finish(); - - return spiStatus == SPI_OK_INSERT; -} - - /* * BuildResponseMessage builds the response BSON for an insert command. */