Commit Graph

72 Commits

Author SHA1 Message Date
Dominik c83a24ddb9 Merge branch 'development' into tweak/performance
Signed-off-by: Dominik <dl6er@dl6er.de>
2026-04-11 12:25:47 +02:00
Dominik f5f87d3ffb fix: sync test gravity.db.sql schema with production database
The test schema had drifted from the real /etc/pihole/gravity.db:
- domainlist/adlist used single-column UNIQUE instead of composite
  UNIQUE(domain,type) / UNIQUE(address,type), causing silent SQL
  failures on INSERT ... ON CONFLICT
- adlist column order had `type` in wrong position
- client table had `NOL NULL` typo (should be `NOT NULL`)
- *_by_group tables were missing ON DELETE CASCADE and WITHOUT ROWID
- info table was missing WITHOUT ROWID
- vw_gravity had extra `AND adlist.type = 0` filter not in production
- vw_adlist was missing `type` column in SELECT
- domainlist views had ORDER BY clauses not present in production
- Three indexes were missing (idx_adlist_by_group_gid,
  idx_domainlist_by_group_gid, idx_gravity)

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-30 20:32:12 +02:00
Dominik f039bff7f8 perf: use PK lookup in update triggers instead of UNIQUE text column
The tr_adlist_update, tr_client_update, and tr_domainlist_update
triggers used WHERE address/ip/domain = NEW.* to locate the row being
updated. This requires a B-tree traversal of the UNIQUE text index on
every UPDATE. Replace with WHERE id = NEW.id which uses the INTEGER
PRIMARY KEY (rowid alias) for O(1) direct lookup.

The tr_group_update trigger already used WHERE id = NEW.id — this
makes all four update triggers consistent.

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-24 06:13:09 +01:00
Dominik 1e52321b92 fix: correct "NOL NULL" typo to "NOT NULL" on client.ip in gravity schema
The client table's ip column was declared as "TEXT NOL NULL UNIQUE".
SQLite silently ignores the misspelled constraint, allowing NULL values
to be inserted despite the apparent intent. The UNIQUE constraint still
prevented duplicate NULLs (SQLite allows at most one NULL in a UNIQUE
column), but a single NULL IP row could cause client lookup failures.

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-24 06:07:44 +01:00
Dominik abc8f7e4f1 perf: skip redundant carray rebinds, use WITHOUT ROWID on junction tables
Add bind_client_groups() helper that tracks the last-bound SHM groupspos
per statement and skips sqlite3_carray_bind() when the array is already
bound. Since addintarray() deduplicates, clients sharing the same group
set (the common case — most installations use only the default group)
share the same groupspos, so after the first DNS query all subsequent
queries skip the rebind on all four hot-path statements. Each skipped
rebind avoids an internal carray_bind struct malloc/free cycle.

Add WITHOUT ROWID to adlist_by_group, domainlist_by_group,
client_by_group, and info tables. These have composite or TEXT primary
keys and no extra data columns — ideal candidates. WITHOUT ROWID
eliminates the hidden rowid B-tree so the PK is the storage key
directly, reducing one level of indirection per JOIN through the
gravity views.

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-24 05:17:41 +01:00
Dominik 5008c11619 fix: revert adlist ID caching, query gravity views live for correctness
Replace pre-computed per-client adlist ID arrays with live view queries
for gravity and antigravity lookups. The cached approach bypassed view
JOINs for ~4x faster lookups, but produced stale results when users
modified groups, adlists, or their assignments at runtime without
triggering a full gravity reload — the info.updated timestamp only
changes on "pihole -g", not on individual table edits.

All four hot-path query types (gravity, antigravity, allowlist, denylist)
now uniformly query through their respective views with
group_id IN carray(), binding the client's group IDs from SHM. The
views' LEFT JOINs live-check adlist.enabled, group.enabled, and group
assignments on every query, ensuring changes take effect immediately.

Removed:
- adlist_ids_stmt shared prepared statement
- get_client_adlist_ids() pre-computation function
- gravity_adlistpos / antigravity_adlistpos fields from clientsData
- Associated fork handling, init, reset, and finalization code

Kept from prior optimization work:
- Shared prepared statements with carray() binding
- SHM intarray storage for client group IDs
- Junction table (group_id, ...) indexes for carray filter performance

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-24 05:09:31 +01:00
Dominik 5cd86f7e1f perf: add ANTIGRAVITY_TABLE support, dedup regex queries, and add junction table indexes
- Add ANTIGRAVITY_TABLE enum, count query, getTable case, and SHM/API counter
- Add SELECT DISTINCT to regex group queries to eliminate duplicates when a
  client belongs to multiple groups containing the same regex
- Add (group_id, ...) indexes on adlist_by_group and domainlist_by_group to
  enable index seeks for carray()-filtered queries instead of full scans
- Remove unnecessary ORDER BY from domainlist views
- Restore LEFT JOINs in domainlist views (groups can be removed at runtime)

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-24 04:48:08 +01:00
Dominik 4edba811fb fix: add missing gravity/antigravity domain indexes to test schema
The real gravity.db created by pihole -g has idx_gravity ON
gravity(domain, adlist_id) — a covering index that enables O(log n)
domain lookups instead of full table scans. The test schema was missing
this index, making it out of sync with actual deployments. Also adds the
equivalent index for the antigravity table.

Signed-off-by: Dominik <dl6er@dl6er.de>
2026-03-22 10:31:02 +01:00
DL6ER fe29217860 Rename the views from white/black to allow/deny as well as some internal constants for consistency. Note that this requires an increase in gravity database version
Signed-off-by: DL6ER <dl6er@dl6er.de>
2025-08-15 19:56:28 +02:00
DL6ER 72aea366fa Port gravity.db update to version 19 into FTL's testing harness
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-12-28 11:10:58 +01:00
DL6ER 7c29048009 Translate anti-/gravity list IDs to negative numbers so they can be distinguish from domains rather easily. Users are free to foil this method when they force negative IDs into the database but they will never be automatically created
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-12-25 06:10:01 +01:00
Dominik 17a2038b22 Merge pull request #1807 from pi-hole/tweak/special_domains_prio
Implement special domains allowing
2023-12-13 19:45:14 +01:00
DL6ER 34cfc9c465 Remove undocumented audit feature
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-12-08 07:53:49 +01:00
DL6ER 6a42fc5757 Tests: Add CI test for allowing special domains per group
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-12-07 20:54:49 +01:00
DL6ER 470689da47 Add antigravity and /api/search related CI tests
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-10-07 21:52:42 +02:00
DL6ER f8b8e63044 Add antigravity (subscribed allowlists with wildcard support)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-09-15 21:39:04 +02:00
DL6ER 07f1f7df44 Save number of ABP-style entries in adlist table's new column abp_entries
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-06-15 09:38:37 +02:00
DL6ER 44c3fe4ef4 Merge remote-tracking branch 'origin/development' into new/http
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-03-13 10:30:39 +01:00
DL6ER ae9b291082 Set abp_domains = 1 during the CI tests.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-26 07:19:48 +01:00
DL6ER 8794b1684d Add ABP format blocking support for gravity. Note that the option needs to be switched on by setting GRAVITY_ABP_STYLE=true in pihole-FTL.conf to avoid running this computationally expensive task on the vast majority of user databases only fed from properly formatted HOSTS lists. Gravity can enable the setting when it detects ABP format automatically.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-15 19:48:19 +01:00
DL6ER 9833fe1af0 Reload gravity database when 'updated' property in table 'info' has changed
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-05 16:44:14 +01:00
DL6ER 5e2e6e6fa4 Merge branch 'development' into new/http
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-02-01 21:48:41 +01:00
DL6ER 49e1c74455 New syntax: querytype=A accepts now also a list (like querytype=A,AAAA,MX). You can use the exclamation mark as before for inversion (querytype=!A) matches everything BUT type A queries. This has now been extended to be able to invert a list, too (like (querytype=!A,AAAA matches everything BUT A and AAAA queries)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2023-01-26 20:11:55 +01:00
DL6ER a9ea62a3fc Merge branch 'development' into new/http
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-12-30 15:12:14 +01:00
DL6ER 0f520269d8 Merge pull request #1415 from pi-hole/adlist_message_table
Add warning about inaccessible adlists to message table (Pi-hole diagnosis)
2022-09-08 13:42:30 +02:00
DL6ER 84085bebcd Tests: CNAME inspection: NODATA CNAME targets are blocked
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-09-05 20:07:19 +02:00
Christian König 94a28040fa Update gravity.db.sql
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-08-31 23:51:29 +02:00
DL6ER 20ba471ccd pihole-FTL.log was renamed to FTL.log
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-07-17 12:20:28 +02:00
DL6ER fd2a633d20 Use FTLs embedded SQLite3 engine for the tests instead of relying whatever the system may be providing
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-01-18 15:37:42 +01:00
DL6ER c0570c51c2 Merge branch 'development' into new/http
Signed-off-by: DL6ER <dl6er@dl6er.de>
2021-11-02 09:53:13 +01:00
yubiuser 65c9fc0147 Simplify vw_adlist
Signed-off-by: yubiuser <ckoenig@posteo.de>
2021-10-13 22:24:03 +01:00
DL6ER 8be285c375 Speed up regex option tests by predefining them instead of injecting during runtime
Signed-off-by: DL6ER <dl6er@dl6er.de>
2021-10-10 12:10:13 +02:00
DL6ER 02154d2023 Add powerDNS to the CI testing suite to serve zone ftl. locally
Signed-off-by: DL6ER <dl6er@dl6er.de>
2021-10-10 12:08:41 +02:00
DL6ER 1db7c40106 Update tests
Signed-off-by: DL6ER <dl6er@dl6er.de>
2021-04-26 14:40:06 +02:00
DL6ER 45faefa786 Merge branch 'development' into new/http
Signed-off-by: DL6ER <dl6er@dl6er.de>
2021-04-26 14:09:50 +02:00
DL6ER 07642c8ab7 Tests: Update gravity.db template used for the tests to version 12.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-06-23 16:49:08 +02:00
DL6ER 873bcf8cc3 Tests: Add tests for MAC address and interface name client selections.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-06-23 16:49:08 +02:00
DL6ER 1af474819c Update tests to use gravity domain count stored in test database.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-02-03 08:43:06 +01:00
DL6ER abf0e4cdec Adjust tests after the last bugfix, bring gravity.db.sql schema to version 9.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-30 20:54:11 +00:00
DL6ER b6d74c701c Fix two testing errors.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-18 22:13:07 +00:00
DL6ER 80584788ad Add new zero-group-specific tests (domain associated ONLY to a particular query is only seen by this client).
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-12 17:51:44 +00:00
DL6ER 5637d132bf Update FTL gravity.db.sql template to gravity database version 7.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-12 17:42:26 +00:00
DL6ER 685d4a7c5b Add tests for a third client that is member of an empty group. This client bypasses Pi-hole entirely as no adlists, exact or regex blacklists are enabled for it.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-19 18:55:41 +02:00
DL6ER 382e8dd43b Tests: add third client that does not block anything (tagged with an empty group)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-19 16:00:02 +02:00
DL6ER fe0ec848d4 Add per-client tests
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-18 20:53:51 +02:00
DL6ER 609e09ad5f Merge branch 'development' into new/internal-blocking
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-10 21:15:20 +02:00
DL6ER 06c885a150 Improve tests by testing only against our own testing domains instead of relying on the outcome of some formally randomly selected domains.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-09 22:07:15 +02:00
DL6ER c19067b6a3 Update gravity.db.sql to version 4
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-09 21:46:23 +02:00
DL6ER 429a71dd56 Improve tests by testing only against our own testing domains instead of relying on the outcome of some formally randomly selected domains.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-09-09 21:45:29 +02:00
DL6ER be1b573a2a Rename regex blacklist trigger to tr_regex_blacklist_update.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-07-16 11:36:00 +02:00