Unix Technical Forum

creating indexes on a table already containing data

This is a discussion on creating indexes on a table already containing data within the MySQL General forum forums, part of the MySQL category; --> Hi all, I've got a database that has a few thousand rows, I've noticed that some of the search ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 09:26 PM
Angelo Zanetti
 
Posts: n/a
Default creating indexes on a table already containing data

Hi all,

I've got a database that has a few thousand rows, I've noticed that some
of the search queries (especially the large ones) are taking some time.
Im looking at adding indexes to my tables in order to speed up the data
retrieval.

My question is as follows: At this point in time if I add the indexes to
the various tables should I see immediate results in the query times or
do I have to wait for new information to enter the database (only new
data gets indexed?)
When does the data actually get indexed? Is it when its inserted or
continually when regards are inserted or updated in the database?

Thanks in advance.

--
------------------------------------------------------------------------
Angelo Zanetti
Systems developer
------------------------------------------------------------------------

*Telephone:* +27 (021) 469 1052
*Mobile:* +27 (0) 72 441 3355
*Fax:* +27 (0) 86 681 5885
*
Web:* http://www.zlogic.co.za
*E-Mail:* angelo@zlogic.co.za <mailto:angelo@zlogic.co.za>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 09:26 PM
Dan Buettner
 
Posts: n/a
Default Re: creating indexes on a table already containing data

Angelo, results should be (nearly) immediate. When you add an index,
MySQL creates an index for the existing data in your table. Later,
when data is added/updated/deleted, the index is updated
simultaneously.

With a few thousand rows, you should be able to get by adding a few
indexes where they seem to make sense. As your database grows, it
might be worth your while to go more in-depth with MySQL optimization.
The online manual has a good section at:
http://dev.mysql.com/doc/refman/5.0/...imization.html
and I also highly recommend Jeremy Zawodny's book "High Performance MySQL".

Dan


On 10/3/06, Angelo Zanetti <angelo@zlogic.co.za> wrote:
> Hi all,
>
> I've got a database that has a few thousand rows, I've noticed that some
> of the search queries (especially the large ones) are taking some time.
> Im looking at adding indexes to my tables in order to speed up the data
> retrieval.
>
> My question is as follows: At this point in time if I add the indexes to
> the various tables should I see immediate results in the query times or
> do I have to wait for new information to enter the database (only new
> data gets indexed?)
> When does the data actually get indexed? Is it when its inserted or
> continually when regards are inserted or updated in the database?
>
> Thanks in advance.
>
> --
> ------------------------------------------------------------------------
> Angelo Zanetti
> Systems developer
> ------------------------------------------------------------------------
>
> *Telephone:* +27 (021) 469 1052
> *Mobile:* +27 (0) 72 441 3355
> *Fax:* +27 (0) 86 681 5885
> *
> Web:* http://www.zlogic.co.za
> *E-Mail:* angelo@zlogic.co.za <mailto:angelo@zlogic.co.za>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=drbuettner@gmail.com
>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 09:26 PM
mos
 
Posts: n/a
Default Re: creating indexes on a table already containing data

At 05:42 PM 10/3/2006, you wrote:


>Dan Nelson wrote:
>
>>In the last episode (Oct 03), Angelo Zanetti said:
>>
>>
>>>I've got a database that has a few thousand rows, I've noticed that
>>>some of the search queries (especially the large ones) are taking
>>>some time. Im looking at adding indexes to my tables in order to
>>>speed up the data retrieval.
>>>
>>>My question is as follows: At this point in time if I add the indexes
>>>to the various tables should I see immediate results in the query
>>>times or do I have to wait for new information to enter the database
>>>(only new data gets indexed?)
>>>
>>>When does the data actually get indexed? Is it when its inserted or
>>>continually when regards are inserted or updated in the database?
>>>

>>
>>When you add an index, Mysql builds a complete index of your table
>>immediately. For a few thousand rows it should take under a minute. The
>>index will automatically be updated as you insert rows or change
>>existing ones.
>>
>>

>
>thanks Dan and Dan.
>
>I will have a look at the mysql site. However I checked and there are 600
>rows approx in the database.
>The query im running has 3 subselect statements and takes quite a while,
>would you say that indexing wouldn't help as there arent that many rows in
>the database currently? And therefore consider rewriting parts of the
>statement?
>I will add the indexes as good measuse anyway.
>
>TIA


Use an "Explain" in front of your Select statement in the MySQL gui to see
which indexes it is using.

Example:

explain select * from table1 where cust_no=123 order by date_sold;

Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 09:26 PM
Angelo Zanetti
 
Posts: n/a
Default Re: creating indexes on a table already containing data



Dan Nelson wrote:

>In the last episode (Oct 03), Angelo Zanetti said:
>
>
>>I've got a database that has a few thousand rows, I've noticed that
>>some of the search queries (especially the large ones) are taking
>>some time. Im looking at adding indexes to my tables in order to
>>speed up the data retrieval.
>>
>>My question is as follows: At this point in time if I add the indexes
>>to the various tables should I see immediate results in the query
>>times or do I have to wait for new information to enter the database
>>(only new data gets indexed?)
>>
>>When does the data actually get indexed? Is it when its inserted or
>>continually when regards are inserted or updated in the database?
>>
>>

>
>When you add an index, Mysql builds a complete index of your table
>immediately. For a few thousand rows it should take under a minute.
>The index will automatically be updated as you insert rows or change
>existing ones.
>
>
>


thanks Dan and Dan.

I will have a look at the mysql site. However I checked and there are
600 rows approx in the database.
The query im running has 3 subselect statements and takes quite a while,
would you say that indexing wouldn't help as there arent that many rows
in the database currently? And therefore consider rewriting parts of the
statement?
I will add the indexes as good measuse anyway.

TIA

--
------------------------------------------------------------------------
Angelo Zanetti
Systems developer
------------------------------------------------------------------------

*Telephone:* +27 (021) 469 1052
*Mobile:* +27 (0) 72 441 3355
*Fax:* +27 (0) 86 681 5885
*
Web:* http://www.zlogic.co.za
*E-Mail:* angelo@zlogic.co.za <mailto:angelo@zlogic.co.za>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:45 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com