@@ -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
@@ -1221,13 +1291,17 @@ void Monitoring::putRequest(SnapshotData::DumpRecord& record, const Request* req
1221
1291
1222
1292
const Statement* const statement = request->getStatement ();
1223
1293
1224
- // sql text
1225
- if (statement->sqlText )
1226
- record.storeString (f_mon_stmt_sql_text, *statement->sqlText );
1294
+ // Since ODS 13.1 statement text and plan is put into mon$compiled_statements
1295
+ if (dbb->getEncodedOdsVersion () < ODS_13_1)
1296
+ {
1297
+ // sql text
1298
+ if (statement->sqlText )
1299
+ record.storeString (f_mon_stmt_sql_text, *statement->sqlText );
1227
1300
1228
- // explained plan
1229
- if (plan.hasData ())
1230
- record.storeString (f_mon_stmt_expl_plan, plan);
1301
+ // explained plan
1302
+ if (plan.hasData ())
1303
+ record.storeString (f_mon_stmt_expl_plan, plan);
1304
+ }
1231
1305
1232
1306
// statistics
1233
1307
const int stat_id = fb_utils::genUniqueId ();
@@ -1506,7 +1580,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
1506
1580
1507
1581
if (dbb->getEncodedOdsVersion () >= ODS_13_1)
1508
1582
{
1509
- // Statement information
1583
+ // Statement information, must be put into dump before requests
1510
1584
1511
1585
for (const auto statement : attachment->att_statements )
1512
1586
{
@@ -1526,7 +1600,8 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
1526
1600
1527
1601
if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
1528
1602
{
1529
- const string plan = Optimizer::getPlan (tdbb, statement, true );
1603
+ const string plan = (dbb->getEncodedOdsVersion () >= ODS_13_1) ?
1604
+ " " : Optimizer::getPlan (tdbb, statement, true );
1530
1605
putRequest (record, request, plan);
1531
1606
}
1532
1607
}
0 commit comments