Rows excluded by a partial index still affect tin.full_score. These two indexes cover the same documents but produce different scores:
CREATE EXTENSION IF NOT EXISTS tin;
CREATE TEMP TABLE docs (body text, active boolean);
INSERT INTO docs VALUES ('beer', true), ('wine', true);
INSERT INTO docs
SELECT 'wine', false FROM generate_series(1, 100);
CREATE INDEX ON docs USING tin (body) WHERE active;
CREATE TEMP TABLE control AS SELECT body FROM docs WHERE active;
CREATE INDEX ON control USING tin (body);
SELECT tin.full_score(ctid) FROM docs
WHERE active AND body ==> 'beer';
-- 4.229264
SELECT tin.full_score(ctid) FROM control
WHERE body ==> 'beer';
-- 0.6931472
Both scores should be 0.6931472. Reproduced with Lead 1.0.3 and PostgreSQL 18.6.
load_documents() scans all non-null documents without applying the index predicate, so excluded rows enter the scoring statistics.
I've put a fix and two regression tests in my fork. Both tests fail before the fix; all 34 extension tests pass afterward on PostgreSQL 17.11 and 18.6. Sharing here since PRs are restricted to collaborators.
Rows excluded by a partial index still affect
tin.full_score. These two indexes cover the same documents but produce different scores:Both scores should be
0.6931472. Reproduced with Lead 1.0.3 and PostgreSQL 18.6.load_documents()scans all non-null documents without applying the index predicate, so excluded rows enter the scoring statistics.I've put a fix and two regression tests in my fork. Both tests fail before the fix; all 34 extension tests pass afterward on PostgreSQL 17.11 and 18.6. Sharing here since PRs are restricted to collaborators.