Get-DbaDbTable: Fix performance regression with URN filter and config option#10140
Conversation
|
Thanks so much for your PR! Tests are so busted from yesterday's outage. gonna close and reopen to try to push it forward. |
…e 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: - Before: ~30 seconds (loads 1000+ tables) - After: <1 second (loads only requested table)
Add 'commands.get-dbadbtable.clearandinitialize' config option (default: false) to let users opt-in to the ClearAndInitialize optimization. This prevents pipeline commands like Copy-DbaDbTableData from having their SMO cache cleared. Co-Authored-By: Claude Opus 4.6 <[email protected]>
0549886 to
842d1e7
Compare
|
Thank you so much! Will release shortly 🪄 |
|
Sorry, I added two comments to the code, one with text and one with mentions only. Here is everything together at the correct place: Maybe this was merged too fast... In the old version we used And we now calculate a I think the test for Should I open a follow up pull request? |
|
yes please. |
|
Just opened #10157 for that. |
Azure SQL's SMO enumerator does not support the IndexSpaceUsed and DataSpaceUsed properties. When ClearAndInitialize is called with an explicit property list that includes these, it throws: "unknown property IndexSpaceUsed" The fix removes these two properties from the list before calling ClearAndInitialize when the server is Azure SQL. The call itself remains unconditional (matching the pre-#10140 behavior), and the URN filter logic from #10157 is unchanged. Fixes #10181 (do Get-DbaDbTable, Copy-DbaDbTableData) Co-authored-by: Andreas Jordan <[email protected]>
Summary
Fixes #10139 - Get-DbaDbTable performance regression introduced in 2.7.7.
-Schemaor-Tableparameters are specified, builds a proper URN filter (e.g.,[@Schema='dbo' and @Name='MyTable']) and passes it toClearAndInitialize()instead of an empty string. This ensures only matching tables are loaded from the server, restoring sub-second performance for targeted queries.commands.get-dbadbtable.clearandinitialize: Controls whetherClearAndInitializeis called at all. Defaults to$falseto prevent breaking pipeline commands likeCopy-DbaDbTableDatathat reuse SMO objects (whereClearAndInitializeclears already loaded properties from the collection).Enabling the performance optimization
Users who call
Get-DbaDbTablestandalone (not piped from reused SMO connections) can opt-in to bulk property loading:When enabled,
ClearAndInitializeloads all requested table properties (Schema, Name, RowCount, IndexSpaceUsed, etc.) in a single optimized SQL query, with server-side filtering via URN when-Schemaor-Tableis specified.Test plan
Get-DbaDbTable -SqlInstance $srv -Database $db -Table "specific_table"returns quickly (sub-second) regardless of config setting, thanks to URN filterGet-DbaDbTable -SqlInstance $srv -Database $dbreturns all tables correctlyCopy-DbaDbTableDatapipeline scenarios work without losing SMO properties (config default$false)$true) activatesClearAndInitializefor bulk loading optimization(do Get-DbaDbTable)
🤖 Generated with Claude Code