-
Notifications
You must be signed in to change notification settings - Fork 625
Serve OR queries from the index. #3368
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
Conversation
e023f88
to
81b6e16
Compare
Coverage Report 1Affected Products
Test Logs
Notes |
Size Report 1Affected Products
Test Logs
Notes |
/retest |
the idea is that a DNF transform on a composite filter will result in a condition that looks like
where each condition is an AND operation of 1 or more FieldFilters. We can then run sub-queries for condition1, condition2, etc, and find the |
* Iterates over all field indexes that are used to serve the given target, and returns the least | ||
* recent offset of them all. Asserts that the target can be served from index. | ||
*/ | ||
FieldIndex.IndexOffset getLeastRecentIndexOffset(Target target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minOffset? You could alternatively also drop the LeastRecent/Min name altogether and just call this getOffset(Target target)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be more clear to keep a wording that signals to the caller that this method will do a min
operation of a bunch of offsets, rather than just a getter method that retrieves one offset. I'll go with minOffset
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
FieldIndex.IndexOffset getLeastRecentIndexOffset(Target target); | ||
|
||
/** Returns the lowest offset for the provided index group. */ | ||
FieldIndex.IndexOffset getLeastRecentIndexOffset(Collection<FieldIndex> fieldIndexes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just pass the collection group? The index manager has all indices in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we should probably add a static import for IndexOffset or make IndexOffset a high level class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -74,6 +74,18 @@ | |||
/** Returns all configured field indexes. */ | |||
Collection<FieldIndex> getFieldIndexes(); | |||
|
|||
/** Returns whether we can serve the given target from the index. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the/an
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
firebase-firestore/src/main/java/com/google/firebase/firestore/local/QueryEngine.java
Outdated
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteIndexManager.java
Show resolved
Hide resolved
import androidx.annotation.Nullable; | ||
import com.google.common.collect.ObjectArrays; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a goal to kick our Guava dependency, as the Android build doesn't deal well with version conflicts for popular libraries. Hence, we should not directly use Guava and we eventually want to remove it altogether (it is used by GRPC).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
subQueries.get(0) | ||
: | ||
// Construct "subQuery1 UNION subQuery2 UNION ... LIMIT N" | ||
TextUtils.join(" UNION ", subQueries) + " LIMIT " + target.getLimit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure that we do not pass more than 999 bind elements. The best way to do this probably to validate that the query only contains 100 DNF terms (or what we decide the limit is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add parenthesis to indicate whether the LIMIT belongs to all statements or just the last one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add an assertion here, and when I post the DNF calculation code I'll throw an exception if the number of DNF terms exceeds a certain number.
Also updating this to SELECT * FROM (query1 UNION query2 UNION ...) LIMIT X
.
firebase-firestore/src/main/java/com/google/firebase/firestore/util/LogicUtils.java
Outdated
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/util/LogicUtils.java
Show resolved
Hide resolved
* Iterates over all field indexes that are used to serve the given target, and returns the least | ||
* recent offset of them all. Asserts that the target can be served from index. | ||
*/ | ||
IndexOffset minOffset(Target target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All Java methods should start with a verb: getMinOffset()
You should also align the two comments on their usage of "lowest" and "least recent" (which contrasts min).
return true; | ||
} | ||
|
||
private IndexOffset getLeastRecentIndexOffset(Collection<FieldIndex> fieldIndexes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name might still need an update.
/retest |
No description provided.