perf: replace UNION with UNION ALL to avoid costly deduplication#372
Merged
halconel merged 2 commits intoepoch8:feat/offsetsfrom Feb 2, 2026
Merged
perf: replace UNION with UNION ALL to avoid costly deduplication#372halconel merged 2 commits intoepoch8:feat/offsetsfrom
halconel merged 2 commits intoepoch8:feat/offsetsfrom
Conversation
… avoid costly deduplication
…RCHAR-float type mismatch errors
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
Problem 1: UNION deduplication overhead
Current implementation uses
UNIONwhich forces PostgreSQL to:This causes slow queries (~818ms) even with proper indexes.
Solution
Use
UNION ALLwith explicit duplicate exclusion in WHERE:WHERE update_ts > offsetWHERE delete_ts > offset AND update_ts <= offsetThis eliminates duplicates at query planning stage, allowing early LIMIT application.
Performance Impact: 4,757x faster (818ms → 0.172ms in production)
Problem 2: NaN values cause type mismatch
When DataFrame columns contain NaN values (common for NULL-able foreign keys like
profile_id), pandas passes them as Pythonfloat('nan')to SQL queries:PostgreSQL error:
operator does not exist: character varying = double precisionThis causes:
Solution
Filter NaN values before building SQL IN clauses:
idx[key].dropna().to_list()idx[primary_keys].dropna()Follows pattern from commit b3e7cc5 which fixed the same issue for join_keys.
Changes
Modified files:
datapipe/meta/sql_meta.py- UNION ALL optimization in 3 functionsdatapipe/sql_util.py- NaN filtering insql_apply_idx_filter_to_tableAll offset tests pass (64 tests).