Skip to content

Commit 1168eb2

Browse files
committed
Eliminate one coercion stage for input data
1 parent b85dbf5 commit 1168eb2

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/dsql/DsqlRequests.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ bool DsqlDmlRequest::fetch(thread_db* tdbb, UCHAR* msgBuffer)
418418
// and outMetadata and outMsg in not used there, so passing NULL's is safe.
419419
jrd_tra* tra = req_transaction;
420420

421-
executeReceiveWithRestarts(tdbb, &tra, NULL, msgBuffer, false, false, true);
421+
executeReceiveWithRestarts(tdbb, &tra, nullptr, nullptr, msgBuffer, false, false, true);
422422
fb_assert(tra == req_transaction);
423423
}
424424
else
@@ -572,7 +572,7 @@ bool DsqlDmlRequest::needRestarts()
572572

573573
// Execute a dynamic SQL statement
574574
void DsqlDmlRequest::doExecute(thread_db* tdbb, jrd_tra** traHandle,
575-
IMessageMetadata* outMetadata, UCHAR* outMsg,
575+
const UCHAR* inMsg, IMessageMetadata* outMetadata, UCHAR* outMsg,
576576
bool singleton)
577577
{
578578
firstRowFetched = false;
@@ -584,9 +584,13 @@ void DsqlDmlRequest::doExecute(thread_db* tdbb, jrd_tra** traHandle,
584584
}
585585
else
586586
{
587-
UCHAR* msgBuffer = req_msg_buffers[message->msg_buffer_number];
587+
MessageNode* msg = dsqlStatement->getStatement()->messages[message->msg_number];
588+
589+
fb_assert(msg != nullptr && inMsg != nullptr);
590+
591+
ULONG inMsgLength = msg->getFormat(request)->fmt_length;
588592
JRD_start_and_send(tdbb, request, req_transaction, message->msg_number,
589-
message->msg_length, msgBuffer);
593+
inMsgLength, inMsg);
590594
}
591595

592596
// Selectable execute block should get the "proc fetch" flag assigned,
@@ -682,7 +686,12 @@ void DsqlDmlRequest::execute(thread_db* tdbb, jrd_tra** traHandle,
682686
const dsql_msg* message = dsqlStatement->getSendMsg();
683687
if (message)
684688
{
685-
mapInOut(tdbb, false, message, inMetadata, NULL, inMsg);
689+
// If this is not first call of execute(), metadata most likely is already converted to message
690+
// but there is no easy way to check if they match so conversion is unconditional.
691+
// Even if value of inMetadata is the same, other instance could be placed in the same memory.
692+
// Even if the instance is the same, its content may be different from previous call.
693+
MessageNode* msg = dsqlStatement->getStatement()->messages[message->msg_number];
694+
metadataToFormat(inMetadata, msg);
686695
}
687696

688697
// we need to mapInOut() before tracing of execution start to let trace
@@ -696,15 +705,16 @@ void DsqlDmlRequest::execute(thread_db* tdbb, jrd_tra** traHandle,
696705
thread_db::TimerGuard timerGuard(tdbb, req_timer, !have_cursor);
697706

698707
if (needRestarts())
699-
executeReceiveWithRestarts(tdbb, traHandle, outMetadata, outMsg, singleton, true, false);
708+
executeReceiveWithRestarts(tdbb, traHandle, inMsg, outMetadata, outMsg, singleton, true, false);
700709
else {
701-
doExecute(tdbb, traHandle, outMetadata, outMsg, singleton);
710+
doExecute(tdbb, traHandle, inMsg, outMetadata, outMsg, singleton);
702711
}
703712

704713
trace.finish(have_cursor, ITracePlugin::RESULT_SUCCESS);
705714
}
706715

707716
void DsqlDmlRequest::executeReceiveWithRestarts(thread_db* tdbb, jrd_tra** traHandle,
717+
const UCHAR* inMsg,
708718
IMessageMetadata* outMetadata, UCHAR* outMsg,
709719
bool singleton, bool exec, bool fetch)
710720
{
@@ -724,7 +734,7 @@ void DsqlDmlRequest::executeReceiveWithRestarts(thread_db* tdbb, jrd_tra** traHa
724734
try
725735
{
726736
if (exec)
727-
doExecute(tdbb, traHandle, outMetadata, outMsg, singleton);
737+
doExecute(tdbb, traHandle, inMsg, outMetadata, outMsg, singleton);
728738

729739
if (fetch)
730740
{

src/dsql/DsqlRequests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,13 @@ class DsqlDmlRequest final : public DsqlRequest
186186
bool needRestarts();
187187

188188
void doExecute(thread_db* tdbb, jrd_tra** traHandle,
189+
const UCHAR* inMsg, // Only data buffer, metadata must be synchronized before call
189190
Firebird::IMessageMetadata* outMetadata, UCHAR* outMsg,
190191
bool singleton);
191192

192193
// [Re]start part of "request restarts" algorithm
193194
void executeReceiveWithRestarts(thread_db* tdbb, jrd_tra** traHandle,
195+
const UCHAR* inMsg,
194196
Firebird::IMessageMetadata* outMetadata, UCHAR* outMsg,
195197
bool singleton, bool exec, bool fetch);
196198

0 commit comments

Comments
 (0)