Skip to content

Use correlated EXISTS for PostgreSQL session activity data - #4528

Merged
mikecao merged 1 commit into
umami-software:devfrom
dongwonmoon:codex/session-activity-exists
Sep 11, 2026
Merged

mikecao merged 1 commit into
umami-software:devfrom
dongwonmoon:codex/session-activity-exists

Conversation

@dongwonmoon

@dongwonmoon dongwonmoon commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implement the correlated EXISTS proposed in #4526 for PostgreSQL session activity queries.

The existing hasData expression checks event IDs against site/date-wide event_data. Depending on the data and query plan, opening a session profile can repeatedly scan a large materialized result. The correlated check lets PostgreSQL look up properties for each event using the existing website_event_id index.

Website/date predicates, returned fields, ordering, and the 500-row limit are unchanged. No new index or configuration is required. The ClickHouse implementation is unchanged.

Verification

  • Compared all returned fields for 500 rows on synthetic PostgreSQL 15.19 data; the results matched.
  • Ran a small source-derived SQL check covering date boundaries, NULL dates, other-site data, multiple sessions, missing qualifying properties, multiple properties, and performance-event exclusion.
  • Build passed with SKIP_DB_CHECK=1 (database checks/migrations skipped).
  • Three related unit tests passed; the changed file passes lint.
  • Full lint fails on existing diagnostics: the unmodified and patched versions of the same dev revision produce identical diagnostics (6 errors, 13 warnings, 11 infos).

These are SQL-level checks using temporary tables, not a production or API performance benchmark. The diagnosis and proposed approach come from #4526; this change implements that approach with independent verification.

Source-derived SQL check · Measurement summary and limitations

Related: #4526


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 10, 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 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR optimizes PostgreSQL session activity queries by replacing a website/date-wide IN subquery with a correlated EXISTS lookup.

  • Preserves the existing website and date constraints used to calculate hasData.
  • Correlates each event directly through event_data.website_event_id.
  • Leaves returned fields, ordering, row limits, and the ClickHouse implementation unchanged.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness, security, or repository-rule issues identified.

The changed predicate preserves the prior filtering semantics while correlating through a non-null indexed foreign key, and no concrete regression remains.

Important Files Changed

Filename Overview
src/queries/sql/sessions/getSessionActivity.ts Rewrites the PostgreSQL hasData predicate as a semantically equivalent correlated lookup that can use the existing event ID index.

Reviews (1): Last reviewed commit: "Use correlated EXISTS for PostgreSQL ses..." | Re-trigger Greptile

@mikecao
mikecao merged commit 2a5ef9d into umami-software:dev Sep 11, 2026
2 of 6 checks passed
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.

2 participants