SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Indexing question


Indexing question

Author
Message
Biank
Biank
SSC-Enthusiastic
SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)

Group: General Forum Members
Points: 108 Visits: 989
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!!
Evil Kraig F
Evil Kraig F
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8627 Visits: 7660
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
Biank
Biank
SSC-Enthusiastic
SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)

Group: General Forum Members
Points: 108 Visits: 989
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 Sad
So, any suggestion will be appreciated based on current structure.

thanks again.
Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39690 Visits: 38562
What edition of SQL Server 2008 are you using?

Cool
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)
Biank
Biank
SSC-Enthusiastic
SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)

Group: General Forum Members
Points: 108 Visits: 989
both 2008 R2 sp2 and 2012
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