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(datastore): optimize sync queries with predicates by wrapping in an AND group #1225

Merged
merged 2 commits into from
Mar 30, 2021

Conversation

richardmcclellan
Copy link
Contributor

When a filter is provided on a sync operation, AppSync will attempt to optimize the request by performing a DynamoDB query, rather than a scan. A query is only possible if the filter contains the hash key, or the hash key and the sort key. To perform this optimization, the AppSync resolver requires the presence of a top level "and" group.

This PR wraps the sync expression filter with an AND group if the predicate provided by the customer is just a predicate operation, rather than a group.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@richardmcclellan richardmcclellan requested a review from a team March 12, 2021 16:56
@richardmcclellan richardmcclellan changed the title Rm/sync and @richardmcclellan fix(datastore): optimize sync queries with predicates by wrapping in an AND group Mar 12, 2021
@richardmcclellan richardmcclellan changed the title @richardmcclellan fix(datastore): optimize sync queries with predicates by wrapping in an AND group fix(datastore): optimize sync queries with predicates by wrapping in an AND group Mar 12, 2021
// provided syncPredicate is already a QueryPredicateGroup, this is not needed. If the provided
// group is of type AND, the optimization will occur. If the top level group is OR or NOT, the
// optimization is not possible anyway.
syncPredicate = new QueryPredicateGroup(QueryPredicateGroup.Type.AND, Arrays.asList(syncPredicate));
Copy link
Contributor

Choose a reason for hiding this comment

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

This might look better wrapped into a factory method:

QueryPredicateGroup.andOf(syncPredicate)

It would prevent the access escalation of the constructor, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had considered something like that, but couldn't come up with a good name for the method itself. I think andOf works though - I'll do that!

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