Skip to content
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

Proposal: Getting rid of Neighbors in Path Queries #6125

Merged
merged 5 commits into from Sep 29, 2021

Conversation

neilkakkar
Copy link
Collaborator

Changes

I very much dislike neighbors function because: https://clickhouse.com/docs/en/sql-reference/functions/other-functions/#neighbor

  1. It's implementation depends on a global ORDER BY clause in the subquery
  2. Even then, if the data is not in the same block, this returns wrong results.

I'm proposing leveraging arrays to get the same job done. It uses a bit more memory than before (one more copy of the array for each person) - but gets rid of global sorting.

Another improvement this query makes: Ensures the groupArray works correctly.

From the docs: Values can be added to the array in any (indeterminate) order. To fix this, you order by the correct things in a subquery.

We're already ordering by timestamp in PathEventQuery, so don't need to order by personID in the outer clause.

Checklist

  • All querysets/queries filter by Organization, by Team, and by User
  • Django backend tests
  • Jest frontend tests
  • Cypress end-to-end tests
  • Migrations are safe to run at scale (e.g. PostHog Cloud) – present proof if not obvious
  • New/changed UI is decent on smartphones (viewport width around 360px)

@timgl timgl temporarily deployed to posthog-pr-6125 September 27, 2021 14:50 Inactive
@timgl timgl temporarily deployed to posthog-pr-6125 September 27, 2021 15:01 Inactive
@neilkakkar neilkakkar marked this pull request as ready for review September 27, 2021 15:02
@timgl timgl temporarily deployed to posthog-pr-6125 September 28, 2021 15:20 Inactive
@timgl timgl temporarily deployed to posthog-pr-6125 September 28, 2021 15:37 Inactive
Copy link
Member

@EDsCODE EDsCODE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good call

@neilkakkar neilkakkar merged commit b8bc056 into master Sep 29, 2021
@neilkakkar neilkakkar deleted the paths_query_improvements branch September 29, 2021 09:44
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.

None yet

3 participants