How to interpret SYS_QUERY_HISTORY results

0

I am trying to troubleshoot query performance issues and am seeing the following results out of SYS_QUERY_HISTORY.

query_idelapsed_timeexecution_timecompile_timeplanning_timecompute_type
12345623117760194625850622176937primary
12346615800459981495584236132701primary
123475068902504690150261075952primary
1234854783645007025236776902primary
12349368474291247230358302primary

Are the elapsed time values inclusive of execution_time / compile_time? And in the case of compile_time being so high what steps can actually be taken?

The documentation for SYS_QUERY_HISTORY mostly enumerates the columns of the table, but doesn't give any guidance on how to interpret the values.

willayd
asked 6 months ago405 views
1 Answer
0

Hi willayd,

The elapsed time is the difference between the end_time and the start_time of the request. It includes the execution, queuing, compilation and planning times.

  • Execution: the steps in the query plan are active and being executed. If this phase takes a lot of time, then this means that the queries should be reviewed for optimization, optimization can be at the physical data model level (such as distribution and sort keys) or at the query level (rewriting the query by analyzing the query plan first and then improving its performance). Here are the best practices for designing tables.
  • Queuing: the query is on-hold or in other words on the waiting list, waiting for an available slot so it can get executed. This is so often used as an indicator for high number of concurrent queries. This column can be reduced by reviewing the defined workload management and/or enabling the concurrency scaling feature.
  • Compilation: the time spent on compiling the execution plan. Usually the first execution includes the overhead of compiling the code and as a result the future runs of the same query will be faster, often even with different parameters (Query planning and execution workflow and compiled code).
  • Planning: the time spent on query planning such as query plan rewrite for a faster execution and better performance.

Regards,

Ziad

AWS
EXPERT
Ziad
answered 6 months ago
  • Thanks Ziad for the references. But these numbers have to be cumulative right? So is it:

    • Elapsed = Execution + Queueing + Compilation + Planning?
    • Execution = Queuing + Compilation + Planning
    • Queueing = Compilation + Planning

    etc...? Also I think what is ultimately missing from those guides is to how to improve these. In the sample I provided, query 12437 for example seems dominated by Compilation time - but how can that be improved? I don't see anything in those links on how to effect that

  • Hi willayd,

    Elapsed time should be equal or slightly higher than Execution + Queueing + Compilation + Planning. If this is not the case, I recommend opening a support ticket for further analysis. However, Execution is not the sum of Queuing+Compilation+Planning and Queuing is not the sum of Compilation + Planning. Execution, Queuing, Compilation and Planning values are not related to each other, each one of these 4 columns reflects the total time of its appropriate phase. Compilation time should considerably decrease after the first execution. In the above table, the data seems to be misleading, I would recommend you to open a ticket for the support.

    Regards,

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions