Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 833c467

Browse files
LordParagshuaitian-git
authored andcommitted
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`. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
1 parent 5a19661 commit 833c467

File tree

2 files changed

+0
-95
lines changed

2 files changed

+0
-95
lines changed

pg_documentdb/include/commands/insert.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,4 @@ bool InsertDocument(uint64 collectionId, const char *shardTableName, int64 shard
2121
bool InsertOrReplaceDocument(uint64 collectionId, const char *shardTableName, int64
2222
shardKeyValue,
2323
pgbson *objectId, pgbson *document);
24-
25-
bool InsertDocumentToTempCollection(MongoCollection *collection, int64 shardKeyValue,
26-
pgbson *document);
27-
bool TryInsertOne(MongoCollection *collection, pgbson *document, int64 shardKeyHash, bool
28-
sameSourceAndTarget, WriteError *writeError);
2924
#endif

pg_documentdb/src/commands/insert.c

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,58 +1040,6 @@ CallInsertWorkerForInsertOne(MongoCollection *collection, int64 shardKeyHash,
10401040
}
10411041

10421042

1043-
bool
1044-
TryInsertOne(MongoCollection *collection, pgbson *document, int64 shardKeyHash, bool
1045-
sameSourceAndTarget, WriteError *writeError)
1046-
{
1047-
volatile bool rowsInserted = false;
1048-
MemoryContext oldContext = CurrentMemoryContext;
1049-
ResourceOwner oldOwner = CurrentResourceOwner;
1050-
1051-
BeginInternalSubTransaction(NULL);
1052-
1053-
PG_TRY();
1054-
{
1055-
if (sameSourceAndTarget)
1056-
{
1057-
rowsInserted = InsertDocumentToTempCollection(collection,
1058-
shardKeyHash, document);
1059-
}
1060-
else
1061-
{
1062-
rowsInserted = InsertDocument(collection->collectionId,
1063-
collection->shardTableName,
1064-
shardKeyHash, PgbsonGetDocumentId(document),
1065-
document);
1066-
}
1067-
ReleaseCurrentSubTransaction();
1068-
MemoryContextSwitchTo(oldContext);
1069-
CurrentResourceOwner = oldOwner;
1070-
}
1071-
PG_CATCH();
1072-
{
1073-
MemoryContextSwitchTo(oldContext);
1074-
1075-
ErrorData *errorData = CopyErrorDataAndFlush();
1076-
if (writeError != NULL)
1077-
{
1078-
writeError->code = errorData->sqlerrcode;
1079-
writeError->errmsg = errorData->message;
1080-
}
1081-
1082-
/* Abort the inner transaction */
1083-
RollbackAndReleaseCurrentSubTransaction();
1084-
MemoryContextSwitchTo(oldContext);
1085-
CurrentResourceOwner = oldOwner;
1086-
1087-
rowsInserted = false;
1088-
}
1089-
PG_END_TRY();
1090-
1091-
return rowsInserted;
1092-
}
1093-
1094-
10951043
/*
10961044
* command_insert_one is the internal implementation of the db.collection.insertOne() API.
10971045
*/
@@ -1302,44 +1250,6 @@ InsertOrReplaceDocument(uint64 collectionId, const char *shardTableName, int64
13021250
}
13031251

13041252

1305-
bool
1306-
InsertDocumentToTempCollection(MongoCollection *collection, int64 shardKeyValue,
1307-
pgbson *document)
1308-
{
1309-
const int argCount = 3;
1310-
Oid argTypes[3];
1311-
Datum argValues[3];
1312-
pgbson *objectId = PgbsonGetDocumentId(document);
1313-
StringInfoData query;
1314-
int spiStatus PG_USED_FOR_ASSERTS_ONLY = 0;
1315-
1316-
SPI_connect();
1317-
initStringInfo(&query);
1318-
appendStringInfo(&query,
1319-
"INSERT INTO \"%s\""
1320-
" (shard_key_value, object_id, document) "
1321-
" VALUES ($1, %s.bson_from_bytea($2), "
1322-
"%s.bson_from_bytea($3))", collection->tableName,
1323-
CoreSchemaName, CoreSchemaName);
1324-
argTypes[0] = INT8OID;
1325-
argValues[0] = Int64GetDatum(shardKeyValue);
1326-
argTypes[1] = BYTEAOID;
1327-
argValues[1] = PointerGetDatum(CastPgbsonToBytea(objectId));
1328-
argTypes[2] = BYTEAOID;
1329-
argValues[2] = PointerGetDatum(CastPgbsonToBytea(document));
1330-
1331-
SPIPlanPtr plan = GetSPIQueryPlan(collection->collectionId, QUERY_ID_INSERT,
1332-
query.data, argTypes, argCount);
1333-
1334-
spiStatus = SPI_execute_plan(plan, argValues, NULL, false, 1);
1335-
pfree(query.data);
1336-
1337-
SPI_finish();
1338-
1339-
return spiStatus == SPI_OK_INSERT;
1340-
}
1341-
1342-
13431253
/*
13441254
* BuildResponseMessage builds the response BSON for an insert command.
13451255
*/

0 commit comments

Comments
 (0)