mysql - Should I also index columns included in a PRIMARY KEY? -


This question suddenly went into my head ... I have a table which, based on their ID, I create table looks like this:

  create table 'ticket_content' (`ticket_ID` INT not tap, 'entity_id' INT not zero, 'indicated DO 'INT NO FAL DEFAULT 0, Primary key (`Ticket_ID`,` unit_ID`), key `ticket_id` (` ticket_ID`), key `unit_id` (` entity_id`))  

I I am wondering if there is a need to include those previous two key lines, will I get better speed with the following questions, or do the individual columns automatically under the primary key Will be indexed from?

  SELECT * ticket_contact WHERE ticket_id = 1; SELECT * ticket from ticket_contact WHERE entity_id = 1; The index created by    

primary key is identical to any Other (potential mixed) UNIQUE index therefore you do not need to create a separate index for ticket_id because it is in (ticket_id, entity_id) index The main column is included in the form.

By using that column independently of ticket_id

> you usually entity_id

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -