@@ -549,6 +549,12 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
549
549
550
550
// Parse the dump
551
551
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
+
552
558
MonitoringData::Reader reader (pool, temp_space);
553
559
554
560
SnapshotData::DumpRecord dumpRecord (pool);
@@ -617,7 +623,71 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
617
623
}
618
624
619
625
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
+
620
689
buffer->store (record);
690
+ }
621
691
}
622
692
}
623
693
@@ -1228,13 +1298,17 @@ void Monitoring::putRequest(SnapshotData::DumpRecord& record, const Request* req
1228
1298
1229
1299
const Statement* const statement = request->getStatement ();
1230
1300
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 );
1234
1307
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
+ }
1238
1312
1239
1313
// statistics
1240
1314
const int stat_id = fb_utils::genUniqueId ();
@@ -1513,7 +1587,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
1513
1587
1514
1588
if (dbb->getEncodedOdsVersion () >= ODS_13_1)
1515
1589
{
1516
- // Statement information
1590
+ // Statement information, must be put into dump before requests
1517
1591
1518
1592
for (const auto statement : attachment->att_statements )
1519
1593
{
@@ -1533,7 +1607,8 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
1533
1607
1534
1608
if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
1535
1609
{
1536
- const string plan = Optimizer::getPlan (tdbb, statement, true );
1610
+ const string plan = (dbb->getEncodedOdsVersion () >= ODS_13_1) ?
1611
+ " " : Optimizer::getPlan (tdbb, statement, true );
1537
1612
putRequest (record, request, plan);
1538
1613
}
1539
1614
}
0 commit comments