Skip to content

Slow Query Performance in Postgres Provider Due to Full count on Large Tables #1969

@webb-ben

Description

@webb-ben

Description
The Postgres provider currently performs a full .count() on every request to populate numberMatched, which significantly slows down queries on large tables. This makes API responses much slower than necessary, especially when querying large datasets for a small subset of the features.

Steps to Reproduce

  1. Set up pygeoapi with a large Postgres table as a data source.
  2. Make a request to an endpoint that queries the table.
  3. Observe that the response time is impacted by the .count() operation.

Expected behavior
Queries should return results faster by avoiding expensive .count() operations on large tables.

Potential workarounds are:

Screenshots/Tracebacks
If applicable, add screenshots to help explain your problem.

Environment

  • OS: Mac
  • Python version: 3.10
  • pygeoapi version: 0.20.dev0

Additional context
Similar constraints exist in other providers, with some only doing a count of features when resulttype=hits

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions