INTPYTHON-855 Create unique indexes in a way that can be used by the query planner#543
INTPYTHON-855 Create unique indexes in a way that can be used by the query planner#543sophiayangDB wants to merge 11 commits into
Conversation
| case _: | ||
| return {"$exists": True} |
There was a problem hiding this comment.
$exists matches if the field is null, which we don't want (that explains at least some of the test failures).
Consider this advice: "Null vs. Missing: $exists: true will return documents where a field is explicitly set to null. If you want documents where a field exists and is not null, combine it with $ne: null"
| if db_type is None: | ||
| return {"$exists": True} |
There was a problem hiding this comment.
Is this branch used? Offhand, I can't think of why db_type would be None. That would denote a virtual field that don't exist in the database, and such fields wouldn't be indexed... (perhaps this is AI nonsense.)
| if not field.null: | ||
| return |
There was a problem hiding this comment.
Conceptually, it makes sense to me that the partialFilterExpression isn't needed if the field can't contain null values. My concern is that we would also have to make AlterField modify any/drop any relevant indexes when a field changes from null to not-null (or vice versa).
INTPYTHON-855
Changes in this PR
Before this change, exact lookups were generated as plain equality predicates in lookups.py. Since those queries did not include the type conditions required by partial unique indexes, MongoDB often chose a collection scan instead of using the index. This patch adds the corresponding type filters to exact lookups so the planner can select the intended partial unique index.
Test Plan
Added unit tests in
tests/lookup_Checklist
Checklist for Author
Checklist for Reviewer