Before the original post, I had submitted a connect item for something similar.
It turns out that filtered indexes may not be used when auto-parameterization(or for stored proc) occurs without a recompile hint. This is sort of understandable but I can think of workarounds and I suspect additional logic will be added in the future as mentioned below. Here is the feedback from a connect item I submitted.
"
Thanks for your feedback. The query in question, select lastname from Person.Contact where ContactID <=(100-20) is auto-parameterized by SQL Server into the following form, using the standard auto-parameterization rules: select lastname from Person.Contact where ContactID <=(@1-@2) These rules are designed to minimize compile time cost for simple queries like this, possibly at the expense of additional optimizations such as using a filtered index. Admittedly, it is a difficult tradeoff. In a future release, we'll consider extending the design to make a better decision in a cost-based way. For now, this behavior is by design.
alt head: You can't have your cake and eat it too.
We regret to inform you of a passing in the SQL community. Read more here.
Rick Heiges has a post on my favorite new feature in SQL Server 2008, filtered indexes.
So does Decipherinfosys along with a good description on the difference of indexes and statistics if you need some background.
SQLBlogcasts has gotten an upgrade and Tony posts some great stats. Congrats!
Not SQL per say but the Hyper-V release candidate has been released. Speaking of Hyper-V, Sriram posts his slide decks on virtualizing SQL. Part 1 and Part 2.
This is a great starting point for SQL Server 2008 as is this. These come by way of the MSDN\Technet update blog.
The SQL Server 2005 sp3 debate continues.
The SQL ISV team posts a performance improving cursor rewrite sample. However, it is not ANSI compliant :) which is odd since most ISV tsql code needs to be portable.
Paul Nielson will be releasing a DVD.
While we are at it, check out the new SQL Server social network.
alt head: Got ADD?
Technorati Tags: SQL Server,SQL Server 2008,SQL Server 2005,SQL Server 2000,tsql,cursors,virtualization,filtered indexes,social networking
So I was messing around with filtered indexes tonight. Yes, beta software is my idea of a wild Saturday night. Hey, I played some Smash Bros first. ;) I was trying to figure out what happens if a plan is created using a covering but filtered index and try to reuse it with a parameter that is covered vertically but not horizontally. Let's look at this example:
create database dbtest01;
--Force parameterization
alter database dbtest01 set parameterization forced;
use dbtest01
--create test table 1
create table t1
(id int identity(1,1),
c1 int,
c2 int)
--insert dummy data
declare @ctr int = 2000000
while @ctr > 0
begin
insert into t1(c1, c2) values (@ctr, @ctr)
select @ctr=@ctr-1
end
--create clustered indexes
create clustered index CI on t1(id)
--Let create a covering indexes that is pretty extreme.
create index ix01 on t1(c1) where c1 = 1990001
--Test queries
--ctrl + m
dbcc freeproccache
set statistics io on
--Does a CI scan.
select c1 from t1
where c1 = 1990001
--Nope, index hints returns an error
--Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query without specifying any hints and without using SET FORCEPLAN.
select c1 from t1 with (index=ix01)
--Ahh, recompile works. Now it uses the filtered index
option(recompile)
--What about simple parameterization and a stored proc?
alter database dbtest01 set parameterization simple;
create proc proc1
@p1 int
as
where c1 = @p1
--It does the CI scan
exec proc1 1990001
alter proc proc1
--It uses the filtered index :)
My jaw literally dropped when I saw it. If this works as advertised, it has the potential of changing everything. The days of over indexing will be over. Dynamic indexing off of the missing and unused index DMV's could be possible especially with added support. I also think this will better accomplish what people tried to do with partitioning for performance reasons in SQL Server 2005.
It will be really interesting to see how it gets applied in production and where this leads in the next versions. Maybe an autoindex checkbox will replace the DBA :)
This is a small and quick example. We will have to see how it scales to larger environments.
use adventureworks
--Let's nullify a random 400
update Production.WorkOrder
set EndDate = null
where WorkOrderID in (select top 400 WorkOrderID from Production.WorkOrder where enddate is not null)
--Let's give a random 200 a recent date to mimic prod data
update top (200) Production.WorkOrder
set duedate = getdate()-10
where enddate is null
--Base query --This is query type that should be simple yet common --Let's get open WO's that will be due soon
select p.Name, wo.OrderQty, wo.DueDate
from Production.WorkOrder wo JOIN Production.Product p on wo.ProductID=p.ProductID
where wo.EndDate is null and wo.DueDate >= '2007-11-24'
--CI Scan with loop join
--Table 'WorkOrder'. Scan count 1, logical reads 530, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.--Now let's create a covering index
create index ix01 on Production.WorkOrder(EndDate,DueDate, ProductID) include (OrderQty)
--Run the base query
set statistics io on select p.Name, wo.OrderQty, wo.DueDate from Production.WorkOrder wo JOIN Production.Product p on wo.ProductID=p.ProductID where wo.EndDate is null and wo.DueDate >= '2007-11-24'
--Does NCI seek
--Table 'WorkOrder'. Scan count 1, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
--Clean up
drop index [Production].[WorkOrder].[ix01]
--Create Filter index
create index ix01 on Production.WorkOrder(EndDate,DueDate, ProductID) include (OrderQty) where EndDate is null and DueDate >= '2007-11-24'
--Run base query
set statistics io on select p.Name, wo.OrderQty, wo.DueDate
--It uses it. We have a real small sample but it performs better
--Table 'WorkOrder'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. --Now let's look at size --Create unfiltered index for comparison
create index ix02 on Production.WorkOrder(EndDate,DueDate, ProductID) include (OrderQty)
--note the new syntax
declare @dbid int = db_id()
declare @objid int = object_id('[Production].[WorkOrder]')
select * from sys.dm_db_index_physical_stats(@dbid, @objid, null, null, 'detailed') ps join sys.indexes i
on ps.object_id=i.object_id and ps.index_id=i.index_id
and i.name in ('ix01', 'ix02') and i.type_desc='NONCLUSTERED'
--We are looking at 2 page vs. 301 pages
That is a huge difference in size. The major point is not the fact that we retrieve the same while taking up so much less space on disk but so much less space in memory as well. We are going to get into this much more!
Technorati Tags: SQL Server 2008,Filtered indexes,CTP6
The big news of the week is the release of CTP6. There millions of posts about it but let me point you to some interesting ones. Dennis Gobo points out the new DMV's. SSQA reports on the features that have been removed like SSNS. Personally, I think the highlight of the CTP is filtered indexes. I will be posting a blog about them this weekend.
Aaron points out that cumulative update 6 for SQL Server 2005 sp2 is available.
Uhoh, SQL Server driver for PHP CTP has been released. Get your LASP on. Haha. Joking aside. I went to a Windows 2008 event this week and MS is gunning for Apache. Hopefully, SQL powered PHP apps are better to support than SQL powered Java apps.
How nerdy are you? If you answered, very. Hop on over to the Second Life Technet event this Saturday. Details here.
Laurentiu Cristofor posts a FAQ on SQL Server password policies. He has some good info on his blog. Check it out.
Not new but relevant to DBA's, check out this Windows 2008 performance white paper.
http://download.microsoft.com/download/3/1/5/315b8683-3765-4426-96ec-179360abb82f/Download_Instructions_ENU.htm
or
http://www.microsoft.com/downloads/details.aspx?FamilyId=749BD760-F404-4D45-9AC0-D7F1B3ED1053&displaylang=en
CTP 6 must getting close. There have been various false alarms on blogs and BOL and the Feature pack is available.