feat: push --exclude down to driver query level#828
Conversation
4b42aaf to
987c0cd
Compare
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
|
@k1LoW is this more along the lines of what you are thinking? |
|
Thanks for reworking this. The direction looks great to me. Pushing I'll come back with a detailed review later. |
|
Thanks @k1LoW ! Sorry, I keep missing notifications on this PR |
|
Thanks for the rework — the direction (opt-in 1.
|
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