OpenEnergyPlatform / oeplatform

Repository for the code of the Open Energy Platform (OEP) website. The OEP provides an interface to the Open Energy Family
http://openenergyplatform.org/
GNU Affero General Public License v3.0
61 stars 19 forks source link

API request using count(*) query on "big" tables causes long page loading time #1531

Open jh-RLI opened 5 months ago

jh-RLI commented 5 months ago

Description of the issue

We explored the issue regarding to long loading times on tables with 100m+ rows.

Steps to Reproduce

  1. Search for open_FRED tagged tables for https://openenergy-platform.org/dataedit/view/climate/openfred_series
  2. Open detail page
  3. Data window shows a loading spinner for about ~1.6 min

Ideas of solution

The main source for this loading time is related to the count(*) query. This database function has to walk through the complete table before it can return the exact number of rows available.

In the example this takes about 40 s per count call, and it is called 2x. It will also repeatedly call for each filter that is applied but will perform reasonably.

TO mitigate this, we can attempt to reduce the initial page load as it is not necessary to call count(*) 2x for the same result. OR use the postgresql statistics module.

TO avoid count(*) in most cases we can pre-calculate this and store it, then only update it once the table was updated.

Context and Environment

Workflow checklist