@@ -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
@@ -1221,13 +1291,17 @@ void Monitoring::putRequest(SnapshotData::DumpRecord& record, const Request* req
12211291
12221292 const Statement* const statement = request->getStatement ();
12231293
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 );
12271300
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+ }
12311305
12321306 // statistics
12331307 const int stat_id = fb_utils::genUniqueId ();
@@ -1506,7 +1580,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15061580
15071581 if (dbb->getEncodedOdsVersion () >= ODS_13_1)
15081582 {
1509- // Statement information
1583+ // Statement information, must be put into dump before requests
15101584
15111585 for (const auto statement : attachment->att_statements )
15121586 {
@@ -1526,7 +1600,8 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15261600
15271601 if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
15281602 {
1529- const string plan = Optimizer::getPlan (tdbb, statement, true );
1603+ const string plan = (dbb->getEncodedOdsVersion () >= ODS_13_1) ?
1604+ " " : Optimizer::getPlan (tdbb, statement, true );
15301605 putRequest (record, request, plan);
15311606 }
15321607 }
0 commit comments