Skip to content

Switch paginated queries to use psql tuple comparison to improve planner performance#8066

Closed
jdolle wants to merge 2 commits into
mainfrom
tuple-pagination
Closed

Switch paginated queries to use psql tuple comparison to improve planner performance#8066
jdolle wants to merge 2 commits into
mainfrom
tuple-pagination

Conversation

@jdolle

@jdolle jdolle commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Background

Performance improvements

Description

This query is the same as the OR but is easier on the planner

@jdolle jdolle requested a review from n1ru4l May 23, 2026 00:00
@github-actions

github-actions Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
hive 11.1.2-alpha-20260523002243-3f6eb18e95abcb339b57da27bb584720717af46b npm ↗︎ unpkg ↗︎

@github-actions

github-actions Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

🐋 This PR was built and pushed to the following Docker images:

Targets: build

Platforms: linux/amd64

Image Tag: 3f6eb18e95abcb339b57da27bb584720717af46b

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The refactor to PostgreSQL tuple comparisons for pagination contains several critical bugs. The table alias 'c' is used in multiple queries where it is not defined in the 'FROM' clause, leading to runtime failures. Furthermore, the 'organization_members' query incorrectly references 'id' instead of 'user_id' for the cursor comparison.

Comment thread packages/services/api/src/modules/organization/providers/organization-members.ts Outdated
Comment thread packages/services/api/src/modules/schema/providers/contracts.ts Outdated
? psql`
AND (
(
c."created_at" = ${cursor.createdAt}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was a bug before. I guess we werent ever using this?

@n1ru4l n1ru4l May 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the bug that was here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's referencing c. but nothing is being aliased to c.

@n1ru4l n1ru4l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AFAIK these two approaches are functional equivalent. I personally use the AND OR over the tuple approach as it is more explicit to me. But I can be convinced to use these instead if it provides some benefit.

I will still reject this unless I am convinced to either

  1. why this improves performance
  2. why this is more readable and understandable (without having to open the documentation)

@jdolle

jdolle commented May 27, 2026

Copy link
Copy Markdown
Collaborator Author

I'm fine closing this if we're not comfortable with the syntax. Personally I find it much easier to read since it's very compact. But if we prefer the verbose form, it's functionally equivalent.

@jdolle jdolle closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants