如何在 Azure Synapse 专用 SQL 池中查找分区的范围值

How to find the range values for a partition in Azure Synapse dedicated SQL pool

我在 Azure Synapse 专用 SQL 池中有一个 dbo.Test_Partitioned table,它在 TEST_SEQ 列上进行范围右分区。

我正在尝试为未来的数据自动化分区创建过程。如果最后一个分区超过 2 亿条记录,我们将其拆分。为此,我计划使用 CTAS 创建一个新的 table 来保存数据(清空分区),然后拆分,最后将数据切换回来。

我能够找到最后一个分区号,但是有没有办法找到使用查询创建最后一个分区的范围值。我需要在之前的范围拆分值上添加一个间隔值来进行拆分。

提前致谢。

进一步研究,我得到了结果。

SELECT 
t.name AS TableName, 
i.name AS IndexName, 
p.partition_number,
p.partition_id,
f.type_desc,
c.name AS PartitioningColumnName,
CONVERT(nvarchar(255), r.value) as boundary
FROM sys.tables AS t
JOIN sys.indexes AS i
    ON t.object_id = i.object_id
JOIN sys.partitions AS p
    ON i.object_id = p.object_id AND i.index_id = p.index_id
JOIN  sys.partition_schemes AS s
    ON i.data_space_id = s.data_space_id
JOIN sys.partition_functions AS f
    ON s.function_id = f.function_id
LEFT JOIN sys.partition_range_values AS r
    ON f.function_id = r.function_id and r.boundary_id = p.partition_number
JOIN sys.index_columns AS ic
    ON ic.object_id = i.object_id
    AND ic.index_id = i.index_id AND ic.partition_ordinal > 0
JOIN sys.columns AS c
    ON t.object_id = c.object_id
WHERE t.name = @table
    AND c.column_id = ic.column_id
ORDER BY p.partition_number;