Adding support for indexed views in addition to indexes on tables.#610
Conversation
|
@FirstCall42 thanks for this. There are quite a few notable changes in here, specifically to a lot of the joins. How much testing have you done with the changes? My primary concerns are probably stuff like:
These change is of particular interest: I'm not in love with the Thanks! |
|
Hi Erik, Here is the testing I have done. Against some test and production databases. SQL 2019 Enterprise. However, I expected to get some comments about the style and the joins. Would you prefer an alternative like this? If so, I can make a new commit with the changes. SELECT DISTINCT
-- @database_id,
-- database_name = DB_NAME(@database_id),
schema_id = s.schema_id,
schema_name = s.name,
object_id = i.object_id,
table_name = x.name,
index_id = i.index_id,
index_name = ISNULL(i.name, x.name + N'.Heap'),
can_compress =
CASE
WHEN p.index_id > 0
AND p.data_compression = 0
THEN 1
ELSE 0
END
FROM sys.indexes AS i
LEFT JOIN sys.tables AS t
ON i.object_id = t.object_id
AND t.is_ms_shipped = 0 AND t.type <> N'TF'
LEFT JOIN sys.views AS v
ON i.object_id = v.object_id
CROSS APPLY (
SELECT t.schema_id, t.name WHERE t.schema_id IS NOT NULL
UNION ALL
SELECT v.schema_id, v.name WHERE v.schema_id IS NOT NULL
) AS x
JOIN sys.schemas AS s
ON x.schema_id = s.schema_id
JOIN sys.partitions AS p
ON i.object_id = p.object_id
AND i.index_id = p.index_id
LEFT JOIN sys.dm_db_index_usage_stats AS us
ON i.object_id = us.object_id
WHERE i.is_disabled = 0
AND i.is_hypothetical = 0 |
|
@FirstCall42 Eh, I'll tweak things if they start causing issues, but I appreciate the offer. Thanks for taking care of this. It'll show in the next release at the beginning of June. |
Adding support for indexed views. As discussed we will use table_name for results column and the filter (if used).
Tested using the following.
resolves #569