如何在 Azure Synapse 中查找哈希分布中使用的列?
How do I find the column used in a HASH DISTRIBUTION within Azure Synapse?
除了 HASH 分布中使用的列之外,此查询提供了我需要的一切:
select * from sys.pdw_table_distribution_properties
我需要 table 加入才能获得吗?
我们必须使用JOIN
操作来获取HASH分布中的列。
对于我们使用的列:sys.pdw_column_distribution_properties
您必须参考此 doc 作为 JOIN 的参考。
您必须在sys.pdw_table_distribution_properties
中将分布指定为HASH,并将distribution_ordinal
设置为> 0
(大概是为multi-column HASH 表铺路)。这样的事情应该有效:
SELECT
OBJECT_SCHEMA_NAME(tdp.object_id) schemaName,
OBJECT_NAME(tdp.object_id) tableName,
c.name AS hashDistributionColumnName,
cdp.distribution_ordinal
FROM sys.pdw_table_distribution_properties tdp
INNER JOIN sys.pdw_column_distribution_properties cdp ON tdp.object_id = cdp.object_id
INNER JOIN sys.columns c ON cdp.object_id = c.object_id
AND cdp.column_id = c.column_id
WHERE tdp.distribution_policy_desc = 'HASH'
AND cdp.distribution_ordinal > 0;
使用它还可以查看散列以外的其他分布类型。
SELECT OBJECT_SCHEMA_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID) AS [SCHEMA],
OBJECT_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID) AS [TABLE],
DISTRIBUTION_COLUMN.DISTRIBUTION_ORDINAL AS [DISTRIBUTION_ORDINAL],
PDW_TABLE_DISTRIBUTION_PROPERTIES.DISTRIBUTION_POLICY_DESC AS [DISTRIBUTION_POLICY],
DISTRIBUTION_COLUMN.[COLUMN]
FROM SYS.PDW_TABLE_DISTRIBUTION_PROPERTIES
LEFT OUTER JOIN (
SELECT PDW_COLUMN_DISTRIBUTION_PROPERTIES.OBJECT_ID AS [OBJECT_ID],
PDW_COLUMN_DISTRIBUTION_PROPERTIES.DISTRIBUTION_ORDINAL AS [DISTRIBUTION_ORDINAL],
COLUMNS.NAME AS [COLUMN]
FROM SYS.PDW_COLUMN_DISTRIBUTION_PROPERTIES
INNER JOIN SYS.COLUMNS
ON COLUMNS.OBJECT_ID = PDW_COLUMN_DISTRIBUTION_PROPERTIES.OBJECT_ID
AND COLUMNS.COLUMN_ID = PDW_COLUMN_DISTRIBUTION_PROPERTIES.COLUMN_ID
WHERE DISTRIBUTION_ORDINAL > 0 ) AS DISTRIBUTION_COLUMN
ON DISTRIBUTION_COLUMN.OBJECT_ID = PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID
ORDER BY OBJECT_SCHEMA_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID),
OBJECT_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID),
DISTRIBUTION_COLUMN.DISTRIBUTION_ORDINAL
除了 HASH 分布中使用的列之外,此查询提供了我需要的一切:
select * from sys.pdw_table_distribution_properties
我需要 table 加入才能获得吗?
我们必须使用JOIN
操作来获取HASH分布中的列。
对于我们使用的列:sys.pdw_column_distribution_properties
您必须参考此 doc 作为 JOIN 的参考。
您必须在sys.pdw_table_distribution_properties
中将分布指定为HASH,并将distribution_ordinal
设置为> 0
(大概是为multi-column HASH 表铺路)。这样的事情应该有效:
SELECT
OBJECT_SCHEMA_NAME(tdp.object_id) schemaName,
OBJECT_NAME(tdp.object_id) tableName,
c.name AS hashDistributionColumnName,
cdp.distribution_ordinal
FROM sys.pdw_table_distribution_properties tdp
INNER JOIN sys.pdw_column_distribution_properties cdp ON tdp.object_id = cdp.object_id
INNER JOIN sys.columns c ON cdp.object_id = c.object_id
AND cdp.column_id = c.column_id
WHERE tdp.distribution_policy_desc = 'HASH'
AND cdp.distribution_ordinal > 0;
使用它还可以查看散列以外的其他分布类型。
SELECT OBJECT_SCHEMA_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID) AS [SCHEMA],
OBJECT_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID) AS [TABLE],
DISTRIBUTION_COLUMN.DISTRIBUTION_ORDINAL AS [DISTRIBUTION_ORDINAL],
PDW_TABLE_DISTRIBUTION_PROPERTIES.DISTRIBUTION_POLICY_DESC AS [DISTRIBUTION_POLICY],
DISTRIBUTION_COLUMN.[COLUMN]
FROM SYS.PDW_TABLE_DISTRIBUTION_PROPERTIES
LEFT OUTER JOIN (
SELECT PDW_COLUMN_DISTRIBUTION_PROPERTIES.OBJECT_ID AS [OBJECT_ID],
PDW_COLUMN_DISTRIBUTION_PROPERTIES.DISTRIBUTION_ORDINAL AS [DISTRIBUTION_ORDINAL],
COLUMNS.NAME AS [COLUMN]
FROM SYS.PDW_COLUMN_DISTRIBUTION_PROPERTIES
INNER JOIN SYS.COLUMNS
ON COLUMNS.OBJECT_ID = PDW_COLUMN_DISTRIBUTION_PROPERTIES.OBJECT_ID
AND COLUMNS.COLUMN_ID = PDW_COLUMN_DISTRIBUTION_PROPERTIES.COLUMN_ID
WHERE DISTRIBUTION_ORDINAL > 0 ) AS DISTRIBUTION_COLUMN
ON DISTRIBUTION_COLUMN.OBJECT_ID = PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID
ORDER BY OBJECT_SCHEMA_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID),
OBJECT_NAME(PDW_TABLE_DISTRIBUTION_PROPERTIES.OBJECT_ID),
DISTRIBUTION_COLUMN.DISTRIBUTION_ORDINAL