Indexing question

  • 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!!

  • 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[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • 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.

  • What edition of SQL Server 2008 are you using?

  • both 2008 R2 sp2 and 2012

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply