Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Index Primer - Just what statistics are kept?


Index Primer - Just what statistics are kept?

Author
Message
sqlrunner
sqlrunner
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 159
Comments posted to this topic are about the item Index Primer - Just what statistics are kept?

Josef Richberg
2009 Exceptional DBA
http://www.josef-richberg.squarespace.com
http://twitter.com/sqlrunner
ta.bu.shi.da.yu
ta.bu.shi.da.yu
SSC Veteran
SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)

Group: General Forum Members
Points: 253 Visits: 494
There's something I'm a bit confused about here...

It's the following:

AVG_RANGE_ROWS: 176.7533 -- number of records for each distinct value (those within the DISTINCT_RANGE_ROWS)

Now how can you have a part of a row? Surely the number of rows for each distinct value whole come out to be a whole number? This seems, as the name suggests, an average.

And in fact... I just checked this out and this is what Microsoft have to say about this:

AVG_RANGE_ROWS - "Average number of rows with duplicate column values within a histogram step, excluding the upper bound (RANGE_ROWS / DISTINCT_RANGE_ROWS for DISTINCT_RANGE_ROWS > 0)."

Random Technical Stuff
rbramhall
rbramhall
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 37
Very cool. I never knew any of this stuff and haven't seen very many articles on statistics. From the article I guess I inferred that the statistics help especially if you do have several columns in the index as long as you always include the Prefix column in your queries.

Of course you always want your most used/important filter column to be first in the index, but this is great to see WHY!
rbramhall
rbramhall
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 37
Actually this brought up another issue I have always wanted to solve. I have a store/product table mapping, ~83M rows and always growing as stores are added. The stores can have anywhere from a couple to 2.5M products in each. Of course the large stores make up the majority of the 83M rows.

The problem is that whenever I update the product mix, I'm deleting/updating/inserting up to 2.5M rows in the 83M row table at a time. We threw lots of hardware at it, and brought 15 minutes down to 2-3 minutes, but still I'm trying to insert 2.5M records into an 83M record table and even with 36 hard drives, it just takes time.

I wanted to use partitioned tables and functions, but that's only in SQL Enterprise edition. But in my research on partitioned tables, I needed to come up with a mechism to group my stores, because you have a limit of 1000 partitions (I think, it's been a while).

In the statistics they group your prefix column into at most 200 steps. That's pretty much the same thing I wanted to do for my partitioned function.

I just wish there was another way that when inserting/deleting the 2.5M records in my table it wouldn't do a total table lock and at 2-3 minutes it causes timeouts on any other store retrieving data from that table.

Any ideas?

Thanks!
Dean Cochrane
Dean Cochrane
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 639
Great article. It discusses index stats in just enough detail to make things clear without bogging down.
ta.bu.shi.da.yu
ta.bu.shi.da.yu
SSC Veteran
SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)SSC Veteran (253 reputation)

Group: General Forum Members
Points: 253 Visits: 494
rbramhall (10/28/2009)
I just wish there was another way that when inserting/deleting the 2.5M records in my table it wouldn't do a total table lock and at 2-3 minutes it causes timeouts on any other store retrieving data from that table.

Any ideas?

Thanks!


Sounds like this should be desirable behaviour! Because if you are deleting so many records, and one of your stores reads that deleted record and does something with it, then they'd have invalid data... of course, I'm not totally sure what you are trying to do. Same with inserts - if the store did a report that relied on knowing what you had at a point in time, and it *under* reported, then again they aren't getting accurate info.

Sorry, just realised the way that your table has been put together.

You can actually stop lock escalation in SQL Server... though that seems a bit drastic. But if you look at the following article it will tell you how to do this. Use at your own risk though!

However.. I've never really tried using it, but perhaps snapshot isolation might help? Of course, that would put contention on TempDB... someone might want to chime in here if I'm telling anything misleading :-)

Random Technical Stuff
Dean Cochrane
Dean Cochrane
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 639
rbramhall (10/28/2009)
The problem is that whenever I update the product mix, I'm deleting/updating/inserting up to 2.5M rows in the 83M row table at a time. We threw lots of hardware at it, and brought 15 minutes down to 2-3 minutes, but still I'm trying to insert 2.5M records into an 83M record table and even with 36 hard drives, it just takes time.


I would think this question is better suited to one of the code forums than to discussion on an excellent article on index statistics, but...

If all you have is a product-store mapping (storeid, productid) I can't see that inserting 2.5 M rows would take 3 minutes. Therefore I suspect that you have a lot of other stuff in the table.

That being the case, I think my first instinct would be to partition the table on storeid. That doesn't mean that you have to have one partition per store: maybe the bit stores each have their own and the smaller ones are grouped together. If you've got tables with ~100M rows in them, you probably should be using Enterprise.

If there is no way to make that work for some reason (cultural or otherwise) I would try a phased insert/update/delete, working with 10,000 rows at a time. That won't improve the end-to-end speed of your process, but if you choose the right number it will prevent lock escalation.

Other people may have ideas regarding such things as BULK INSERT, but I haven't worked with it much.
rbramhall
rbramhall
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 37
ta.bu.shi.da.yu (10/28/2009)
rbramhall (10/28/2009)
I just wish there was another way that when inserting/deleting the 2.5M records in my table it wouldn't do a total table lock and at 2-3 minutes it causes timeouts on any other store retrieving data from that table.

Any ideas?

Thanks!




Sorry, just realised the way that your table has been put together.

You can actually stop lock escalation in SQL Server... though that seems a bit drastic. But if you look at the following article it will tell you how to do this. Use at your own risk though!

However.. I've never really tried using it, but perhaps snapshot isolation might help? Of course, that would put contention on TempDB... someone might want to chime in here if I'm telling anything misleading :-)


I'll check out the article. I looked into the Snapshot Isolation before we went from 4 RAID 5 drives to 36 drives. Now that I have the TempDB Data on 4 drives in RAID 10 and TempDB Log on 4 drives in RAID 10, I'll definitely look back into the Snapshot Isolation. Thanks.
rbramhall
rbramhall
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 37
Dean Cochrane (10/28/2009)
rbramhall (10/28/2009)
The problem is that whenever I update the product mix, I'm deleting/updating/inserting up to 2.5M rows in the 83M row table at a time. We threw lots of hardware at it, and brought 15 minutes down to 2-3 minutes, but still I'm trying to insert 2.5M records into an 83M record table and even with 36 hard drives, it just takes time.


I would think this question is better suited to one of the code forums than to discussion on an excellent article on index statistics, but...

Sorry, will do next time, this literally just popped into my head when I read it, and not used to posting to this site.

If all you have is a product-store mapping (storeid, productid) I can't see that inserting 2.5 M rows would take 3 minutes. Therefore I suspect that you have a lot of other stuff in the table.

Yes, I have a couple money columns, date columns and a few other flags and 9 indexes on it too.

That being the case, I think my first instinct would be to partition the table on storeid. That doesn't mean that you have to have one partition per store: maybe the bit stores each have their own and the smaller ones are grouped together. If you've got tables with ~100M rows in them, you probably should be using Enterprise.

We're getting there, my latest plan is to completely rewrite and go a more rules driven and utilize temp tables or my own static tables per store. For individual stores that solves the problem, but then we would have to build a data warehouse for doing system wide reporting.

The customer would rather spend $100k on services, than spend $100k buying the needed Enterprise licenses from MS and then still have to do services on top of it to utilize the Enterprise licenses!

If there is no way to make that work for some reason (cultural or otherwise) I would try a phased insert/update/delete, working with 10,000 rows at a time. That won't improve the end-to-end speed of your process, but if you choose the right number it will prevent lock escalation.

Definitely another option. Thanks!
hstj
hstj
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 13
If you're inserting 2.5 million records into a table then you're index will be severly defragmented. You should consider rebuilding all indexes involved or at least reorganize them. And aslo: While you're deleting and inserting 2.5 million records, does your other select-queries really need to be read committed? how about putting in a WITH (NOLOCK) in your select statements - that way your deletes and inserts will have an exclusive table lock while working, but your selects will still work - though you'll might get some dirty reads..
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search