filter indexs
筛选索引--filter indexs 筛选索引是一种经过优化的非聚集索引,尤其适用于涵盖从定义完善的数据子集中选择数据的查询。筛选索引使用筛选谓词对表中的部分行进行索引。 一:筛选索引与全表索引相比具有以下 优点 : 1.提高了查询性能和计划质量 设计良好的筛
筛选索引--filter indexs
筛选索引是一种经过优化的非聚集索引,尤其适用于涵盖从定义完善的数据子集中选择数据的查询。筛选索引使用筛选谓词对表中的部分行进行索引。
一:筛选索引与全表索引相比具有以下优点:
1.提高了查询性能和计划质量
设计良好的筛选索引可以提高查询性能和执行计划质量,因为它比全表非聚集索引小并且具有经过筛选的统计信息。与全表统计信息相比,经过筛选的统计信息更加准确,因为它们只涵盖筛选索引中的行。
2.减少了索引维护开销
仅在数据操作语言 (DML)
语句对索引中的数据产生影响时,才对索引进行维护。与全表非聚集索引相比,筛选索引减少了索引维护开销,因为它更小并且仅在对索引中的数据产生影响时才进行维护。筛选索引的数量可以非常多,特别是在其中包含很少受影响的数据时。同样,如果筛选索引只包含频繁受影响的数据,则索引大小较小时可以减少更新统计信息的开销。
3.减少了索引存储开销
在没必要创建全表索引时,创建筛选索引可以减少非聚集索引的磁盘存储开销。可以使用多个筛选索引替换一个全表非聚集索引而不会明显增加存储需要。
4.设计注意事项
为了设计有效的筛选索引,必须了解应用程序使用哪些查询以及这些查询与您的数据子集有何关联。例如,所含值中大部分为 NULL
的列、含异类类别的值的列以及含不同范围的值的列都属于具有定义完善的子集的数据。以下设计注意事项提供了筛选索引优于全表索引的各种情况。
5.数据子集的筛选索引
在列中只有少量相关值需要查询时,可以针对值的子集创建筛选索引。例如,当列中的值大部分为 NULL 并且查询只从非 NULL
值中进行选择时,可以为非 NULL 数据行创建筛选索引。由此得到的索引与对相同键列定义的全表非聚集索引相比,前者更小且维护开销更低。
eg1:例如,AdventureWorks 数据库中有一个包含 2679 行的 Production.BillOfMaterials 表。EndDate 列只有 199 行包含非 NULL 值,其余 2480 行均包含 NULL。下面的筛选索引将涵盖这样的查询:返回在此索引中定义的列的查询,以及只选择 EndDate 值不为 NULL 的行的查询。
USE AdventureWorks;
GO
IF EXISTS (SELECT name FROM
sys.indexes
WHERE name =
N'FIBillOfMaterialsWithEndDate'
AND object_id =
OBJECT_ID (N'Production.BillOfMaterials'))
DROP INDEX
FIBillOfMaterialsWithEndDate
ON
Production.BillOfMaterials
GO
CREATE NONCLUSTERED INDEX
FIBillOfMaterialsWithEndDate
ON
Production.BillOfMaterials (ComponentID, StartDate)
WHERE EndDate IS NOT
NULL;
GO
筛选索引 FIBillOfMaterialsWithEndDate
对下面的查询有效。您可以显示查询执行计划,以确定查询优化器是否使用了此筛选索引。有关如何显示查询执行计划的信息,请参阅分析查询。
SELECT ProductAssemblyID, ComponentID, StartDate
FROM
Production.BillOfMaterials
WHERE EndDate IS NOT
NULL;
GO有关如何创建筛选索引以及如何定义筛选索引谓词表达式的详细信息,请参阅 CREATE INDEX (Transact-SQL)。
6.异类数据的筛选索引
表中含有异类数据行时,可以为一种或多种类别的数据创建筛选索引。
eg2:例如,香港虚拟主机,Production.Product 表中列出的每种产品均分配到一个 ProductSubcategoryID,后者又与 Bikes、Components、Clothing 或 Accessories 产品类别关联。这些类别为异类类别,因为它们在 Production.Product 表中的列值并不是紧密相关的。例如,对于每种产品类别,Color、ReorderPoint、ListPrice、Weight、Class 和 Style. 均具有唯一特征。假设会经常查询具有子类别 27-36 的 Accessories。通过对 Accessories 子类别创建筛选索引,可以提高对 Accessories 的查询的性能。
下面的示例对 Production.Product 表中 Accessories 子类别中的所有产品创建一个筛选索引。
USE AdventureWorks;
GO
IF EXISTS (SELECT name FROM
sys.indexes
WHERE name =
N'FIProductAccessories'
AND object_id = OBJECT_ID
('Production.Product'))
DROP INDEX FIProductAccessories
ON Production.Product;
GO
CREATE NONCLUSTERED INDEX
FIProductAccessories
ON Production.Product (Name,
ListPrice)
WHERE ProductSubcategoryID >= 27 AND ProductSubcategoryID GO
筛选索引 FIProductAccessories 对下面的查询有效,因为查询谓词等效于筛选索引表达式。
SELECT Name, ListPrice
FROM Production.Product
WHERE
ProductSubcategoryID BETWEEN 27 AND
36;
GO
7.视图与筛选索引
视图是存储查询定义的虚拟表;与筛选索引相比,其用途更广,功能更强。有关视图的详细信息,请参阅了解视图和使用视图的情况。下表比较了在视图和筛选索引中可以使用的部分功能。
在表达式中允许 视图 筛选的索引
计算列 是 否
联接 是 否
多个表 是 否
谓词中的简单比较逻辑 是 是

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics


![How to solve the '[Vue warn]: Failed to resolve filter' error](https://img.php.cn/upload/article/000/887/227/169243040583797.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
Methods to solve the "[Vuewarn]:Failedtoresolvefilter" error During the development process using Vue, we sometimes encounter an error message: "[Vuewarn]:Failedtoresolvefilter". This error message usually occurs when we use an undefined filter in the template. This article explains how to resolve this error and gives corresponding code examples. When we are in Vue

1. Filter First look at the location of the filter of the web server. Filter is a chain connected before and after. After the previous processing is completed, it is passed to the next filter for processing. 1.1Filter interface definition publicinterfaceFilter{//Initialization method, only executed once in the entire life cycle. //Filtering services cannot be provided until the init method is successfully executed (failure such as throwing an exception, etc.). //The parameter FilterConfig is used to obtain the initialization parameter publicvoidinit(FilterConfigfilterConfig)throwsServletException;//

Note 1. If the Lambda parameter generates a true value, the filter (Lambda that can generate a boolean result) will generate an element; 2. When false is generated, this element will no longer be used. Example to create a List collection: ListstringCollection=newArrayList();stringCollection.add("ddd2");stringCollection.add("aaa2");stringCollection.add("bbb1");stringC

Analysis of CSS visual properties: box-shadow, text-shadow and filter Introduction: In web design and development, CSS can be used to add various visual effects to elements. This article will focus on the three important properties of box-shadow, text-shadow and filter in CSS, including their usage and effect display. Below we analyze these three properties in detail. 1. box-shadow (box shadow) box-shado

First define a Filter for unified access URL interception. The code is as follows: publicclassUrlFilterimplementsFilter{privateLoggerlog=LoggerFactory.getLogger(UrlFilter.class);@OverridepublicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainchain)throwsIOException,ServletException{H

Detailed explanation of CSS fuzzy attributes: filter and background-filter Introduction: When designing web pages, we often need some special effects to increase the visual appeal of the page. The blur effect is one of the common special effects. CSS provides two blur attributes: filter and background-filter, which are used to blur element content and background content respectively. This article explains these two properties in detail and provides some concrete code examples. 1. filter

Optional class in Java8: How to use the filter() method to filter possibly null values In Java8, the Optional class is a very useful tool that allows us to better handle possibly null values and avoid the occurrence of NullPointerException. The Optional class provides many methods to manipulate potential null values, one of the important methods is filter(). The function of the filter() method is that if Option

Use filters to format and process data in Vue In Vue, we can format and process data by using filters. Filter is a function that can be called directly in the template. It can process the data to be displayed and return the processed results. In this article, we will introduce how to use filters to format and process data, and provide specific code examples. Register filter In the Vue instance, we need to register a filter first so that it can be used in the model
