core/homeassistant/components/recorder
Alex Hermann bdef0ba6e5
Significantly improve performance for some cases of the history start time state query (#99450)
* recorder: Apply filter in the outer query too

Function _get_start_time_state_for_entities_stmt() produced a query which
is dead-slow in my installation. On analysis, the outer query produced
millions of rows which had to be joined to the subquery. The subquery has
a filter which would eliminate almost all of the outer rows.

To speed up the query, apply the same filter to the outer query, so way
less rows have to be joined.

This reduced the query time on my system from more than half an hour to
mere milliseconds.

* lint

* merge filter

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2023-11-28 16:23:49 -06:00
..
auto_repairs
history Significantly improve performance for some cases of the history start time state query (#99450) 2023-11-28 16:23:49 -06:00
models
system_health
table_managers
__init__.py
backup.py
const.py
core.py
db_schema.py
entity_registry.py
executor.py
filters.py
manifest.json
migration.py
pool.py
purge.py
queries.py
repack.py
services.py
services.yaml
statistics.py
strings.json
tasks.py
util.py
websocket_api.py