feat: push --exclude down to driver query level#828
Draft
patkujawa-wf wants to merge 2 commits intok1LoW:mainfrom
Draft
feat: push --exclude down to driver query level#828patkujawa-wf wants to merge 2 commits intok1LoW:mainfrom
patkujawa-wf wants to merge 2 commits intok1LoW:mainfrom
Conversation
4b42aaf to
987c0cd
Compare
k1LoW
reviewed
Apr 27, 2026
Owner
k1LoW
left a comment
There was a problem hiding this comment.
Thank you for the PR!
I can see the value in excluding partition tables at the query level for performance. However, --skip-partitions is a PostgreSQL-specific flag, and I'm hesitant to add driver-specific options to the CLI surface.
I think a more general approach would be to improve the existing table scanning and exclude filtering so that exclusions can be applied earlier (e.g., at the query level) rather than after the full schema is fetched. That would benefit all drivers and work with the existing configuration, not just for partitions.
Also, this PR depends on #827 (--verbose), which I don't plan to merge at this time.
- Add --skip-partitions flag to skip PostgreSQL table partitions - Skip relations referencing excluded partition tables - Reduces unnecessary scanning with partitioned tables
987c0cd to
77770d5
Compare
Per review feedback on k1LoW#828: drop the postgres-specific --skip-partitions flag and instead push the existing --exclude patterns down to the table-listing query so all drivers can benefit. - Add drivers.TableFilterer optional interface (SetTableExcludes) - Plumb excludes via datasource.WithTableExcludes(...) AnalyzeOption - Add config.PushDownableTableExcludes() that returns excludes only when no Include/IncludeLabels are set (so distance traversal can't re-pull excluded tables, and post-fetch schema.Filter remains authoritative) - Implement TableFilterer on the postgres driver: convert glob '*' to SQL LIKE '%' (escaping literal % and _), match both bare and schema-qualified relnames, drop relations whose parent was filtered - Remove --skip-partitions flag and cmdutil/skippartitions.go; partitioned-schema users should now write --exclude 'partition_prefix_*' instead
Author
|
@k1LoW is this more along the lines of what you are thinking? |
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
Pushes
--excludepatterns down to the driver's table-listing query, so excluded tables are never scanned in the first place. For postgres, that skips the 5–6 detail queries (columns, indexes, constraints, triggers, FKs) per excluded table.Replaces the original
--skip-partitionsproposal per review feedback — partitioned-schema users now write--exclude 'partition_prefix_*'and get the same perf win without a postgres-specific flag.Changes
drivers.TableFiltererinterface (SetTableExcludes([]string)); drivers opt in.datasource.Analyzenow accepts...AnalyzeOption;WithTableExcludes(...)plumbs patterns through.config.PushDownableTableExcludes()returns excludes only when noInclude/IncludeLabelsare set, so distance traversal can't silently drop tables. Post-fetchschema.Filterremains authoritative.TableFilterer: converts glob*→ SQLLIKE '%'(escaping_,%,\), matches both bare and schema-qualified relnames, drops FK relations whose parent was filtered.--skip-partitionsflag andcmdutil/skippartitions.goremoved.globToLikeandqueryForTables(no DB required).Test plan
go build ./...,go vet ./...go test ./schema/... ./config/... ./cmdutil/... ./drivers/postgres/...--exclude 'events_p*'— confirm child partitions skipped--exclude: behavior unchanged