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

Indexing question Expand / Collapse
Author
Message
Posted Thursday, March 21, 2013 5:17 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 9:03 AM
Points: 53, Visits: 549
Hello,

I'm trying to create indexes on a table that will hold all of data changes in any columns of any tables so the number of rows will be pretty big.

Here's the table structure:

ID int identity
chg_type char(1) not null
tbl_nm varchar(40) not null
p_key_nm varchar(40) not null
p_key_id id not null
col_nm varchar(40) not null
old_txt varchar(1000) null
net_txt varchar(1000) null
mod_dt datetime not null
mod_by varchar(50) not null

And common query #1, someting like;
select old_txt, new_txt, mod_dt, mod_by
from table1
where tbl_na = 'tbl_name'
and p_key_id = 111
and p_key_nm = 'ttt'

common query #2, someting like;
select tbl_name, old_txt, new_txt, mod_dt, mod_by
from table1
where mod_dt > '1/1/2013'
and mod_by = 'uuu'

I created index like this:
1. PK on ID column
2. Non-Unquie NC on p_key_id, tbl_name includes old_txt and new_txt
3. NC on mod_dt, mod_by


I wonder if these indexes are good enough (from initial point of view) to cover both queries without impacting much overheads?

Thanks much for your help!!
Post #1434083
Posted Thursday, March 21, 2013 5:36 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:09 PM
Points: 6,251, Visits: 7,411
Biank (3/21/2013)
I'm trying to create indexes on a table that will hold all of data changes in any columns of any tables so the number of rows will be pretty big.

Here's the table structure:

ID int identity
chg_type char(1) not null
tbl_nm varchar(40) not null
p_key_nm varchar(40) not null
p_key_id id not null
col_nm varchar(40) not null
old_txt varchar(1000) null
net_txt varchar(1000) null
mod_dt datetime not null
mod_by varchar(50) not null

One audit table to rule them all? You've just created one HECK of a contention point for your entire database. Make sure you turn on deadlock notices, you may need them. Also start monitoring for what's called 'hotspotting' your tables. There's a lot out there on google for that term.

I created index like this:
1. PK on ID column
2. Non-Unquie NC on p_key_id, tbl_name includes old_txt and new_txt
3. NC on mod_dt, mod_by

PK is Clustered or nonclustered? Use what you like for the key, but I recommend a tight clustered index which is your most common search patterns. Also, for mod_by, are your users going to the database to directly edit or do you use a front end application? If it's a front end, they almost always all use the same login, you won't have any detection of the user(s).

... I've never tried this tactic because of how painfully most of my systems would react if every table had to contend with a single location for auditing simultaneously on every transaction.

I would truly recommend you review a different design method. Once you get any serious throughput on this system you will feel tremendous amounts of pain.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1434090
Posted Thursday, March 21, 2013 6:02 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 9:03 AM
Points: 53, Visits: 549
thanks for your input.

I tried not to go this route but there are no other choices but track all the changes thsi way, unfortunately.

1. The PK will be Clustered.
2. I'm planing to use vertical partitioning based on the number of rows.
3. Yes, I'm looking for other better solution for this since it's alreay to late to change it now.

I guess, there are not many indexing option since this is already a bad design
So, any suggestion will be appreciated based on current structure.

thanks again.
Post #1434096
Posted Thursday, March 21, 2013 8:47 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 8:34 PM
Points: 23,343, Visits: 32,079
What edition of SQL Server 2008 are you using?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1434116
Posted Thursday, March 21, 2013 11:54 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 9:03 AM
Points: 53, Visits: 549
both 2008 R2 sp2 and 2012
Post #1434139
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse