Fix Get-DbaDbTable performance regression #10141
Open
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.
Resubmit PR from @PeterSawatzki-MGGM which keeps his commits but hopefully is able to merge.
Fix Get-DbaDbTable performance regression when using -Schema or -Table parameters
The ClearAndInitialize optimization introduced in 2.7.7 loads ALL tables in the database before filtering client-side. This causes severe performance issues (30+ seconds vs <1 second) when only specific tables are requested.
This fix adds server-side filtering by passing an XPath-style URN filter to ClearAndInitialize when -Schema or -Table parameters are specified.
Example filter: [@Schema='dispo' and @name='t_auftraege']
Performance improvement:
Type of Change
Invoke-ManualPester)Purpose
Fix a severe performance regression introduced in version 2.7.7 where
Get-DbaDbTablewith-Schemaor-Tableparameters loads ALL tables in the database before filtering client-side, causing execution times to increase from <1 second to 30+ seconds on databases with many tables.Approach
The
ClearAndInitializeoptimization added in 2.7.7 uses an empty filter string, which causes SMO to load all tables:This fix constructs an XPath-style URN filter when
-Schemaor-Tableparameters are specified, enabling server-side filtering:The filter syntax follows the SMO ClearAndInitialize documentation.
Commands to test
Screenshots
SQL Server Profiler comparison:
sys.tablessys.partitionsLearning
ClearAndInitializemethod accepts an XPath-style filter as the first parameter[@Property='value']format withand/oroperators