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

Incorrect warning about missing index #6840

Open
ottob opened this issue Mar 7, 2024 · 3 comments
Open

Incorrect warning about missing index #6840

ottob opened this issue Mar 7, 2024 · 3 comments

Comments

@ottob
Copy link

ottob commented Mar 7, 2024

[REQUIRED] Environment info

firebase-tools:
13.4.0

Platform:
macOS

[REQUIRED] Test case

Haven't been able to create one.
We have over 100 indexes. They all work fine except this one where we get the warning.
We have a similar index that is almost the same except that the final field is reversed. Could this cause an issue?

...
 {
          "fieldPath": "updated",
          "order": "ASCENDING"
        }

[REQUIRED] Steps to reproduce

firebase deploy --only firestore:indexes

Index defined in indexes.json

{
      "collectionGroup": "cases",
      "queryScope": "COLLECTION",
      "fields": [
        {
          "fieldPath": "userRoles",
          "arrayConfig": "CONTAINS"
        },
        {
          "fieldPath": "userOrganizationId",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "caregiverId",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "snoozed",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "status",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "visibility",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "unsigned",
          "order": "DESCENDING"
        },
        {
          "fieldPath": "updated",
          "order": "DESCENDING"
        }
      ]
    },

[REQUIRED] Expected behavior

Deploy without warning

[REQUIRED] Actual behavior

i firestore: The following indexes are defined in your project but are not present in your firestore indexes file:
(cases) --
(userRoles,CONTAINS)
(caregiverId,ASCENDING)
(snoozed,ASCENDING)
(status,ASCENDING)
(userOrganizationId,ASCENDING)
(visibility,ASCENDING)
(unsigned,DESCENDING)
(updated,DESCENDING)

@exaby73
Copy link

exaby73 commented Mar 8, 2024

Hello @ottob. Do you have indexes defined from the Firebase console that haven't been added to the index file here?

@exaby73 exaby73 added the Needs: Author Feedback Issues awaiting author feedback label Mar 8, 2024
@ottob
Copy link
Author

ottob commented Mar 8, 2024

Do you have indexes defined from the Firebase console that haven't been added to the index file here?

No, then I think we would get a warning about it.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Mar 8, 2024
@NickChittle
Copy link
Contributor

It's possible this is related to how the Document ID is included in the index. Can you check the indexes that are created in the console and pay attention to the direction of the __name__ field (ASCENDING or DESCENDING) .

The Firebase CLI has an issue where it currently compares indexes with the __name__ stripped off: https://github.com/firebase/firebase-tools/blob/master/src/firestore/api.ts#L187

However the Firestore SDKs perform order by normalization where if the __name__ is left off of a query it is automatically given the direction of the last order by in the query (Which may be automatically added from an inequality) https://github.com/googleapis/nodejs-firestore/blob/5da7138abc15e99edc51fdfd25a70bf5eb0c97b9/dev/src/reference.ts#L1985

Basically your index might be getting created from the CLI as ... updated DESC, __name__ ASC, but the query from the SDK is attempting to be used as ... updated DESC, __name__ DESC

If this is indeed the issue, then you may be able to work around it by explicitly stating the order by.

i.e.

...
    .order_by("updated", "DESCENDING")
    .order_by("__name__", "ASCENDING")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants