Should I add a multi column index to MySQL?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mudge

    Should I add a multi column index to MySQL?

    Hello,

    I have a mysql table. Two columns in the table are used to pull out
    stories from the table.

    One of the columns stands for categories of the stories, and the other
    column is the primary key and has the id for each story.

    I am thinking of writing queries like this:

    mysql_query("SE LECT * FROM articles WHERE category='Scien ce_Fiction'
    AND story_id='45'") ;

    I am wondering if I should create a multi column index that covers both
    "categories " and "story_id" columns. -- INDEX (categories, story_id)

    Would this increase performance?

  • Dani CS

    #2
    Re: Should I add a multi column index to MySQL?

    mudge wrote:[color=blue]
    > Hello,
    >
    > I have a mysql table. Two columns in the table are used to pull out
    > stories from the table.
    >
    > One of the columns stands for categories of the stories, and the other
    > column is the primary key and has the id for each story.
    >
    > I am thinking of writing queries like this:
    >
    > mysql_query("SE LECT * FROM articles WHERE category='Scien ce_Fiction'
    > AND story_id='45'") ;
    >
    > I am wondering if I should create a multi column index that covers both
    > "categories " and "story_id" columns. -- INDEX (categories, story_id)
    >
    > Would this increase performance?
    >[/color]

    Your query should return the same results as

    SELECT * FROM articles WHERE story_id='45';

    because story_id is the primary key.

    Primary keys always have an index, so the answer is no.

    Comment

    Working...