-
-
Notifications
You must be signed in to change notification settings - Fork 190
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 queries table #1255
Optimize queries table #1255
Conversation
…ngs into a linking table and referencing them by an ID. This also allows storing (IP,hostname) pair for clients. Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
… that the prepared statement will be retained for a long time and probably reused many times. Without this flag, SQLite3 assumes that the prepared statement will be used just once or at most a few times and then destroyed relatively soon. The current implementation acts on this hint by avoiding the use of [lookaside memory] so as not to deplete the limited store of lookaside memory. Also, update the tests for the expected database schema after renaming the table and adding the new view. Signed-off-by: DL6ER <dl6er@dl6er.de>
Putting this back to draft mode as we might want to explore another link-table for |
Signed-off-by: DL6ER <dl6er@dl6er.de>
277542b
to
729ff31
Compare
…nothing is actually INSERTed as we chose the OR IGNORE path. Signed-off-by: DL6ER <dl6er@dl6er.de>
729ff31
to
4516ee2
Compare
Ready for review. The |
Branch updated from latest |
After switching to that branch
|
This will need some documentation changes in https://docs.pi-hole.net/database/ftl/ E.g. |
…en couting them Signed-off-by: DL6ER <dl6er@dl6er.de>
@yubiuser Thanks for the error message, you indeed found the spot where the renaming |
Error is fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remember the documentation.
Thanks for that update.
Do we need any modification on web
? I know it will use the queries
view now automatically, but generating the view can take some time. We might not need all columns from there, e.g. wenn computing "Long term graph"
Just an idea: now that you shrank the size per record tremendously, should we save the reply as well? |
I will use this PR as reminder by only merging when I had time to work on the documentation changes.
We are not requesting these columns through the VIEW, hence, they are also not looked up. For instance, take https://github.com/pi-hole/AdminLTE/blob/682a174330d37c4bb8222ff371a3a4b7d363fafa/api_db.php#L264 SELECT COUNT(timestamp) FROM queries; compiles to the following database engine bytecode:
Querying SELECT COUNT(timestamp) FROM query_storage;
as the former already uses the real storage. The same holds true for all other queries.
For v6.0, I already implemented storing everything visible on the Query Log (also reply time, and DNSSEC status). We can do this already now, that's a good idea. Something for a follow-up PR. |
Signed-off-by: DL6ER <dl6er@dl6er.de>
This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there: https://discourse.pi-hole.net/t/pi-hole-ftl-v5-14-web-v5-11-and-core-v5-9-released/53529/1 |
This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there: https://discourse.pi-hole.net/t/delete-queries-error/53761/2 |
This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there: https://discourse.pi-hole.net/t/adding-many-lists-via-shell/54356/2 |
This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there: https://discourse.pi-hole.net/t/pi-hole-blocking-less-than-expected/54394/8 |
By submitting this pull request, I confirm the following:
How familiar are you with the codebase?:
10
This PR optimizes the
queries
table by using link-tables with IDs instead of storing thedomain
,client
andforward
as strings over and over. This is not a breaking change to users as we provide aVIEW queries
in place of the oldTABLE queries
that will give the same results for external queries as before:VIEW queries
TABLE query_storage
(holding the real data)In the example above, storage required per query before:
Storage required per query with the optimization of this PR:
This reduction by factor 4 easily outperforms the tiny extra amount of space we need for the newly introduced link-tables. We chose this hybrid approach through the
VIEW
because we cannot afford rewriting the entirequeries
table as this would literally take forever on low-end devices such as Raspberry Pis from the early days.This also lays the foundation for a requested feature that is availability of host names in the long-term database as the linked client ID are in fact a pair of
(ip,hostname)
in the database. This allows us to store both without any really noticeable overhead.This PR comes with a tiny drawback (that isn't really one, though): After the database has been optimized (upgraded to version 11), older versions of FTL will not be able to write new queries to the database. It is possible to revert the upgrade of the database without data-loss, however, it is a multiple-step task and should not be done copy-paste-like. That's why I'm not giving the precise instructions to do this here.
edit We furthermore save some space on the
additional_information
field that con contain domains when blocking during deep CNAME inspection.