SqlScriptDOM icon indicating copy to clipboard operation
SqlScriptDOM copied to clipboard

ScriptDom does not fill Clustered property even if it was explicitly provided on HASH index

Open IVNSTN opened this issue 11 months ago • 0 comments

ScriptDom version: 161.8919.0 Compatibility level used for parsing: 150

Parser did not fill Clustered property and because it is a PRIMARY KEY which are CLUSTERED by default unless explicitly defined as NONCLUSTERED, I resolved this case in my code as implicitly clustered. However it is clearly explicitly NONCLUSTERED. I think Clustered property should be false in this case.

CREATE TABLE dbo.foo
(
    bar VARCHAR(512)   NOT NULL
    , far VARCHAR(20)    NULL
    , CONSTRAINT PK PRIMARY KEY NONCLUSTERED HASH (bar) WITH (BUCKET_COUNT = 500000)
    , INDEX IX_2 NONCLUSTERED HASH (far)
          WITH (BUCKET_COUNT = 500000)
)
WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA);
GO

Here are object properties for PK node: image

So to check if index is clustered with respect to property nullability one has to do something like that:

bool isClustered;
if (node.Clustered.HasValue)
{
    isClustered = node.Clustered.Value;
}
else if (node.IndexType != null && node.IndexType.IndexTypeKind.HasValue)
{
    isClustered = node.IndexType.IndexTypeKind.Value == IndexTypeKind.Clustered
        || node.IndexType.IndexTypeKind.Value == IndexTypeKind.ClusteredColumnStore;
}
else
{
    isClustered = node.IsPrimaryKey;
}

feels like it could be more straightforward

IVNSTN avatar Mar 04 '24 12:03 IVNSTN