Skip to content

Too slow query fetch #150

Closed
Closed
@umax

Description

@umax

Hi, team!

Imagine we have an entity Order with customer_id (str, uuid4), created_at (datetime) and other fields. I want to get all orders for specified customer and time range.

The query returns about 1500 records.
The problem: it takes about 7-8 seconds!

Environment details

  • OS type and version: Docker image python:3.8-slim
  • Python version: Python 3.8.6
  • pip version: 20.2.2
  • google-cloud-datastore version: 2.0.1

Datastore indexes:

  • kind: Order
    properties:

    • name: customer_id
    • name: created_at
      direction: asc
  • kind: Order
    properties:

    • name: customer_id
    • name: created_at
      direction: desc

Code example

query = db_client.query(
    kind='Order',
    filters=(
        ('customer_id', '=', customer_id),
        ('created_at', '>=', datetime_from),
        ('created_at', '<=', datetime_to),
    ),
)
result = list(query.fetch())

What I do wrong or can you suggest how to speed up this query?
Thanks!

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the googleapis/python-datastore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions