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

Fix issue where filtered queries fail on updated fields #409

Merged
merged 3 commits into from
Jun 20, 2023

Conversation

adzialocha
Copy link
Member

@adzialocha adzialocha commented Jun 19, 2023

Closes #379

📋 Checklist

  • Add tests that cover your changes
  • Add this PR to the Unreleased section in CHANGELOG.md
  • Link this PR to any issues it closes
  • New files contain a SPDX license header

@adzialocha
Copy link
Member Author

adzialocha commented Jun 19, 2023

The problem is in this sub-select SQL query:

AND EXISTS (
    SELECT
        operation_fields_v1.value
    FROM
        operation_fields_v1
    WHERE
        operation_fields_v1.name = 'username'
        AND
            operation_fields_v1.value = $1
        AND
            operation_fields_v1.operation_id = document_view_fields.operation_id
)

It filters all fields out which do not fulfill this requirement (username = $1), even when they belong to the same document ..

I've made a test against the same query with filter but without UPDATE operations in the document and it works.

@adzialocha adzialocha changed the title Fix issue where filtered queries failed on updated fields Fix issue where filtered queries fail on updated fields Jun 19, 2023
@sandreae
Copy link
Member

The problem is in this sub-select SQL query:

AND EXISTS (
    SELECT
        operation_fields_v1.value
    FROM
        operation_fields_v1
    WHERE
        operation_fields_v1.name = 'username'
        AND
            operation_fields_v1.value = $1
        AND
            operation_fields_v1.operation_id = document_view_fields.operation_id
)

It filters all fields out which do not fulfill this requirement (username = $1), even when they belong to the same document ..

I've made a test against the same query with filter but without UPDATE operations in the document and it works.

So it is filtering out the other document fields, which we actually might want (depending on the selected fields)?

@adzialocha
Copy link
Member Author

adzialocha commented Jun 20, 2023

So it is filtering out the other document fields, which we actually might want (depending on the selected fields)?

Exactly! The problem was that we just filtered document fields, but actually we wanted to filter document views which contain that document field. I extended the sub query now with a JOIN to reflect this.

@adzialocha adzialocha marked this pull request as ready for review June 20, 2023 11:33
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Patch coverage: 90.00% and project coverage change: +0.05 🎉

Comparison is base (2c677c6) 92.58% compared to head (2eb2f93) 92.64%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #409      +/-   ##
==========================================
+ Coverage   92.58%   92.64%   +0.05%     
==========================================
  Files          70       70              
  Lines        6652     6660       +8     
==========================================
+ Hits         6159     6170      +11     
+ Misses        493      490       -3     
Impacted Files Coverage Δ
aquadoggo/src/db/stores/query.rs 96.70% <90.00%> (-0.08%) ⬇️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@adzialocha adzialocha requested a review from sandreae June 20, 2023 11:58
@sandreae sandreae merged commit 9acfea6 into main Jun 20, 2023
9 checks passed
@sandreae sandreae deleted the fix-updated-fields-query branch June 20, 2023 22:15
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.

Querying a filtered collection breaks on updated documents
2 participants