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

Make OData sorting predictable and unique #75

Merged
merged 1 commit into from
Mar 6, 2024
Merged

Conversation

JSReds
Copy link
Contributor

@JSReds JSReds commented Mar 5, 2024

Change-type: patch
See: https://balena.zulipchat.com/#narrow/stream/345890-balena-io/topic/Server.20side.20pagination.20-.20Enpal.20feedback/near/423035741

Explanation:
The presence of numerous NULL values in certain columns creates a non-unique sorting scenario, subject to PostgreSQL's (PG) optimization strategies, which may rely on disk storage order.
This issue extends beyond specific columns and applies to any column containing NULL values. For instance, when sorting by a column with NULLs, the sorting behavior may become unpredictable.
To maintain compliance with PostgreSQL documentation, which mandates predictable and unique sorting, we propose a potential workaround. This involves incorporating an '$orderby id' clause alongside the primary sorting column. The '$orderby id' clause ensures ascending or descending order, aligned with the user's chosen sorting direction for other columns.
It's worth noting that if the code can recognize a unique column, we may revisit this solution. Upon sorting the table by such a unique column, the workaround to enforce predictable sorting behavior could be removed.

Screenshot 2024-03-05 at 16 46 43

@JSReds JSReds requested a review from thgreasi March 5, 2024 15:43
@JSReds JSReds self-assigned this Mar 5, 2024
return {
[fieldPath]: direction,
};
return [`${fieldPath} ${direction}`, `id ${direction}`];
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw this (and probably the above as well) could also be:

Suggested change
return [`${fieldPath} ${direction}`, `id ${direction}`];
return [{ [fieldPath]: direction }, { id: direction }];

@flowzone-app flowzone-app bot merged commit 3e515f8 into main Mar 6, 2024
45 checks passed
@flowzone-app flowzone-app bot deleted the temp-orderby-fix branch March 6, 2024 10:18
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

2 participants