Skip to content

Conversation

@DavidWiseman
Copy link
Collaborator

Insert settings into table variable before comparison to improve performance. Simplify DatabaseSettingsUnpivot_Get

Insert settings into table variable before comparison to improve performance.
Simplify DatabaseSettingsUnpivot_Get
Copilot AI review requested due to automatic review settings December 5, 2025 15:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the Databases_Upd stored procedure by materializing database settings into a table variable before comparison, and simplifies the DatabaseSettingsUnpivot_Get function by replacing a CTE-based UNPIVOT approach with a more efficient CROSS APPLY VALUES construct.

Key Changes:

  • Materialized function results into a table variable to prevent multiple function executions
  • Replaced CTE + UNPIVOT pattern with CROSS APPLY VALUES for better performance and readability
  • Added NULL filtering to exclude settings without values

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
DBADashDB/dbo/Stored Procedures/Databases_Upd.sql Introduces @NewSettings table variable to cache function results and avoid re-executing DatabaseSettingsUnpivot_Get during the JOIN operation
DBADashDB/dbo/Functions/DatabaseSettingsUnpivot_Get.sql Refactored from CTE + UNPIVOT to CROSS APPLY VALUES pattern, reducing code complexity and improving performance with NULL filtering

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +82 to +83
WHERE d.InstanceID = @InstanceID
AND u.Value IS NOT NULL
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new NULL filter on line 83 changes the function's behavior by excluding settings with NULL values, which were previously included in the UNPIVOT result. This could break existing logic in Databases_Upd that depends on tracking NULL values for certain settings. Verify that this exclusion is intentional and that NULL values should not be tracked in the history table.

Suggested change
WHERE d.InstanceID = @InstanceID
AND u.Value IS NOT NULL
WHERE d.InstanceID = @InstanceID

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNPIVOT removes the NULLs automatically. There is no functional change.

@DavidWiseman DavidWiseman merged commit 65395b8 into trimble-oss:main Dec 6, 2025
@DavidWiseman DavidWiseman deleted the Databases_Upd-performance branch December 6, 2025 12:13
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