Skip to content

Commit 475d999

Browse files
committed
Merge pull request #8513 from FirebirdSQL/work/mon_stmt_blobs
Makes MON$COMPILED_STATEMENTS and MON$STATEMENTS share blobs with text and plan content of the same statement.
1 parent 8993a57 commit 475d999

File tree

1 file changed

+83
-8
lines changed

1 file changed

+83
-8
lines changed

src/jrd/Monitoring.cpp

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
549549

550550
// Parse the dump
551551

552+
// BlobID's of statement text and plan
553+
struct StmtBlobs { bid text; bid plan; };
554+
555+
// Map compiled statement id to blobs ids
556+
NonPooledMap<FB_UINT64, StmtBlobs> blobsMap(pool);
557+
552558
MonitoringData::Reader reader(pool, temp_space);
553559

554560
SnapshotData::DumpRecord dumpRecord(pool);
@@ -617,7 +623,71 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
617623
}
618624

619625
if (store_record)
626+
{
627+
if (dbb->getEncodedOdsVersion() >= ODS_13_1)
628+
{
629+
// The code below requires that rel_mon_compiled_statements put
630+
// into dump before rel_mon_statements, see also dumpAttachment()
631+
632+
FB_UINT64 stmtId;
633+
StmtBlobs stmtBlobs;
634+
dsc desc;
635+
636+
if ((rid == rel_mon_compiled_statements) && EVL_field(nullptr, record, f_mon_cmp_stmt_id, &desc))
637+
{
638+
fb_assert(desc.dsc_dtype == dtype_int64);
639+
stmtId = *(FB_UINT64*) desc.dsc_address;
640+
641+
if (EVL_field(nullptr, record, f_mon_cmp_stmt_sql_text, &desc))
642+
{
643+
fb_assert(desc.isBlob());
644+
stmtBlobs.text = *reinterpret_cast<bid*>(desc.dsc_address);
645+
}
646+
else
647+
stmtBlobs.text.clear();
648+
649+
if (EVL_field(nullptr, record, f_mon_cmp_stmt_expl_plan, &desc))
650+
{
651+
fb_assert(desc.isBlob());
652+
stmtBlobs.plan = *reinterpret_cast<bid*>(desc.dsc_address);
653+
}
654+
else
655+
stmtBlobs.plan.clear();
656+
657+
if (!stmtBlobs.text.isEmpty() || !stmtBlobs.plan.isEmpty())
658+
blobsMap.put(stmtId, stmtBlobs);
659+
}
660+
else if ((rid == rel_mon_statements) && EVL_field(nullptr, record, f_mon_stmt_cmp_stmt_id, &desc))
661+
{
662+
fb_assert(desc.dsc_dtype == dtype_int64);
663+
stmtId = *(FB_UINT64*) desc.dsc_address;
664+
665+
if (blobsMap.get(stmtId, stmtBlobs))
666+
{
667+
if (!stmtBlobs.text.isEmpty())
668+
{
669+
record->clearNull(f_mon_stmt_sql_text);
670+
if (EVL_field(nullptr, record, f_mon_stmt_sql_text, &desc))
671+
{
672+
fb_assert(desc.isBlob());
673+
*reinterpret_cast<bid*>(desc.dsc_address) = stmtBlobs.text;
674+
}
675+
}
676+
if (!stmtBlobs.plan.isEmpty())
677+
{
678+
record->clearNull(f_mon_stmt_expl_plan);
679+
if (EVL_field(nullptr, record, f_mon_stmt_expl_plan, &desc))
680+
{
681+
fb_assert(desc.isBlob());
682+
*reinterpret_cast<bid*>(desc.dsc_address) = stmtBlobs.plan;
683+
}
684+
}
685+
}
686+
}
687+
}
688+
620689
buffer->store(record);
690+
}
621691
}
622692
}
623693

@@ -1228,13 +1298,17 @@ void Monitoring::putRequest(SnapshotData::DumpRecord& record, const Request* req
12281298

12291299
const Statement* const statement = request->getStatement();
12301300

1231-
// sql text
1232-
if (statement->sqlText)
1233-
record.storeString(f_mon_stmt_sql_text, *statement->sqlText);
1301+
// Since ODS 13.1 statement text and plan is put into mon$compiled_statements
1302+
if (dbb->getEncodedOdsVersion() < ODS_13_1)
1303+
{
1304+
// sql text
1305+
if (statement->sqlText)
1306+
record.storeString(f_mon_stmt_sql_text, *statement->sqlText);
12341307

1235-
// explained plan
1236-
if (plan.hasData())
1237-
record.storeString(f_mon_stmt_expl_plan, plan);
1308+
// explained plan
1309+
if (plan.hasData())
1310+
record.storeString(f_mon_stmt_expl_plan, plan);
1311+
}
12381312

12391313
// statistics
12401314
const int stat_id = fb_utils::genUniqueId();
@@ -1513,7 +1587,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15131587

15141588
if (dbb->getEncodedOdsVersion() >= ODS_13_1)
15151589
{
1516-
// Statement information
1590+
// Statement information, must be put into dump before requests
15171591

15181592
for (const auto statement : attachment->att_statements)
15191593
{
@@ -1533,7 +1607,8 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15331607

15341608
if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
15351609
{
1536-
const string plan = Optimizer::getPlan(tdbb, statement, true);
1610+
const string plan = (dbb->getEncodedOdsVersion() >= ODS_13_1) ?
1611+
"" : Optimizer::getPlan(tdbb, statement, true);
15371612
putRequest(record, request, plan);
15381613
}
15391614
}

0 commit comments

Comments
 (0)