Results 1 to 11 of 11

Thread: [RESOLVED] indexes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Resolved [RESOLVED] indexes

    Hello,
    I don't know if we can do this other databases but we can create indexes in mysql at the time of creating table.
    What I want to know is are the indexes updated automatically as and when we insert new data or update existing data?
    I am quite ignorant about these things, so my question might not make sense.
    Thank you.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: indexes

    It might vary for some database systems, but for all of the ones I'm aware of, yes, indexes are updated when data is inserted/updated.

    Note however that it means inserting/updating takes longer, as it takes some extra time to also update the index.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: indexes

    So, if the field to be indexed is not updated much, am I better off filling the table with values and then creating index?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: indexes

    More than likely you are always going to be adding/deleteing/updating etc records in your database. Typically I just create the indexs with the table and leave it alone unless an index goes nutso and needs to be dropped and readded.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: indexes

    There are times we have "dropped" an index so insert's of many, many rows can be done quickly.

    Then a "re-create" of the index is done after the inserts.

    It's a rare requirement - but definitely one that we have done.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: indexes

    I would image though that the INSERT would have to be pretty massive in order for you to feel the need to do that, right?

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: indexes

    Yes - row counts around a million.

    On tables with "several" indexes.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: indexes

    @sirsa: With the kind of inserts that szlamany is talking about, then I would suggest you follow suit and drop/create before/after your INSERTS.

    However, most INSERTS don't contain those kind of numbers so typically leaving the indexs alone (as long as they are doing their job) would be a standard way to go.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: indexes

    Thanks for all your replies. The point is I will be filling the table once with about million rows. After that , updates will be made to the other fields other than the one that is indexed. Where clause will be having the indexed field most of the times.

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: indexes

    Then, add your rows and then add your indexes and go from there.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: indexes

    Thanks to all of you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width