List:General Discussion« Previous MessageNext Message »
From:Steve Edberg Date:January 16 2003 10:02am
Subject:Re: index problem
View as plain text  
At 2:31 AM -0700 1/16/03, Prasanth Krishna wrote:
>i have a database with a single table say tbl1 with an index on a
>particular field say col1. when i say
>select * from tbl1;
>it doesn't use the index on that table.

In this query, I can't see any reason to use an index...MySQL is 
simply returning all columns from all records in whatever order it 
sees fit.

If you used

	select * from tbl1 order by col1

it *would* use the index.

>but if i say
>select col1 from tbl1;
>it uses the index.

I'm guessing that in this case MySQL is reading col1 directly from 
the index doesn't need to look at the actual data record at 
all. Which is good.

>how to make mysql use the index on col1 for the first query?

Give it a reason to do so ;)


| Steve Edberg                                      sbedberg@stripped |
| University of California, Davis                          (530)754-9127 |
| Programming/Database/SysAdmin      |
| SETI@Home: 1001 Work units on 23 oct 2002                              |
| 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens...  |
index problemPrasanth Krishna16 Jan
  • Re: index problemSteve Edberg16 Jan
RE: index problemSimon Green16 Jan