|
Anyone can explain how would I benefit from filtered statistics on columns that do not have an index? Update: Based on this link, query plans will differ as the optimizer will estimate more accurately. I see the differences in plans when I run under the AdventureWorks sample DB. But I still do not see the benefit as the IO logical reads are still the same with and without filtered statistics.
(comments are locked)
|
|
If you have queries with complex but predictable where clauses which include multiple columns then creating filtered statistics might make sense. They are cheaper than indexes as far as the system resources are concerned, but still provide information to the engine about so-called cardinality estimates (a fancy word for selectivity). The information is stored for each prefix column of the statistics, meaning that if the queries fail to include the prefix column in the predicates then the statistics are useless, just like the indexes are useless when the first column of the index is not included. I am sure that someone will have a better answer, but these are my 2 cents. Oleg @Oleg - good answer. I am trying to get an example put together and the bloody thing won't do what I want it to. I suspect I am getting some sort of plan reuse when I don't want it, but I cannot seem to fix it.
Oct 27 '10 at 03:25 PM
WilliamD
@WilliamD If it is dev DB then you can just clear all them out: dbcc dropcleanbuffers with no_infomsgs;
dbcc freeproccache with no_infomsgs;
dbcc freesystemcache('All') with no_infomsgs;
goLadies and Gentlemen! All existing plans have left the building :)
Oct 27 '10 at 03:35 PM
Oleg
@Oleg - tried that, didn't help with my example. I think I'll post it as a wiki here and someone can take a look.
Oct 27 '10 at 03:37 PM
WilliamD
@Oleg - +1 - not sure how anyone is going to have a better answer than that...
Oct 27 '10 at 03:39 PM
Matt Whitfield ♦♦
Thanks guys. I understand the theory but still don't get the idea of filtered statistics for a table that has no indexes. At the end, the optimizer will do a cluster index scan or table scan. What do you think?
Oct 27 '10 at 05:44 PM
ozamora
(comments are locked)
|
|
I cannot seem to get this example to work as I wanted. Maybe it can be improved upon - it is just too late for me today. I play in my test DB SandBox, that it all you will need to change to get this to work. I clear the cache in this script too - DO NOT PLAY WITH THIS ON A PRODUCTION SYSTEM!!!!!! /* The execution plan is the same as before - SQL Server even warns that there are missing Stats on the execution plan - why is that? */ Is it posssible that this is because of the AUTO_UPDATE_STATISTICS OFF? What I mean is that though statistics are created, they are not actually there yet? In other words, if you remove the AUTO_UPDATE_STATISTICS OFF from the beginning of the script, maybe it will then do what you expect.
Oct 27 '10 at 03:52 PM
Oleg
@WilliamD In my situation, your script did not need any modifications, it just ran as expected. What I mean is that after I uncommented dbcc lines and executed them, the next select with the predicate had shown consistent numbers (99) for both estimated and actual number of rows. The warning also disappeared. The only difference was that I used AdventureWorks database with few extra tables I created for some other tests and did not drop yet, so the number of inserted records happened to be 1329.
Oct 27 '10 at 04:53 PM
Oleg
@Oleg - thanks for testing this. I dont know about the AUTO_UPDATE_STATISTCS OFF affecting this, as I create the statistic manually and then clear the cache - this should then go ahead and re-create the exec plan, and use any stats that are available. Last night I had it work once when I was going through it, but then after that it didn't. It was past midnight and I was a little bit too tired to fix it then..... maybe another day, another blog post.
Oct 27 '10 at 11:53 PM
WilliamD
(comments are locked)
|

