zoukankan      html  css  js  c++  java
  • SqlServer中的(分区)表文件组

    获取一个表的文件组信息,有如下脚本:

    SELECT OBJECT_SCHEMA_NAME(t.object_id) AS schema_name
    ,t.name AS table_name
    ,i.index_id
    ,i.name AS index_name
    ,ds.name AS filegroup_name
    ,FORMAT(p.rows, '#,###') AS rows
    FROM sys.tables t
    INNER JOIN sys.indexes i ON t.object_id=i.object_id
    INNER JOIN sys.filegroups ds ON i.data_space_id=ds.data_space_id
    INNER JOIN sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id
    ORDER BY t.name, i.index_id

    但红框圈出的表是做过表分区的,获取的文件组信息是错误的,应考虑表分区问题,用如下脚本获取表文件组:

    SELECT OBJECT_SCHEMA_NAME(t.object_id) AS schema_name
    ,t.name AS table_name
    ,i.index_id
    ,i.name AS index_name
    ,p.partition_number
    ,fg.name AS filegroup_name
    ,FORMAT(p.rows, '#,###') AS rows
    FROM sys.tables t
    INNER JOIN sys.indexes i ON t.object_id = i.object_id
    INNER JOIN sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id
    LEFT OUTER JOIN sys.partition_schemes ps ON i.data_space_id=ps.data_space_id
    LEFT OUTER JOIN sys.destination_data_spaces dds ON ps.data_space_id=dds.partition_scheme_id AND p.partition_number=dds.destination_id
    INNER JOIN sys.filegroups fg ON COALESCE(dds.data_space_id, i.data_space_id)=fg.data_space_id

     这样,获取的文件组才是正确的。学习自:https://jasonstrate.com/2013/01/29/determining-file-group-for-a-table/,摘其最重要的一条信息:

      简言之,“分区索引不再决定数据的位置,而是由分区方案决定”。

  • 相关阅读:
    PS_0005:画带颜色在线条框 按住Alt键复制
    零钱兑换(动态规划)
    倒排索引原理和实现
    集群搭建
    java内部类
    nohup &后台运行脚本
    scala构造函数
    spark数据源读取及读数据原理
    安装redis解决公司linux环境的坑
    61、对于employees表中,给出奇数行的first_name
  • 原文地址:https://www.cnblogs.com/seanyan/p/14821163.html
Copyright © 2011-2022 走看看