From: Dan Nelson Date: July 14 2004 4:56pm Subject: Re: do i need an index for this? List-Archive: http://lists.mysql.com/mysql/169057 Message-Id: <20040714165656.GC45644@dan.emsphone.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In the last episode (Jul 14), J S said: > I want to find the earliest and latest times in the time column of my > table internet_usage: > > +--------------+----------------------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +--------------+----------------------+------+-----+---------+-------+ > | time | timestamp(14) | YES | | NULL | | > +--------------+----------------------+------+-----+---------+-------+ > > So far there are 324936160 rows. If I do : > > SELECT MIN(time) as earliest, MAX(time) as latest from internet_usage; > > I can see the query is going to run for a long time. Do I have to > create an index on time to speed this up or is there another way of > doing it? Most definitely. An index will make that query almost instantaneous. Mysql won't even have to hit the table at all, and just has to look at the first and last index blocks. -- Dan Nelson dnelson@stripped