0

I have the following queries:

SELECT id FROM gr_webimages; (~0.0040 sec, 500 records)

SELECT id, parents FROM gr_webimages;  (~0.0450 sec, 500 records)

As you can see the only difference is the "parents" field which is a varchar(255) type. ("id" int(10) primary key) The second query is more than 10 times slower and the server not using any index. Could anyone explain why it takes so long and how can I speed up this query?

tcxbalage
  • 696
  • 1
  • 10
  • 30

1 Answers1

3

The first query can actually run without even touching the table... all the information it needs is available in the primary key index, so it just runs through the index to get the info it needs. The second query must actually go and read from the table, which is a significantly larger read...

See here: http://publib.boulder.ibm.com/infocenter/soliddb/v6r3/index.jsp?topic=/com.ibm.swg.im.soliddb.sql.doc/doc/using.indexes.to.improve.query.performance.html

"If the query selects only the indexed column, the query can read the indexed column value directly from the index, rather than from the table."

John Chrysostom
  • 3,973
  • 1
  • 34
  • 50