Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Indexing question
Indexing question
Rate Topic
Display Mode
Topic Options
Author
Message
Biank
Biank
Posted Thursday, March 21, 2013 5:17 PM
SSC Rookie
Group: General Forum Members
Last Login: Yesterday @ 8:09 PM
Points: 48,
Visits: 299
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
Evil Kraig F
Evil Kraig F
Posted Thursday, March 21, 2013 5:36 PM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 6:03 PM
Points: 5,658,
Visits: 6,099
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
Biank
Biank
Posted Thursday, March 21, 2013 6:02 PM
SSC Rookie
Group: General Forum Members
Last Login: Yesterday @ 8:09 PM
Points: 48,
Visits: 299
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
Lynn Pettis
Lynn Pettis
Posted Thursday, March 21, 2013 8:47 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 3:56 PM
Points: 21,588,
Visits: 27,378
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
Biank
Biank
Posted Thursday, March 21, 2013 11:54 PM
SSC Rookie
Group: General Forum Members
Last Login: Yesterday @ 8:09 PM
Points: 48,
Visits: 299
both 2008 R2 sp2 and 2012
Post #1434139
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.