Repository navigation
Conversation
…ly pushed A pushed-down aggregate replaces the scan, so nothing re-checks restrictions that were not extracted as quals, and the FDW aggregates rows the WHERE clause should have removed. Grouping sets were also pushed down as a single group. Only push down when every baserestrictinfo clause became a qual and the query has no grouping sets. Fixes supabase#659
Author
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.
Why
SELECT count(*) FROM ft WHERE <cond>can return the count of the whole table when<cond>is not one the framework turns into aQual. The aggregate is pushed down anyway, it replaces the scan, and nothing re-checks the condition. Grouping sets are pushed down as one group the same way. Both give a wrong number with no error.Fixes #659.
What changed
get_foreign_upper_pathsnow skips aggregate pushdown when:baserestrictinfowas not extracted intostate.quals.extract_qualsmakes at most oneQualperRestrictInfo, so comparing the two lengths checks this exactly. A plainWHERE id = 1is still pushed down.postgres_fdwrefuses both cases the same way inforeign_grouping_ok.Tests
New cases in
clickhouse_aggregate_pushdown_test:COUNT(*) ... WHERE name || '' = 'alice'returns 2 and runs as a local aggregate. On main it returns 4.GROUP BY GROUPING SETS ((), ())yields two rows of 4. On main it yields one row.Run locally on pg15 against a native ClickHouse server:
cargo pgrx test --features "clickhouse_fdw pg15" pg15: 19 passedcargo test -p supabase-wrappers --no-default-features --features pg15 --lib: 36 passedRUSTFLAGS="-D warnings" cargo clippy --tests --no-deps --features "clickhouse_fdw pg15"inwrappers/: cleancargo fmt --check -p supabase-wrappers -p wrappers: cleanNot run: the other native FDW suites.