Reputation: 4718
I have the following code:
foldersRef.where("ParentID", "==", "1").where("Deleted", "==", false)
ParentID
and Deleted
) be preferable to a single-field index for this query?ParentID
and Deleted
, will Firestore know to use the composite index?.where()
clauses / function calls matter?Upvotes: 3
Views: 1381
Reputation: 138979
- Will a composite index (that indexes ParentID and Deleted) be preferable to a single-field index for this query?
If you are using the following line of code:
foldersRef.where("ParentID", "==", "1").where("Deleted", "==", false)
Without any ordering (ASCENDING or DESCENDING), there is no need to create a composite index. Firestore will create the needed index automatically.
- If I also have individual single-field indexes for ParentID and Deleted, will Firestore know to use the composite index?
No. Single-field indexes are also created automatically by Fiestore. So there is no need to creat any index for a single filed. Beside that, if you have separate field indexes with orderding, it doesn't mean that you also have a composite index for those fields. You need to create yourself.
- When I create the composite index, does the order of fields matter?
Yes, if you change the order of your where()
calls, you also need to create the corresponding index accordingly.
- Does the order of my .where() clauses / function calls matter?
In terms of speed, as long as you create the correct index, no.
Upvotes: 1
Reputation: 6854
foldersRef.where("ParentID", "==", "1").where("Deleted", "==", false)
and foldersRef.where("Deleted", "==", false).where("ParentID", "==", "1")
would require two different composite indexes.Upvotes: 1