@@ -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+ using StmtBlobs = struct { 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,55 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
617623 }
618624
619625 if (store_record)
626+ {
627+ if (dbb->getEncodedOdsVersion () >= ODS_13_1)
628+ {
629+ FB_UINT64 stmtId;
630+ StmtBlobs stmtBlobs;
631+ dsc desc;
632+
633+ if ((rid == rel_mon_compiled_statements) && EVL_field (nullptr , record, f_mon_cmp_stmt_id, &desc))
634+ {
635+ stmtId = *(FB_UINT64*) desc.dsc_address ;
636+
637+ if (EVL_field (nullptr , record, f_mon_cmp_stmt_sql_text, &desc))
638+ stmtBlobs.text = *reinterpret_cast <bid*>(desc.dsc_address );
639+ else
640+ stmtBlobs.text .clear ();
641+
642+ if (EVL_field (nullptr , record, f_mon_cmp_stmt_expl_plan, &desc))
643+ stmtBlobs.plan = *reinterpret_cast <bid*>(desc.dsc_address );
644+ else
645+ stmtBlobs.plan .clear ();
646+
647+ if (!stmtBlobs.text .isEmpty () || !stmtBlobs.plan .isEmpty ())
648+ blobsMap.put (stmtId, stmtBlobs);
649+ }
650+ else if ((rid == rel_mon_statements) && EVL_field (nullptr , record, f_mon_stmt_cmp_stmt_id, &desc))
651+ {
652+ stmtId = *(FB_UINT64*) desc.dsc_address ;
653+
654+ if (blobsMap.get (stmtId, stmtBlobs))
655+ {
656+ if (!stmtBlobs.text .isEmpty ())
657+ {
658+ record->clearNull (f_mon_stmt_sql_text);
659+ if (EVL_field (nullptr , record, f_mon_stmt_sql_text, &desc))
660+ *reinterpret_cast <bid*>(desc.dsc_address ) = stmtBlobs.text ;
661+ }
662+
663+ if (!stmtBlobs.plan .isEmpty ())
664+ {
665+ record->clearNull (f_mon_stmt_expl_plan);
666+ if (EVL_field (nullptr , record, f_mon_stmt_expl_plan, &desc))
667+ *reinterpret_cast <bid*>(desc.dsc_address ) = stmtBlobs.plan ;
668+ }
669+ }
670+ }
671+ }
672+
620673 buffer->store (record);
674+ }
621675 }
622676}
623677
@@ -1221,13 +1275,17 @@ void Monitoring::putRequest(SnapshotData::DumpRecord& record, const Request* req
12211275
12221276 const Statement* const statement = request->getStatement ();
12231277
1224- // sql text
1225- if (statement->sqlText )
1226- record.storeString (f_mon_stmt_sql_text, *statement->sqlText );
1278+ // Since ODS 13.1 statement text and plan is put into mon$compiled_statements
1279+ if (dbb->getEncodedOdsVersion () < ODS_13_1)
1280+ {
1281+ // sql text
1282+ if (statement->sqlText )
1283+ record.storeString (f_mon_stmt_sql_text, *statement->sqlText );
12271284
1228- // explained plan
1229- if (plan.hasData ())
1230- record.storeString (f_mon_stmt_expl_plan, plan);
1285+ // explained plan
1286+ if (plan.hasData ())
1287+ record.storeString (f_mon_stmt_expl_plan, plan);
1288+ }
12311289
12321290 // statistics
12331291 const int stat_id = fb_utils::genUniqueId ();
@@ -1526,7 +1584,8 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15261584
15271585 if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
15281586 {
1529- const string plan = Optimizer::getPlan (tdbb, statement, true );
1587+ const string plan = (dbb->getEncodedOdsVersion () >= ODS_13_1) ?
1588+ " " : Optimizer::getPlan (tdbb, statement, true );
15301589 putRequest (record, request, plan);
15311590 }
15321591 }
0 commit comments