Skip to content

fix(mssql): apply INCLUDING/EXCLUDING before per-table catalog queries - #1785

Open
George-Fam wants to merge 2 commits into
dimitri:mainfrom
George-Fam:fix/mssql-catalog-prefilter
Open

George-Fam wants to merge 2 commits into
dimitri:mainfrom
George-Fam:fix/mssql-catalog-prefilter

Conversation

@George-Fam

Copy link
Copy Markdown

Thanks for pgloader. I found this while evaluating v4 for an MSSQL migration.

Problem

In v4, MSSQLSource ignores the table-spec passed to create-source, so catalog runs five metadata queries per table (columns, primary keys, indexes, foreign keys, extended properties) for every user table, and core.clj applies INCLUDING/EXCLUDING only afterwards. With INCLUDING ONLY TABLE NAMES LIKE 'x' on a database with many tables, the catalog step still costs five round trips for each table in the database.

The migrated tables are correct, but the cost regressed. v3 had pushed these filters into the MSSQL catalog SQL since 46be4a5; the v4 rewrite (9fb3fae) dropped it.

Fix

create-source now passes (:table-filter table-spec) to MSSQLSource, and catalog applies it to the table list before the per-table queries. Without a filter, behaviour is unchanged.

The post-filter in core.clj stays. Both filters see the same raw table name, so the set of migrated tables is identical.

Testing

  • New unit test test-catalog-prefilters-tables: stubs the catalog queries and checks that, with a table filter, per-table metadata is only queried for the matching tables. It fails on main and passes with the fix.
  • New regression test 14-including-only: an includetest database with two keep_* tables and one drop_audit table, loaded with INCLUDING ONLY TABLE NAMES LIKE 'keep%' IN SCHEMA 'inc'. Checks that only the matching tables are migrated, with their rows and the foreign key between them. Passes with v3 and v4.
  • make test-unit: 139 tests, 523 assertions, 0 failures. cljfmt clean.
  • Full CI is green on my fork: test(mssql): cover INCLUDING/EXCLUDING catalog pre-filtering George-Fam/pgloader#2

MSSQLSource ignored the table-spec passed to create-source, so catalog
listed every user table and ran five metadata queries per table
(columns, primary keys, indexes, foreign keys, extended properties)
before core.clj filtered the result. INCLUDING ONLY therefore could not
shorten the catalog sweep, which scales with the total table count.

This restores v3 behaviour, where INCLUDING/EXCLUDING have been pushed
into the MSSQL catalog SQL since 46be4a5 (2014); the v4 port has
ignored table-spec since the v4 Clojure rewrite (9fb3fae).
Unit test (mssql_test.clj): stub the catalog queries and check that, with
a table filter, per-table metadata is only queried for the matching
tables. Fails without the previous commit.

Regression test 14-including-only: an includetest database with two
keep_* tables and one drop_audit table, loaded by mssql-including.load
with INCLUDING ONLY TABLE NAMES LIKE 'keep%' IN SCHEMA 'inc'. Checks that
only the matching tables are migrated, with their rows and the foreign
key between them. Passes with v3 and v4.

This branch has not been deployed

No deployments
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.

1 participant