Skip to content

Makes MON$COMPILED_STATEMENTS and MON$STATEMENTS share blobs with text and plan content of the same statement.#8513

Merged
hvlad merged 3 commits intomasterfrom
work/mon_stmt_blobs
Apr 12, 2025
Merged

Makes MON$COMPILED_STATEMENTS and MON$STATEMENTS share blobs with text and plan content of the same statement.#8513
hvlad merged 3 commits intomasterfrom
work/mon_stmt_blobs

Conversation

@hvlad
Copy link
Copy Markdown
Member

@hvlad hvlad commented Apr 11, 2025

Table MON$COMPILED_STATEMENTS introduced in ODS 13.1 with FB5 contains MON$SQL_TEXT and MON$EXPLAINED_PLAN fields that duplicate contents of the same fields in MON$STATEMENTS. The size of SQL text and explained plan could be relatively big, thus it is feasible to not duplicate its, saving memory, disk and CPU circles.

This PR makes engine to put statement text and plan into MON$COMPILED_STATEMENTS only and share blobs with corresponding record in MON$STATEMENTS (if present).

@hvlad hvlad self-assigned this Apr 11, 2025
@hvlad hvlad requested a review from dyemanov April 11, 2025 07:52
Comment thread src/jrd/Monitoring.cpp
dsc desc;

if ((rid == rel_mon_compiled_statements) && EVL_field(nullptr, record, f_mon_cmp_stmt_id, &desc))
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fb_assert(desc.dsc_dtype == dtype_int64);

Comment thread src/jrd/Monitoring.cpp
{
stmtId = *(FB_UINT64*) desc.dsc_address;

if (EVL_field(nullptr, record, f_mon_cmp_stmt_sql_text, &desc))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fb_assert(desc.isBlob());

Comment thread src/jrd/Monitoring.cpp
else
stmtBlobs.text.clear();

if (EVL_field(nullptr, record, f_mon_cmp_stmt_expl_plan, &desc))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fb_assert(desc.isBlob());

Comment thread src/jrd/Monitoring.cpp
blobsMap.put(stmtId, stmtBlobs);
}
else if ((rid == rel_mon_statements) && EVL_field(nullptr, record, f_mon_stmt_cmp_stmt_id, &desc))
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fb_assert(desc.dsc_dtype == dtype_int64);

Comment thread src/jrd/Monitoring.cpp
if (!stmtBlobs.text.isEmpty())
{
record->clearNull(f_mon_stmt_sql_text);
if (EVL_field(nullptr, record, f_mon_stmt_sql_text, &desc))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fb_assert(desc.isBlob());

Comment thread src/jrd/Monitoring.cpp
if (!stmtBlobs.plan.isEmpty())
{
record->clearNull(f_mon_stmt_expl_plan);
if (EVL_field(nullptr, record, f_mon_stmt_expl_plan, &desc))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fb_assert(desc.isBlob());

Comment thread src/jrd/Monitoring.cpp
if (!stmtBlobs.text.isEmpty() || !stmtBlobs.plan.isEmpty())
blobsMap.put(stmtId, stmtBlobs);
}
else if ((rid == rel_mon_statements) && EVL_field(nullptr, record, f_mon_stmt_cmp_stmt_id, &desc))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment that here we assume that compiled statements are stored in the dump before requests.

Comment thread src/jrd/Monitoring.cpp Outdated
@hvlad
Copy link
Copy Markdown
Member Author

hvlad commented Apr 16, 2025

Any objections to backport it into v5 ?

@dyemanov
Copy link
Copy Markdown
Member

No, I don't mind.

@aafemt
Copy link
Copy Markdown
Contributor

aafemt commented Apr 16, 2025

Was it tested enough for a branch which is supposed to be stable?

@hvlad
Copy link
Copy Markdown
Member Author

hvlad commented Apr 16, 2025

Was it tested enough for a branch which is supposed to be stable?

There is QA test for it. Also, snapshots of v5 often used by users.
Last, feel free to break it.

hvlad added a commit that referenced this pull request Apr 17, 2025
Makes MON$COMPILED_STATEMENTS and MON$STATEMENTS share blobs with text and plan content of the same statement.
@hvlad hvlad deleted the work/mon_stmt_blobs branch April 17, 2025 06:30
@mrotteveel mrotteveel added the rlsnotes60: no Intentionally not added to the Firebird 6.0 release notes. label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants