Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2025

Conversation

hvlad
Copy link
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
dsc desc;

if ((rid == rel_mon_compiled_statements) && EVL_field(nullptr, record, f_mon_cmp_stmt_id, &desc))
{
Copy link
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);

{
stmtId = *(FB_UINT64*) desc.dsc_address;

if (EVL_field(nullptr, record, f_mon_cmp_stmt_sql_text, &desc))
Copy link
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());

else
stmtBlobs.text.clear();

if (EVL_field(nullptr, record, f_mon_cmp_stmt_expl_plan, &desc))
Copy link
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());

blobsMap.put(stmtId, stmtBlobs);
}
else if ((rid == rel_mon_statements) && EVL_field(nullptr, record, f_mon_stmt_cmp_stmt_id, &desc))
{
Copy link
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);

if (!stmtBlobs.text.isEmpty())
{
record->clearNull(f_mon_stmt_sql_text);
if (EVL_field(nullptr, record, f_mon_stmt_sql_text, &desc))
Copy link
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());

if (!stmtBlobs.plan.isEmpty())
{
record->clearNull(f_mon_stmt_expl_plan);
if (EVL_field(nullptr, record, f_mon_stmt_expl_plan, &desc))
Copy link
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());

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
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.

@hvlad
Copy link
Member Author

hvlad commented Apr 16, 2025

Any objections to backport it into v5 ?

@dyemanov
Copy link
Member

No, I don't mind.

@aafemt
Copy link
Contributor

aafemt commented Apr 16, 2025

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

@hvlad
Copy link
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
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.

5 participants