Skip to content

Commit 451e302

Browse files
Darling Datagflpcantor31
authored andcommitted
Automation: Format and Build SQL File
1 parent 1e708b2 commit 451e302

2 files changed

Lines changed: 4 additions & 257 deletions

File tree

Install-All/DarlingData.sql

Lines changed: 3 additions & 256 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Compile Date: 12/28/2025 14:31:00 UTC
1+
-- Compile Date: 12/28/2025 14:49:57 UTC
22
SET ANSI_NULLS ON;
33
SET ANSI_PADDING ON;
44
SET ANSI_WARNINGS ON;
@@ -17334,172 +17334,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1733417334
ia.*
1733517335
FROM #index_analysis AS ia
1733617336
OPTION(RECOMPILE);
17337-
17338-
/* Special debug for exact duplicates */
17339-
RAISERROR('Special debug for exact duplicates after rule 2:', 0, 0) WITH NOWAIT;
17340-
SELECT
17341-
ia1.index_name AS index1_name,
17342-
ia1.action AS index1_action,
17343-
ia1.consolidation_rule AS index1_rule,
17344-
ia1.index_priority AS index1_priority,
17345-
ia1.target_index_name AS index1_target,
17346-
ia1.filter_definition AS index1_filter,
17347-
ia2.index_name AS index2_name,
17348-
ia2.action AS index2_action,
17349-
ia2.consolidation_rule AS index2_rule,
17350-
ia2.index_priority AS index2_priority,
17351-
ia2.target_index_name AS index2_target,
17352-
ia2.filter_definition AS index2_filter
17353-
FROM #index_analysis AS ia1
17354-
JOIN #index_analysis AS ia2
17355-
ON ia1.scope_hash = ia2.scope_hash /* Same database and object */
17356-
AND ia1.index_name <> ia2.index_name
17357-
AND ia1.exact_match_hash = ia2.exact_match_hash /* Exact match: keys + includes + filter */
17358-
WHERE ia1.consolidation_rule = N'Exact Duplicate'
17359-
OR ia2.consolidation_rule = N'Exact Duplicate'
17360-
ORDER BY ia1.index_name
17361-
OPTION(RECOMPILE);
17362-
END;
17363-
17364-
/* Rule 3: Superset/subset key columns (runs before key duplicates to prioritize subset/superset relationships) */
17365-
IF @debug = 1
17366-
BEGIN
17367-
RAISERROR('Rule 3 debug - Testing JOIN conditions for subset/superset:', 0, 0) WITH NOWAIT;
17368-
SELECT
17369-
subset_index = ia1.index_name,
17370-
subset_keys = ia1.key_columns,
17371-
superset_index = ia2.index_name,
17372-
superset_keys = ia2.key_columns,
17373-
pattern_test = REPLACE(REPLACE(REPLACE(ia1.key_columns, '~', '~~'), '[', '~['), ']', '~]') + N', %',
17374-
like_match =
17375-
CASE
17376-
WHEN ia2.key_columns LIKE (REPLACE(REPLACE(REPLACE(ia1.key_columns, '~', '~~'), '[', '~['), ']', '~]') + N', %') ESCAPE '~'
17377-
THEN 'YES'
17378-
ELSE 'NO'
17379-
END,
17380-
filter_match =
17381-
CASE
17382-
WHEN ISNULL(ia1.filter_definition, '') = ISNULL(ia2.filter_definition, '')
17383-
THEN 'YES'
17384-
ELSE 'NO'
17385-
END,
17386-
ia1_eligible =
17387-
CASE
17388-
WHEN EXISTS
17389-
(
17390-
SELECT 1/0
17391-
FROM #index_details AS id1
17392-
WHERE id1.index_hash = ia1.index_hash
17393-
AND id1.is_eligible_for_dedupe = 1
17394-
)
17395-
THEN 'YES'
17396-
ELSE 'NO'
17397-
END,
17398-
ia2_eligible =
17399-
CASE
17400-
WHEN EXISTS
17401-
(
17402-
SELECT 1/0
17403-
FROM #index_details AS id2
17404-
WHERE id2.index_hash = ia2.index_hash
17405-
AND id2.is_eligible_for_dedupe = 1
17406-
)
17407-
THEN 'YES'
17408-
ELSE 'NO'
17409-
END,
17410-
sort_mismatch =
17411-
CASE
17412-
WHEN EXISTS
17413-
(
17414-
SELECT 1/0
17415-
FROM #index_details AS id1
17416-
JOIN #index_details AS id2
17417-
ON id2.column_position_hash = id1.column_position_hash
17418-
WHERE id1.index_hash = ia1.index_hash
17419-
AND id2.index_hash = ia2.index_hash
17420-
AND id1.is_descending_key <> id2.is_descending_key
17421-
)
17422-
THEN 'YES'
17423-
ELSE 'NO'
17424-
END,
17425-
ia1_consolidation_rule = ISNULL(ia1.consolidation_rule, 'NULL'),
17426-
ia2_consolidation_rule = ISNULL(ia2.consolidation_rule, 'NULL'),
17427-
ia1_is_unique_constraint =
17428-
CASE
17429-
WHEN EXISTS
17430-
(
17431-
SELECT 1/0
17432-
FROM #index_details AS id1_uc
17433-
WHERE id1_uc.index_hash = ia1.index_hash
17434-
AND id1_uc.is_unique_constraint = 1
17435-
)
17436-
THEN 'YES'
17437-
ELSE 'NO'
17438-
END,
17439-
ia2_is_unique_constraint =
17440-
CASE
17441-
WHEN EXISTS
17442-
(
17443-
SELECT 1/0
17444-
FROM #index_details AS id2_uc
17445-
WHERE id2_uc.index_hash = ia2.index_hash
17446-
AND id2_uc.is_unique_constraint = 1
17447-
)
17448-
THEN 'YES'
17449-
ELSE 'NO'
17450-
END
17451-
FROM #index_analysis AS ia1
17452-
JOIN #index_analysis AS ia2
17453-
ON ia1.scope_hash = ia2.scope_hash
17454-
AND ia1.index_name <> ia2.index_name
17455-
AND ia2.key_columns LIKE (REPLACE(REPLACE(REPLACE(ia1.key_columns, '~', '~~'), '[', '~['), ']', '~]') + N', %') ESCAPE '~'
17456-
AND ISNULL(ia1.filter_definition, '') = ISNULL(ia2.filter_definition, '')
17457-
AND NOT (ia1.is_unique = 1 AND ia2.is_unique = 0)
17458-
WHERE ia1.consolidation_rule IS NULL
17459-
AND ia2.consolidation_rule IS NULL
17460-
AND NOT EXISTS
17461-
(
17462-
SELECT 1/0
17463-
FROM #index_details AS id1_uc
17464-
WHERE id1_uc.index_hash = ia1.index_hash
17465-
AND id1_uc.is_unique_constraint = 1
17466-
)
17467-
AND NOT EXISTS
17468-
(
17469-
SELECT 1/0
17470-
FROM #index_details AS id2_uc
17471-
WHERE id2_uc.index_hash = ia2.index_hash
17472-
AND id2_uc.is_unique_constraint = 1
17473-
)
17474-
AND EXISTS
17475-
(
17476-
SELECT 1/0
17477-
FROM #index_details AS id1
17478-
WHERE id1.index_hash = ia1.index_hash
17479-
AND id1.is_eligible_for_dedupe = 1
17480-
)
17481-
AND EXISTS
17482-
(
17483-
SELECT 1/0
17484-
FROM #index_details AS id2
17485-
WHERE id2.index_hash = ia2.index_hash
17486-
AND id2.is_eligible_for_dedupe = 1
17487-
)
17488-
AND NOT EXISTS
17489-
(
17490-
SELECT 1/0
17491-
FROM #index_details AS id1
17492-
JOIN #index_details AS id2
17493-
ON id2.column_position_hash = id1.column_position_hash
17494-
WHERE id1.index_hash = ia1.index_hash
17495-
AND id2.index_hash = ia2.index_hash
17496-
AND id1.is_descending_key <> id2.is_descending_key
17497-
)
17498-
AND (ia1.index_name LIKE N'IX_Users_%Subset%' AND ia2.index_name LIKE N'IX_Users_%Superset%')
17499-
ORDER BY
17500-
ia1.index_name,
17501-
ia2.index_name
17502-
OPTION(RECOMPILE);
1750317337
END;
1750417338

1750517339
UPDATE
@@ -17609,27 +17443,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1760917443
ia.*
1761017444
FROM #index_analysis AS ia
1761117445
OPTION(RECOMPILE);
17612-
17613-
/* Special debug for subset/superset test indexes */
17614-
RAISERROR('Special debug for #index_details subset/superset eligibility:', 0, 0) WITH NOWAIT;
17615-
SELECT
17616-
index_id = id.index_id,
17617-
index_name = id.index_name,
17618-
column_name = id.column_name,
17619-
key_ordinal = id.key_ordinal,
17620-
is_descending_key = id.is_descending_key,
17621-
is_included_column = id.is_included_column,
17622-
is_eligible_for_dedupe = id.is_eligible_for_dedupe,
17623-
is_unique_constraint = id.is_unique_constraint,
17624-
is_primary_key = id.is_primary_key
17625-
FROM #index_details AS id
17626-
WHERE id.index_name LIKE N'IX_Users_%Subset%'
17627-
OR id.index_name LIKE N'IX_Users_%Superset%'
17628-
ORDER BY
17629-
id.index_id,
17630-
id.key_ordinal,
17631-
id.column_name
17632-
OPTION(RECOMPILE);
1763317446
END;
1763417447

1763517448
/* Rule 4: Mark superset indexes for merging with includes from subset */
@@ -17666,73 +17479,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1766617479
END;
1766717480

1766817481
/* Rule 5: Key duplicates - matching key columns, different includes */
17669-
IF @debug = 1
17670-
BEGIN
17671-
RAISERROR('Rule 5 debug - Testing key duplicates with different includes:', 0, 0) WITH NOWAIT;
17672-
SELECT
17673-
index1 = ia1.index_name,
17674-
index1_keys = ia1.key_columns,
17675-
index1_includes = ia1.included_columns,
17676-
index2 = ia2.index_name,
17677-
index2_keys = ia2.key_columns,
17678-
index2_includes = ia2.included_columns,
17679-
key_filter_match =
17680-
CASE
17681-
WHEN ia1.key_filter_hash = ia2.key_filter_hash
17682-
THEN 'YES'
17683-
ELSE 'NO'
17684-
END,
17685-
includes_different =
17686-
CASE
17687-
WHEN ISNULL(ia1.included_columns, '') <> ISNULL(ia2.included_columns, '')
17688-
THEN 'YES'
17689-
ELSE 'NO'
17690-
END,
17691-
ia1_consolidation_rule = ISNULL(ia1.consolidation_rule, 'NULL'),
17692-
ia2_consolidation_rule = ISNULL(ia2.consolidation_rule, 'NULL')
17693-
FROM #index_analysis AS ia1
17694-
JOIN #index_analysis AS ia2
17695-
ON ia1.scope_hash = ia2.scope_hash
17696-
AND ia1.index_name <> ia2.index_name
17697-
AND ia1.key_filter_hash = ia2.key_filter_hash
17698-
AND ISNULL(ia1.included_columns, '') <> ISNULL(ia2.included_columns, '')
17699-
WHERE ia1.consolidation_rule IS NULL
17700-
AND ia2.consolidation_rule IS NULL
17701-
AND NOT EXISTS
17702-
(
17703-
SELECT 1/0
17704-
FROM #index_details AS id1_uc
17705-
WHERE id1_uc.index_hash = ia1.index_hash
17706-
AND id1_uc.is_unique_constraint = 1
17707-
)
17708-
AND NOT EXISTS
17709-
(
17710-
SELECT 1/0
17711-
FROM #index_details AS id2_uc
17712-
WHERE id2_uc.index_hash = ia2.index_hash
17713-
AND id2_uc.is_unique_constraint = 1
17714-
)
17715-
AND EXISTS
17716-
(
17717-
SELECT 1/0
17718-
FROM #index_details AS id1
17719-
WHERE id1.index_hash = ia1.index_hash
17720-
AND id1.is_eligible_for_dedupe = 1
17721-
)
17722-
AND EXISTS
17723-
(
17724-
SELECT 1/0
17725-
FROM #index_details AS id2
17726-
WHERE id2.index_hash = ia2.index_hash
17727-
AND id2.is_eligible_for_dedupe = 1
17728-
)
17729-
AND (ia1.index_name LIKE N'%DownVotes%' OR ia1.index_name LIKE N'%LastAccess%')
17730-
ORDER BY
17731-
ia1.index_name,
17732-
ia2.index_name
17733-
OPTION(RECOMPILE);
17734-
END;
17735-
1773617482
UPDATE
1773717483
ia1
1773817484
SET
@@ -18080,7 +17826,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1808017826
AND NOT EXISTS
1808117827
(
1808217828
/* Check if there's a unique constraint with matching keys that points to this index */
18083-
SELECT 1
17829+
SELECT
17830+
1/0
1808417831
FROM #index_analysis AS ia_uc
1808517832
WHERE ia_uc.scope_hash = ia.scope_hash
1808617833
AND ia_uc.key_columns = ia.key_columns

sp_IndexCleanup/sp_IndexCleanup.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3576,7 +3576,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35763576
AND NOT EXISTS
35773577
(
35783578
/* Check if there's a unique constraint with matching keys that points to this index */
3579-
SELECT
3579+
SELECT
35803580
1/0
35813581
FROM #index_analysis AS ia_uc
35823582
WHERE ia_uc.scope_hash = ia.scope_hash

0 commit comments

Comments
 (0)