From 833c4677af596132610981d92c1915f307cc7dfb Mon Sep 17 00:00:00 2001 From: Parag Jain Date: Mon, 28 Apr 2025 16:42:28 +0000 Subject: [PATCH] Merged PR 1655313: [Cleanup] Removing Insert dead code for old implementation of $out ### Does this PR have any customer impact? ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) ### Are you introducing any new config? If yes, do you have tests with and without them being set? ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description Removing Insert dead code ---- #### AI description (iteration 1) #### PR Classification Code cleanup #### PR Summary This pull request removes dead code related to the `TryInsertOne` function, which is no longer needed in the codebase. - Removed the `TryInsertOne` function from `src/commands/insert.c`. - Deleted the `TryInsertOne` function declaration from `include/commands/insert.h`. --- pg_documentdb/include/commands/insert.h | 5 -- pg_documentdb/src/commands/insert.c | 90 ------------------------- 2 files changed, 95 deletions(-) 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. */