Skip to content
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

Add table MON$COMPILED_STATEMENTS and columns #7050

Merged
merged 3 commits into from
Feb 7, 2022

Conversation

asfernandes
Copy link
Member

@asfernandes asfernandes commented Nov 24, 2021

MON$STATEMENTS.MON$COMPILED_STATEMENT_ID and MON$CALL_STACK.MON$COMPILED_STATEMENT_ID.

Request ID is incremented every time it's started.

…ILED_STATEMENT_ID and MON$CALL_STACK.MON$COMPILED_STATEMENT_ID.
@asfernandes
Copy link
Member Author

While not required, I have made the first request incarnation to use the same ID of the statement.

Statement and request IDs shares the same counter.

@asfernandes
Copy link
Member Author

Here is a test I used:

create or alter procedure p0(n integer)
as
    declare v integer;
begin
    if (n = 0) then
        select first 1 1 from mon$statements into v;
    else
        execute procedure p0(n - 1);
end!

create or alter procedure p1
as
begin
    execute procedure p0(2);
end!

commit!

execute procedure p1!

select * from mon$statements!
select * from mon$compiled_statements!
select * from mon$call_stack!
     MON$STATEMENT_ID     MON$ATTACHMENT_ID    MON$TRANSACTION_ID MON$STATE                                             MON$TIMESTAMP      MON$SQL_TEXT  MON$STAT_ID MON$EXPLAINED_PLAN MON$STATEMENT_TIMEOUT                                       MON$STATEMENT_TIMER MON$COMPILED_STATEMENT_ID 
===================== ===================== ===================== ========= ========================================================= ================= ============ ================== ===================== ========================================================= ========================= 
                   39                     3                     6         1 2021-11-24 11:35:56.5030 America/Sao_Paulo                              0:3           66             <null>                     0                                                    <null>                        39 
==============================================================================
MON$SQL_TEXT:  
execute procedure p1
==============================================================================
MON$COMPILED_STATEMENT_ID      MON$SQL_TEXT MON$EXPLAINED_PLAN MON$OBJECT_NAME                                                 MON$OBJECT_TYPE MON$PACKAGE_NAME                                                
========================= ================= ================== =============================================================== =============== =============================================================== 
                       39               0:1             <null> <null>                                                                   <null> <null>                                                          
==============================================================================
MON$SQL_TEXT:  
execute procedure p1
==============================================================================
                       41            <null>                0:2 P0                                                                            5 <null>                                                          
==============================================================================
MON$EXPLAINED_PLAN:  

Select Expression
    -> Singularity Check
        -> First N Records
            -> Table "MON$STATEMENTS" Full Scan
==============================================================================
                       40            <null>             <null> P1                                                                            5 <null>                                                          
          MON$CALL_ID      MON$STATEMENT_ID         MON$CALLER_ID MON$OBJECT_NAME                                                 MON$OBJECT_TYPE                                             MON$TIMESTAMP MON$SOURCE_LINE MON$SOURCE_COLUMN  MON$STAT_ID MON$PACKAGE_NAME                                                MON$COMPILED_STATEMENT_ID 
===================== ===================== ===================== =============================================================== =============== ========================================================= =============== ================= ============ =============================================================== ========================= 
                   43                    39                    42 P0                                                                            5 2021-11-24 11:35:56.5030 America/Sao_Paulo                              6                 9           54 <null>                                                                                 41 
                   42                    39                    41 P0                                                                            5 2021-11-24 11:35:56.5030 America/Sao_Paulo                              8                 9           57 <null>                                                                                 41 
                   41                    39                    40 P0                                                                            5 2021-11-24 11:35:56.5030 America/Sao_Paulo                              8                 9           60 <null>                                                                                 41 
                   40                    39                <null> P1                                                                            5 2021-11-24 11:35:56.5030 America/Sao_Paulo                              4                 5           63 <null>                                                                                 40 

@livius2
Copy link

livius2 commented Dec 8, 2021

Can this afffect performance in bad/good way? Or this is only preparation for some future feature?
And what happen when we run ddl which change some table structure which is in compiled statement?

@asfernandes
Copy link
Member Author

This only put more information in MON$ on request.

@asfernandes
Copy link
Member Author

Anyone see problem in merge this in master?

src/jrd/exe.cpp Outdated

// Generate request id.
request->setRequestId(
request->isRequestIdUnassigned() && statement->requests.hasData() && request == statement->requests[0] ?
Copy link
Member

Choose a reason for hiding this comment

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

This part (statement->requests.hasData() && request == statement->requests[0]) is quite longish and repeated twice across the code. Maybe encapsulate it into something like bool Statement::isRootRequest(jrd_req request) const or probably bool jrd_req::isRoot() const? "Root" could be replaced with "Initial" or whatever.

Copy link
Member

@dyemanov dyemanov left a comment

Choose a reason for hiding this comment

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

I don't have any objections after review.

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.

4 participants