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: Handle compound filters on related indexed fields #2575

Merged

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented May 1, 2024

Relevant issue(s)

Resolves #2572

Description

Handles compound filters targeting related indexed fields, and one-many joins from the many side.

The invertableJoin issue may be affecting non indexed joins.

First commit documents the existing behaviour, second commit fixes it.

There is another issue in this space not solved by this PR: #2574

The current behaviour is documented in this commit
Contains two changes:
- complex (relation) filters in indexes are not passed on to the index fetcher - it cannot handle them at the moment
- Adds support for one-many joins from the secondary side in the invertableJoin type, otherwise it fails to yield multiple results
@AndrewSisley AndrewSisley added bug Something isn't working area/query Related to the query component labels May 1, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.11 milestone May 1, 2024
@AndrewSisley AndrewSisley requested a review from a team May 1, 2024 22:14
@AndrewSisley AndrewSisley self-assigned this May 1, 2024
@@ -33,7 +33,7 @@ func isComplex(conditions any, seekRelation bool) bool {
if op, ok := k.(*mapper.Operator); ok {
switch op.Operation {
case request.FilterOpOr, request.FilterOpAnd, request.FilterOpNot:
if v, ok := v.([]any); ok && len(v) == 1 {
if v, ok := v.([]any); ok && len(v) == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not ideal to keep this as-is long-term, as it will prevent a possible performance-shortcut once John's fetcher rework gets merged, but for now it is a simple way of excluding the index fetcher filter's lack of support for compound filters..

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are going to do this might as well remove the if block all together. It's never going to be of length 0.

Copy link
Contributor Author

@AndrewSisley AndrewSisley May 2, 2024

Choose a reason for hiding this comment

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

Will do. I think it is valid to submit an empty and/or clause, but probably not really worth the extra code for that :)

  • Remove len 0 check

@AndrewSisley AndrewSisley changed the title fix: Handle compound filters targeting related indexed fields fix: Handle compound filters on related indexed fields May 1, 2024
@@ -487,6 +486,9 @@ type invertibleTypeJoin struct {
secondaryFieldIndex immutable.Option[int]
secondaryFetchLimit uint

// docsToYield contains cocuments read and ready to be yielded by this node.
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: documents

Copy link
Contributor Author

@AndrewSisley AndrewSisley May 2, 2024

Choose a reason for hiding this comment

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

:) will fix

  • typo

Copy link
Member

@nasdf nasdf left a comment

Choose a reason for hiding this comment

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

LGTM. The additional test coverage is really nice.

@@ -556,6 +558,17 @@ func (join *invertibleTypeJoin) processSecondResult(secondDocs []core.Doc) (any,
}

func (join *invertibleTypeJoin) Next() (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

thought: This function is really difficult to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and IMO the variable names don't really pair up well either, and they actually represent different things in different situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AndrewSisley AndrewSisley merged commit 51ea214 into sourcenetwork:develop May 2, 2024
27 of 28 checks passed
@AndrewSisley AndrewSisley deleted the 2572-cmp-filter-index branch May 2, 2024 12:21
Request: `query {
Program(
filter: {
_and: [
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: this is not _or

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol - nice catch, thanks 😁

I'll fix this shortly (new issue/PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Request: `query {
Program(
filter: {
_and: [
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: this is not _not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compound filter targeting related indexed field errors
4 participants