Skip to content

Use explicit ordering in RawSqlTest#1139

Merged
MaxGabriel merged 2 commits intomasterfrom
rawSqlExplicitOrderBy
Oct 25, 2020
Merged

Use explicit ordering in RawSqlTest#1139
MaxGabriel merged 2 commits intomasterfrom
rawSqlExplicitOrderBy

Conversation

@MaxGabriel
Copy link
Member

I was non-deterministically getting an error on this test, where the pets were misordered. I'm having trouble reproducing, but I believe the issue is that Postgres' order is non-deterministic if not specified (in my experience, it can be Postgres version dependent). I believe the test as-is is incorrect without specifying the pet order, for Postgres.

Postgres docs warn:

After a query has produced an output table (after the select list has been processed) it can optionally be sorted. If sorting is not chosen, the rows will be returned in an unspecified order. The actual order in that case will depend on the scan and join plan types and the order on disk, but it must not be relied on. A particular output ordering can only be guaranteed if the sort step is explicitly chosen.

This commit orders the pets explicitly. This ensures when we get both of Mathias' pets, we get "Rodolfo" first and "Zeno" second, as the assertions require.

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Bumped the version number if there isn't an (unreleased) on the Changelog
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

I was non-deterministically getting an error on this test, where the pets were misordered. I'm having trouble reproducing, but I believe the issue is that Postgres' order is non-deterministic if not specified (in my experience, it can be Postgres version dependent). I believe the test as-is is incorrect without specifying the pet order, for Postgres.

[Postgres docs warn:](https://www.postgresql.org/docs/12/queries-order.html)

> After a query has produced an output table (after the select list has been processed) it can optionally be sorted. If sorting is not chosen, the rows will be returned in an unspecified order. The actual order in that case will depend on the scan and join plan types and the order on disk, but it must not be relied on. A particular output ordering can only be guaranteed if the sort step is explicitly chosen.

This commit orders the pets explicitly. This ensures when we get both of Mathias' pets, we get "Rodolfo" first and "Zeno" second, as the assertions require.
Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

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

awesome thanks!

@MaxGabriel MaxGabriel merged commit 349bffa into master Oct 25, 2020
@MaxGabriel
Copy link
Member Author

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