u/victorl96

Firestore Enterprise Array Index Not Working

Hey everyone,

I wanted to check in to see if anyone has got single-field array index's working in Firestore Enterprise edition. Whatever I do I can't seem to run a query without doing a full table scan.

I created the index like this in Terraform:

resource "google_firestore_index" "organization_user_ids" {
  collection = "organization"
  density = "SPARSE_ANY"


  fields {
    field_path = "userIds"
    array_config = "CONTAINS"
  }


  fields {
    field_path = "__name__"
    order = "ASCENDING"
  }
}

Then executed the following query which seems to always do a table scan (the index is green/ready):

db.pipeline().collection('organization').where(field('userIds').arrayContains('test'))

Execution:
 results returned: 0
 query id: xxxxxxx
 data bytes read: 60 MiB
 entity row scanned: 120,000

Billing:
 read units: 30,000

Tree:
• Compute
|  $out_1: map_set($record_1, "__name__", $__name___1, "__key__", unset)
|  is query result: true
|
|  Execution:
|   records returned: 0
|   latency: 336.47 ms (local <1 ms)
|
└── • Compute
    |  $__name___1: $__key___2
    |
    |  Execution:
    |   records returned: 0
    |   latency: 336.44 ms (local <1 ms)
    |
    └── • TableScan
           source: /organization
           order: UNDEFINED
           output record: $record_1
           filter: array_contains($userIds_1, "test")
           output bindings: {$__key___2=__key__, $userIds_1=userIds}
           output: [$record_1, $__key___2]

           Execution:
            records returned: 0
            latency: 336.43 ms
            post-filtered rows: 120,000
            records scanned: 120,000
            data bytes read: 60 MiB

Thanks!

reddit.com
u/victorl96 — 2 days ago