New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize history.get_last_state_changes query #87554
Optimize history.get_last_state_changes query #87554
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
…ct all the states in the table matching the entity it with it
Its stuck restoring the env Received 340880014 of 345074318 (98.8%), 0.2 MBs/sec |
The mariadb test is failing because point and point2 are the exact same time and since it now uses the index as expected it undefined which one will come first when there are two exact same times. MariaDB happens to use the insertion order where-as sqlite uses the last insertion order.
|
This fix has now been validated |
Proposed change
history.get_last_state_changes
has been optimized for single entity selects.Previously it allowed passing in
None
for the entity but that could have resulted inselecting the entire database. Nothing should have been doing that in practice so I didn't
mark this as a breaking change as anything doing that was already quite broken.
I've also removed the significant state change filtering since it would previously have to
select all the state changes that are present in the database for the entity and than
filter them out one by one since the query would always be without a time window which meant
we could select millions of states and run the system out of ram or force the query to go
to a temp store on disk. By removing the filtering we can use the index. Since this query
is only used for the filter integration that is not expected to change the results and
the existing tests pass as expected.
Type of change
Additional information
history.get_last_state_changes
is poorly optimized which results in overly long queries with the filter integration #81989Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: