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

impr(quaint/qe): PostgreSQL DISTINCT ON #4223

Merged
merged 20 commits into from
Dec 4, 2023
Merged

impr(quaint/qe): PostgreSQL DISTINCT ON #4223

merged 20 commits into from
Dec 4, 2023

Conversation

Druue
Copy link
Contributor

@Druue Druue commented Sep 12, 2023

This PR is looking to introduce the structure for further in-db distinct work and the base case for PostgreSQL's distinct on

  • Added quaint rendering for DISTINCT ON
  • Hooked up QE to to use the DISTINCT ON api from quaint
  • in-memory-record-processor now allows for performing distinct separately in db
    // Add support for more granularly opting in to db-level distinct per query args
    // in-memory-builder was removed

Follow-up steps involve

  • basic orderBy support
  • extended orderBy support
  • CockroachDB
  • MySQL
  • SQLite

contributes prisma/prisma#14765
closes https://github.com/prisma/team-orm/issues/774

relevant discovery work

@Druue Druue requested a review from a team as a code owner September 12, 2023 10:46
@Druue Druue added this to the 5.4.0 milestone Sep 12, 2023
@Druue Druue changed the title impr(quaint/qe): DISTINCT ON WIP -- impr(quaint/qe): DISTINCT ON Sep 12, 2023
@Druue Druue marked this pull request as draft September 12, 2023 10:49
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 12, 2023

CodSpeed Performance Report

Merging #4223 will not alter performance

Comparing impr/distinct-on (a948112) with main (5c4707e)

Summary

✅ 11 untouched benchmarks

@Druue Druue marked this pull request as ready for review September 19, 2023 08:10
@nkovacic
Copy link

nkovacic commented Nov 8, 2023

@Druue any progress on this PR? Would be very beneficial for performance on distinct queries.

@Druue
Copy link
Contributor Author

Druue commented Nov 9, 2023

@Druue any progress on this PR? Would be very beneficial for performance on distinct queries.

Hey @nkovacic, yeah! I'm picking this PR back up today; ran into some issues that brought up the need to do some more discovery work

@Druue Druue changed the title WIP -- impr(quaint/qe): DISTINCT ON WIP -- impr(quaint/qe): PostgreSQL DISTINCT ON Nov 9, 2023
@janpio janpio marked this pull request as draft November 9, 2023 14:30
queries::distinct::distinct::with_duplicates
Add capability for db distinct in:
- read_many
- m2m
- one2m
- inmemory distinct will actually be used
Added
- capability for distinct inmem when orderby
@Druue Druue marked this pull request as ready for review November 29, 2023 00:42
@Druue Druue requested a review from a team as a code owner November 29, 2023 00:42
@Druue Druue requested review from miguelff and removed request for a team November 29, 2023 00:42
@Druue Druue requested a review from jkomyno November 29, 2023 00:42
Copy link
Member

@Weakky Weakky left a comment

Choose a reason for hiding this comment

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

Good first step. Some things could be improved. Also, it looks like a lot of tests are failing atm.

@Druue Druue marked this pull request as draft November 30, 2023 12:48
@Druue Druue changed the title WIP -- impr(quaint/qe): PostgreSQL DISTINCT ON impr(quaint/qe): PostgreSQL DISTINCT ON Nov 30, 2023
- track current in-mem snapshots
- track in-db pg snapshots
@Druue Druue marked this pull request as ready for review November 30, 2023 17:06
Copy link
Member

@Weakky Weakky left a comment

Choose a reason for hiding this comment

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

Let's revisit the tests in the next bits of work, LGTM for now, nice job 👍

@apolanc apolanc modified the milestones: 5.4.0, 5.7.0 Nov 30, 2023
Copy link
Member

@Weakky Weakky left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@Druue Druue merged commit a0c366a into main Dec 4, 2023
67 checks passed
@Druue Druue deleted the impr/distinct-on branch December 4, 2023 12:12
Comment on lines +37 to 71
#[connector_test(only(Postgres))]
async fn no_panic_pg(runner: Runner) -> TestResult<()> {
test_user(&runner, r#"{ id: 1, first_name: "Joe", last_name: "Doe", email: "1" }"#).await?;
test_user(&runner, r#"{ id: 2, first_name: "Doe", last_name: "Joe", email: "2" }"#).await?;

assert_query!(
runner,
"query { findManyUser(distinct: [first_name, last_name]) { id } }",
r#"{"data":{"findManyUser":[{"id":1},{"id":2}]}}"#
insta::assert_snapshot!(
run_query!(
&runner,
indoc!("{
findManyUser(distinct: [first_name, last_name])
{ id }
}")
),
@r###"{"data":{"findManyUser":[{"id":2},{"id":1}]}}"###
);

Ok(())
}

/// Regression test for not selecting the fields the distinct is performed on: https://github.com/prisma/prisma/issues/5969
#[connector_test(exclude(Postgres))]
async fn no_panic_other(runner: Runner) -> TestResult<()> {
test_user(&runner, r#"{ id: 1, first_name: "Joe", last_name: "Doe", email: "1" }"#).await?;
test_user(&runner, r#"{ id: 2, first_name: "Doe", last_name: "Joe", email: "2" }"#).await?;

insta::assert_snapshot!(
run_query!(
&runner,
indoc!("{
findManyUser(distinct: [first_name, last_name])
{ id }
}")
),
@r###"{"data":{"findManyUser":[{"id":1},{"id":2}]}}"###
);
Copy link
Member

Choose a reason for hiding this comment

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

Can we not differentiate the snapshots by "connector" here and avoid the duplication?

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

5 participants