Skip to content

perf: add explicit start-date bound to funnel steps - #4536

Open
dongwonmoon wants to merge 2 commits into
umami-software:devfrom
dongwonmoon:perf/funnel-start-bound
Open

dongwonmoon wants to merge 2 commits into
umami-software:devfrom
dongwonmoon:perf/funnel-start-bound

Conversation

@dongwonmoon

@dongwonmoon dongwonmoon commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an explicit startDate lower bound to subsequent PostgreSQL funnel steps.

The bound is already implied by the preceding step's timestamp, so it does not change the intended matching criteria. Making it explicit allowed PostgreSQL to use the existing date index instead of scanning older events in the tested dataset.

Verification

On a fixed synthetic dataset of approximately 262k events spanning six months (PostgreSQL 15):

  • 7-day API p50: 52 → 23 ms.
  • 30-day API p50: 79 → 56 ms.
  • Full-period API p50: 199 → 203 ms; no improvement.

These repeated API measurements were taken on v3.3.1. A limited SQL recheck against current dev confirmed matching results and the short-range index-scan change for the same no-filter queries. Nine focused tests passed using cached dependencies. Full application build and full-suite tests were not rerun for this submission.

The benefit depends on the dataset and query range. No indexes or configuration changes are required; ClickHouse is unchanged.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@vercel

vercel Bot commented Sep 14, 2026

Copy link
Copy Markdown

@dongwonmoon is attempting to deploy a commit to the Umami Software Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an explicit report-start predicate to every PostgreSQL funnel step after the first, allowing PostgreSQL to apply its date index without changing the intended event ordering.

  • Adds we.created_at >= {{startDate}} alongside the existing end-date and step-window constraints.
  • Adds focused generated-SQL coverage for an eight-step funnel.
  • Leaves the ClickHouse query path unchanged.

Confidence Score: 4/5

The implementation appears safe to merge, with a non-blocking opportunity to make the new regression test accurately enforce per-step predicate placement.

The SQL change preserves the existing funnel time semantics, but the test can pass when predicates are duplicated in one level and omitted from another because it validates only the aggregate count.

Files Needing Attention: src/queries/sql/funnels/getFunnel.test.ts

Important Files Changed

Filename Overview
src/queries/sql/funnels/getFunnel.ts Adds a logically consistent explicit start-date predicate to each subsequent PostgreSQL funnel CTE.
src/queries/sql/funnels/getFunnel.test.ts Adds regression coverage for predicate emission, but the aggregate match count does not verify one predicate per level CTE.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Level 1 events<br/>startDate ≤ created_at ≤ endDate"] --> B["Level 2 events<br/>previous time ≤ created_at ≤ window end<br/>startDate ≤ created_at ≤ endDate"]
  B --> C["Subsequent levels<br/>repeat explicit report bounds"]
  C --> D["UNION per-level counts"]
Loading

Reviews (1): Last reviewed commit: "perf: add explicit start-date bound to f..." | Re-trigger Greptile

Comment thread src/queries/sql/funnels/getFunnel.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant