mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-26 04:09:50 -05:00
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 -->
This commit is contained in:
1 parent
5a19661e8b
commit
833c4677af
2 files changed
-95
No files matched your search
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user