Skip to content

fix: fdw/external support filter pushdown for numeric columns with integer constants#103

Merged
MisterRaindrop merged 4 commits intoapache:mainfrom
MisterRaindrop:liuxiaoyu/fix_numeric
Apr 19, 2026
Merged

fix: fdw/external support filter pushdown for numeric columns with integer constants#103
MisterRaindrop merged 4 commits intoapache:mainfrom
MisterRaindrop:liuxiaoyu/fix_numeric

Conversation

@MisterRaindrop
Copy link
Copy Markdown
Collaborator


Change logs

When a numeric column is compared with an integer constant (e.g.,
biz_dt = 20260331), PostgreSQL wraps the constant in an implicit
type cast FuncExpr (int4 -> numeric). The filter extraction code
only recognized plain Const nodes, causing these filters to be
dropped and resulting in full table scans on the source.

Contributor's checklist

Here are some reminders before you submit your pull request:

MisterRaindrop and others added 4 commits April 7, 2026 10:09
When a numeric column is compared with an integer constant (e.g.,
biz_dt = 20260331), PostgreSQL wraps the constant in an implicit
type cast FuncExpr (int4 -> numeric). The filter extraction code
only recognized plain Const nodes, causing these filters to be
dropped and resulting in full table scans on the source.

Use eval_const_expressions() to evaluate implicit cast expressions
back to plain Const nodes before filter extraction.
The previous commit fixed fdw/pxf_filter.c but the external table
code path (external-table/src/pxffilters.c) has the same issue in
opexpr_to_pxffilter(). Apply the same eval_const_expressions() fix
to handle implicit type casts on constants.
Extend FilterPushDownTest / FDW_FilterPushDownTest regression suites
with c3 = 5 and c3 < 5 to exercise the '=' and '<' operators with an
integer constant against a numeric column — the original scenario
behind the pushdown fix (biz_dt = 20260331) was previously only
covered for >, <=, >=, <> and BETWEEN.

Also sync FilterPushDownTest.sql to include the int-const block in
both test segments, matching the expected output.
@MisterRaindrop MisterRaindrop marked this pull request as ready for review April 17, 2026 12:25
Copy link
Copy Markdown
Collaborator

@ostinru ostinru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Great!

@MisterRaindrop MisterRaindrop merged commit 2789f81 into apache:main Apr 19, 2026
93 of 111 checks passed
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.

2 participants