Jump to content

is there any problem if same column in two type of Index


Recommended Posts

I have a table with 100 columns. Now I have made column1 and column2 as unique

 

unique index(column1,column2)

 

Now, I have to run queries on column1 and/or column2 frequently. So I made column1 and column2 indexed to speed up my query.

like

CREATE INDEX _incol ON customer (column1(10));

 

Now my question is

 

1) Is there any problem as I include column1 and column2 in two types of index?

2) Should I really need to make that two columns indexed separately or the unique index will do the task I want (speed up the query)?

MySQL uses the index that best matches the query. If you are searching on 2 columns, an index that covers those 2 columns will be used first. Next is an index for either of the columns - if there is an index on both, MySQL will use the index that returns the least results.

 

So as said, if you search on both columns 99% of the time, you really only need the one index that has both columns.

But what is the side effect of indexing. I mean is there any problem if I make all kind of possible index (though sounds wired!!)??? The reason is I dont have any problem with space, rather my project is very sensitive with speed, even for 1% time!!

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.