Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Parameterized scoring mismatch and subquery error

Chiusa
#11 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
postgresql, rust, sql
Ambito
databases

Direzione di ricerca

Start in postgres/src/score.rs, especially score_support(), combine_constant_queries(), and the caller around the cited lines. Reproduce both cases with the SQL in the issue, then trace parameter handling and scorer context propagation; done means parameterized and literal queries produce matching scores and the subquery aggregate no longer raises the context error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Ran into a couple issues with using lead for running tests versus actual hosted tin.

Environment: Lead 1.0.3, commit bd95c7e, PostgreSQL 18.6.

Using parameters instead of identical literals changes relevance scores.

Reproduction:

CREATE TEMP TABLE lead_score_repro (
    id integer PRIMARY KEY,
    title text NOT NULL
);

INSERT INTO lead_score_repro VALUES
    (1, 'lorem ipsum'),
    (2, 'lorem ipsun');

CREATE INDEX ON lead_score_repro USING tin (title);
ANALYZE lead_score_repro;

PREPARE lead_ranked(text, text) AS
SELECT id, tin.score(ctid) AS score
FROM lead_score_repro
WHERE title ==> $1 AND title ==> $2
ORDER BY id;

EXECUTE lead_ranked(
    'lorem^4',
    '(ipsum^4 OR ipsum~1^1.4 OR ipsum*^2)'
);

SELECT id, tin.score(ctid) AS score
FROM lead_score_repro
WHERE title ==> 'lorem^4'
  AND title ==> '(ipsum^4 OR ipsum~1^1.4 OR ipsum*^2)'
ORDER BY id;

This gives the following:

Query ID 1 score ID 2 score
Parameters 0.72928625 0.72928625
Literals 4.472281 0.72928625

I believe this is due to the first-query fallback in score_support() that causes this. combine_constant_queries() requires Const nodes and returns None for parameters. The caller then uses first_query, discarding the remaining expressions from scoring:

let combined_query = combine_constant_queries(&same_expression)
    .unwrap_or_else(|| pg_sys::copyObjectImpl(first_query.cast()).cast());

In EXPLAIN (VERBOSE, COSTS OFF), I see score_bound(title, $1, ...) for the parameterized query. For the literal query, I see both search expressions in the scorer's query argument.

Aggregating scores through a subquery raises a scoring-context error

CREATE TEMP TABLE lead_score_repro (
    id integer PRIMARY KEY,
    title text NOT NULL
);

INSERT INTO lead_score_repro VALUES
    (1, 'lorem ipsum'),
    (2, 'lorem ipsun');

CREATE INDEX ON lead_score_repro USING tin (title);
ANALYZE lead_score_repro;

-- Succeeds.
SELECT max(tin.score(ctid)) AS score
FROM lead_score_repro
WHERE title ==> 'lorem^4';

-- Fails.
SELECT max(score) AS score
FROM (
    SELECT tin.score(ctid) AS score
    FROM lead_score_repro
    WHERE title ==> 'lorem^4'
) AS matches;

For the direct aggregate, I get 0.72928625. For the subquery aggregate, I get:

ERROR: tin.score() requires a tin index scan and cannot be used in this query context
SQLSTATE: XX000
Lingua principale
Rust
Stelle
160
Fork
10
Merge medio
18h 42m
PR unite (30g)
16

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.