Skip to content

Instantly share code, notes, and snippets.

@i-norden
Last active October 6, 2023 15:21
Show Gist options
  • Save i-norden/72f322afa9f07de0df3e340782ce1d1d to your computer and use it in GitHub Desktop.
Save i-norden/72f322afa9f07de0df3e340782ce1d1d to your computer and use it in GitHub Desktop.
Example tables and pseudo-query

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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment