Pet*_*ier 4 metadata database-internals sql-server-2012 filtered-index
给定一个表格...
create table dbo.FilterIDXTest (
id int not null identity primary key clustered,
_bigint bigint,
_varchar10 varchar(10),
_varchar20 varchar(20),
_guid uniqueidentifier
);
go
create unique index uq_FilterIDXTest
on dbo.FilterIDXTest ( _varchar10, _varchar20 )
include ( _guid )
where _bigint is not null
and id > 5;
go
Run Code Online (Sandbox Code Playgroud)
...在什么(如果有)目录视图(或其他格式良好的参考对象)中可以WHERE定位和严格识别子句中的列名称?
sys.indexes可以查看提醒我们的filter_definition是([_bigint] IS NOT NULL AND [id]>(5))。
sys.index_columns可以查看ON和INCLUDE列,但仅列出原始CREATE INDEX命令中的 5 列中的 3 列。filter_predicate此处未找到这些列。
我必须假设filter_predicate在某个阶段对依赖项进行了严格检查,因为sp_rename 'dbo.FilterIDXTest._bigint', 'foo_bigint', 'column'失败并出现错误...
Caution: Changing any part of an object name could break scripts and stored procedures.
Msg 5074, Level 16, State 1, Procedure sp_rename, Line 611
The index 'uq_FilterIDXTest' is dependent on column '_bigint'.
Msg 4922, Level 16, State 9, Procedure sp_rename, Line 611
RENAME COLUMN _bigint failed because one or more objects access this column.
Run Code Online (Sandbox Code Playgroud)
...而且我无法让自己相信失败的唯一原因是因为sys.indexes.filter_definition.
作为参考,手头的任务是从许多未记录的遗留服务器中提取源代码。我为此目的使用 RedGate/其他一些付费帮助应用程序的请求已被拒绝,因为“您可以从 UI 中编写对象脚本,对吗? ”。也许我过于严谨了,但我希望有很高的信心,我正在检查源代码控制的索引是实际存在的索引。我正在sql server 2012上测试此脚本,但最终将在其上执行的目标服务器范围从2005 SP1到2008 R2 SP3。
我认为这些信息存储在sys.sql_expression_dependencies. 见MSDN中的表格,sys.sql_expression_dependencies:
本主题适用于:
是:SQL Server(从 2008 年开始)
否:Azure SQL 数据库
是:Azure SQL 数据仓库
是:并行数据仓库评论
下表列出了为其创建和维护相关性信息的实体类型。不会为规则、默认值、临时表、临时存储过程或系统对象创建或维护相关性信息。
Entity type Referencing entity Referenced entity
Table Yes* Yes
View Yes Yes
Filtered index Yes** No
Filtered statistics Yes** No
...
Run Code Online (Sandbox Code Playgroud)
**过滤谓词中使用的每一列都作为引用实体进行跟踪。
另请注意,过滤索引是在 2008 版中作为一项功能添加的,而该系统视图在 2005 年不存在(感谢@Michael Eriksson 注意到这一点)。
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |