fix(oracle): restore PG query semantics and clean up migration chain#1312
Merged
nicoloboschi merged 1 commit intomainfrom Apr 29, 2026
Merged
fix(oracle): restore PG query semantics and clean up migration chain#1312nicoloboschi merged 1 commit intomainfrom
nicoloboschi merged 1 commit intomainfrom
Conversation
The Oracle PR (#1307) introduced subtle behavioral changes to two PG query patterns during the abstraction refactor: 1. semantic_expanded CTE: the DISTINCT ON rewrite lost the global ORDER BY score DESC before LIMIT. When results exceeded the budget, the LIMIT applied in mu.id order instead of keeping the highest- scored rows. Fix: wrap DISTINCT ON in a subquery that re-sorts by score before applying LIMIT. 2. temporal neighbors: the ROW_NUMBER() OVER (PARTITION BY ... ORDER BY time_diff_hours) filter was dropped, doubling the returned rows per probe (K per direction × 2 instead of K closest overall). Fix: restore the ROW_NUMBER filter around the UNION ALL of both scan directions, for both PG and Oracle backends. 3. Migration chain: remove two empty merge migrations that were artifacts of the Oracle branch being developed in parallel (e6f7g8h9i0j1, j5k6l7m8n9o0) and linearize the chain: 8c6fa6f7230b → d5y6z7a8b9c0 → i4j5k6l7m8n9 → k6l7m8n9o0p1
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1307 (Oracle 23ai backend). Fixes three issues introduced during the abstraction refactor:
DISTINCT ONrewrite lost the globalORDER BY score DESCbeforeLIMIT. When results exceeded the budget, the LIMIT applied inmu.idorder instead of keeping the highest-scored rows. Fixed by wrappingDISTINCT ONin a subquery that re-sorts by score beforeLIMIT(both PGbuild_semantic_causal_cteand observation expansion)ROW_NUMBER() OVER (PARTITION BY ... ORDER BY time_diff_hours)filter was dropped, doubling returned rows per probe (K per direction × 2 instead of K closest overall). Restored for both PG and Oracle backendse6f7g8h9i0j1,j5k6l7m8n9o0) that were artifacts of the Oracle branch being developed in parallel. Linearized the chain:8c6fa6f7230b → d5y6z7a8b9c0 → i4j5k6l7m8n9 → k6l7m8n9o0p1Test plan
test_link_expansion_retrieval.py— 2/2 passedtest_db_abstraction.py— 80/80 passedtest_memories_timeseries_empty_bank_returns_zero_filled_buckets— fails identically on main)