Skip to content

[WIP] Sampling-based timing for EXPLAIN ANALYZE #5

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lfittl
Copy link
Owner

@lfittl lfittl commented Jan 17, 2023

No description provided.

@lfittl lfittl force-pushed the explain-sampling branch 2 times, most recently from 8a6d23a to 577afd2 Compare January 17, 2023 02:47
This introduces a new mode, TIMING SAMPLING, as a lower overhead alternative to
TIMING ON for EXPLAIN ANALYZE and auto_explain.

Instead of measuring the current time when entering and exiting each plan node
(which can get expensive even on modern systems, e.g. when doing many loops),
the sampling timing mode measures the time at a fixed recurring interval using
a wall clock timer.

The sampling frequency can be adjusted from 1 to 1000 Hz by passing the SAMPLEFREQ
option to EXPLAIN, and defaults to 1000 Hz (1ms). Higher frequencies are
technically possible but currently not supported by the Postgres timeout API.

The sampled wall clock time is cached and used by the the plan node instrumentation
to attribute how much sampled time passed whilst a plan node was executed.

Since sampling is likely to undercount the actual time taken, the sampled time
values are scaled to the total execution time of the query (or parallel query
worker), before being displayed.

Additionally, this adds support for sampling based timing to auto_explain by
introducing the new "auto_explain.log_timing = sampling" setting, and
"auto_explain.log_timing_samplefreq" setting to set the frequency.
Since the query descriptor isn't directly accessible from
ExecInitParallelPlan we have to pass this via the executor state - this
may need adjustment.
@lfittl lfittl force-pushed the explain-sampling branch 2 times, most recently from d51bbb7 to 6030290 Compare January 17, 2023 07:20
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.

1 participant