Skip to content

Db2 fdw percentile push down#120

Merged
temuenz merged 7 commits into
masterfrom
db2_fdw_percentile_push_down
Jul 18, 2026
Merged

Db2 fdw percentile push down#120
temuenz merged 7 commits into
masterfrom
db2_fdw_percentile_push_down

Conversation

@temuenz

@temuenz temuenz commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

temuenz and others added 7 commits July 11, 2026 10:36
… result-type crash

foreign_expr_walker now recurses into Aggref.aggdirectargs (previously
unwalked) and consults a shared db2AggregateInfo() helper so it only
approves aggregates the deparser actually knows how to emit. deparseAggref
gains deparseOrderedSetAggref() to build DB2's
FUNC(fraction) WITHIN GROUP (ORDER BY col ASC|DESC) syntax for
percentile_cont/percentile_disc, restricted to the single-column,
non-array form DB2 supports.

While testing this against the live DB2 instance, found that
getUsedColumns() derived every pushed-down aggregate's result column type
by borrowing its argument column's DB2 type. That's only correct when the
aggregate preserves its input type (MIN/MAX, PERCENTILE_DISC); for
AVG/SUM/PERCENTILE_CONT the output type differs, which crammed DB2's
DECFLOAT-formatted result into a wrongly-typed, undersized buffer -
crashing the backend on AVG(bigint_col) and producing a parse error for
PERCENTILE_CONT. Now re-tags the result column with the aggregate's real
return type when it differs from the borrowed argument type, routing it
through the existing safe SQLGetData/text-fetch path.

Verified against live DB2: PERCENTILE_CONT/PERCENTILE_DISC push down
correctly (index-only scan), AVG(bigint) no longer crashes, and existing
MIN/MAX/AVG/SUM/COUNT pushdown output is unchanged. Added real
PERCENTILE_CONT/PERCENTILE_DISC assertions to tc015.sql and refreshed
expected output.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@temuenz temuenz linked an issue Jul 18, 2026 that may be closed by this pull request
@temuenz
temuenz merged commit 7cf0b8a into master Jul 18, 2026
4 checks passed
@temuenz
temuenz deleted the db2_fdw_percentile_push_down branch July 18, 2026 10:28
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.

Enhancement: Pass-through queries

1 participant