Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

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
@JSReds JSReds force-pushed the temp-orderby-fix branch from 6841a01 to 9d1faf3 Compare March 5, 2024 15:44
@flowzone-app flowzone-app bot enabled auto-merge March 5, 2024 15:47
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants