Skip to content

Backport #168: Fix zero scores when querying hypertables#175

Merged
tjgreen42 merged 2 commits intorelease/0.4.2from
backport-168-hypertable-zero-scores
Jan 25, 2026
Merged

Backport #168: Fix zero scores when querying hypertables#175
tjgreen42 merged 2 commits intorelease/0.4.2from
backport-168-hypertable-zero-scores

Conversation

@tjgreen42
Copy link
Copy Markdown
Collaborator

Summary

Backport of #168 to the 0.4.2 release branch.

Fixes zero scores when querying hypertables with BM25 indexes:

  1. Planner hook fix for CustomScan - Add T_CustomScan handling in plan_has_bm25_indexscan() to detect BM25 index scans nested inside custom scans (e.g., TimescaleDB's ConstraintAwareAppend)

  2. Standalone scoring fix for hypertable parent indexes - When using standalone BM25 scoring with a hypertable parent index name, the code was falling back to child index stats but NOT switching to the child's index relation and segment metadata

Testing

Cherry-picked from main where it passed all CI checks.

The planner hook's plan_has_bm25_indexscan() and replace_scores_in_plan()
functions didn't handle CustomScan nodes (like TimescaleDB's
ConstraintAwareAppend). This caused the hook to miss BM25 index scans
nested inside custom scans, so score expressions weren't replaced with
stub functions that retrieve cached scores from the index scan.

As a result, standalone scoring was used instead, which looked up the
parent hypertable index (which has total_docs = 0), producing zero
scores for all results.

The fix adds T_CustomScan cases that recurse into cscan->custom_plans
to properly detect and process BM25 index scans.
When using standalone BM25 scoring on a hypertable with the parent index
name (e.g., `content <@> to_bm25query('database', 'parent_idx')`), the
code was falling back to child index stats (total_docs, avg_doc_len) but
NOT switching to the child's index relation and segment metadata. This
caused IDF calculation to fail because it was looking up document
frequencies in the parent index's segments (which are empty).

The fix switches to the child index for segment access when falling back
to a child index's state. This ensures that both memtable and segment
lookups use the correct child index.

Also adds:
- Test 5 in partitioned.sql for MergeAppend score expression replacement
- test/scripts/hypertable.sh for optional TimescaleDB integration testing
@tjgreen42 tjgreen42 merged commit 79cbb30 into release/0.4.2 Jan 25, 2026
11 checks passed
@tjgreen42 tjgreen42 deleted the backport-168-hypertable-zero-scores branch January 25, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant