Tables:
CREATE TABLE IF NOT EXISTS eth.filter_criteria (
id BIGSERIAL PRIMARY KEY,
contract VARCHAR(66),
topic0 VARCHAR(66),
topic1 VARCHAR(66),
topic2 VARCHAR(66),
topic3 VARCHAR(66),
UNIQUE (contract, topic0, topic1, topic2, topic3)
);
CREATE TABLE IF NOT EXISTS eth.filter_ranges (
filter_criteria_id BIGINT NOT NULL,
start BIGINT NOT NULL,
stop BIGINT NOT NULL,
PRIMARY KEY (filter_criteria_id, start, stop),
FOREIGN KEY (filter_criteria_id) REFERENCES eth.filter_criteria (id)
);
Pseudo-query to check if a range has all the logs for the desired criteria
SELECT EXISTS(1) FROM eth.filter_ranges INNER JOIN eth.filter_criteria ON (filter_ranges.filter_criteria_id = filter_criteria.id)
WHERE contract = $1
AND topic0 = $2
AND topic1 = $3
AND topic2 = $4
AND topic3 = $5
AND {some subquery that checks that the desired start and stop intervene a contiguous range in the joined filter_ranges table}