Jump to content

Simple Query Optimization by Indexing


jomsfx

Recommended Posts

I have a really simple query but can't figure out how to make it faster. It's just something like:

 

SELECT field1 FROM table1 WHERE field2 = 'value'; 

 

Because of 300,000 rows in the table it takes around 50 seconds to execute.

I have been researching about indexes and tried to create an index for field2(varchar 80) with an Index Type of Normal and Index Method of BTREE, but the process is still slow.

The storage engine is InnoDB.

 

Once I solve this I will be adding other criteria in the WHERE clause using other columns within the said table.

 

If you could suggest another way to speed this up or could point me to the right direction I would really appreciate it.

 

Thanks.

 

Link to comment
Share on other sites

id:1

Select Type: Simple

table: table1

type: ref

possible keys: field2

key: field2

key len: 43

ref: const

rows: 40950

Extra: Using Where

 

This is how I created the index:

 

CREATE INDEX field2 ON table1(field2(40));

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.