Skip to content

Stage 3 almost never selects query-time results kept across evaluations (Example 4 B3 costs 8,884.5/s vs 2.1/s) #754

Open

Description

@zzylol

Problem, by example

The planner-layering Example 4 Pattern B workload has 1M series at 66,667 rows/s. Plan it with the default cost model (cost model 1, usage over time, ResourceUnitCost::illustrative()) and DeploymentCapabilities { query_time_results_retained: true, .. }.

Stage 3 prices the candidates as follows (per second of wall time):

Candidate Materialization Cost/s
B3 (P3-m2 shape): tumbling KLL panes computed at query time and kept across evaluations MatAtQueryKeptAcrossEvaluations 8,884.5
P2: one whole-window KLL rebuilt at query time on every evaluation MatAtQuery 2.1

So B3 never wins. A sweep from 1 to 1M series at consistent rates found that B3 is selected only at a 1 ms sample interval with 10 to 100 series. It is never selected at 15 s or 1 s intervals. The ASAPQuery-backend draft PR for kept query-time results (ASAPQuery-backend #824) had to use 10 series sampled every 1 ms to get a plan that keeps results at all.

Expected: keeping already-computed panes should be cheaper than rebuilding the whole window from raw samples whenever evaluations repeat faster than panes expire. That is the reason this materialization exists.

Likely cause (to confirm)

  • Cost model 1 charges the kept state as memory for every second it is held: about four kept panes, each holding 1M KLL sketches.
  • Stage 3 sizes sketch memory by full capacity, not by the samples a pane actually holds ([Bug] Stage 3 sizes a sketch's memory by its full capacity, not by the samples it holds #726). That inflates the kept-pane memory for panes that hold few samples per series.
  • Rebuilding P2 is charged only CPU per evaluation plus transient memory. If the raw-scan CPU and the raw-data read per evaluation are underpriced, the comparison tilts further.

Proposal

  1. Add a Stage 3 test that prints B3's and P2's ResourceUsage breakdown (CPU, memory byte-seconds, scanned bytes) for Pattern B, and check each term against the sizes the executor actually allocates.
  2. Fix whichever term is wrong. [Bug] Stage 3 sizes a sketch's memory by its full capacity, not by the samples it holds #726 (size by samples held) is the first candidate.
  3. Pin, with numbers, a realistic configuration under which B3 is selected.

Related

#726 (sketch memory sized by full capacity), #723 (resource usage and cost models), #730 (query-time results kept across evaluations), ASAPQuery-backend #824.

Activity

  1. added
    bugSomething isn't working
    cost-modelCost formulas, statistics, ranking, and selection
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcost-modelCost formulas, statistics, ranking, and selectionresource

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions