Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Index Primer - Just what statistics are kept? Expand / Collapse
Author
Message
Posted Wednesday, October 28, 2009 12:17 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 29, 2012 8:08 AM
Points: 29, Visits: 155
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
Post #809720
Posted Wednesday, October 28, 2009 5:34 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, July 3, 2011 7:09 AM
Points: 258, 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
Post #809820
Posted Wednesday, October 28, 2009 6:30 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 6, 2014 1:07 PM
Points: 9, Visits: 32
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!
Post #809843
Posted Wednesday, October 28, 2009 6:44 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 6, 2014 1:07 PM
Points: 9, Visits: 32
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!
Post #809855
Posted Wednesday, October 28, 2009 6:55 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, May 31, 2014 10:37 PM
Points: 85, Visits: 625
Great article. It discusses index stats in just enough detail to make things clear without bogging down.
Post #809867
Posted Wednesday, October 28, 2009 7:05 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, July 3, 2011 7:09 AM
Points: 258, 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
Post #809875
Posted Wednesday, October 28, 2009 7:06 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, May 31, 2014 10:37 PM
Points: 85, Visits: 625
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.
Post #809877
Posted Wednesday, October 28, 2009 7:24 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 6, 2014 1:07 PM
Points: 9, Visits: 32
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.
Post #809901
Posted Wednesday, October 28, 2009 7:33 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 6, 2014 1:07 PM
Points: 9, Visits: 32
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!
Post #809921
Posted Wednesday, October 28, 2009 12:46 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 5, 2010 11:51 AM
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..
Post #810230
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse