Stup question but anyway

Discussion in 'MySQL' started by deriklogov, Sep 1, 2009.

  1. #1
    The thing is I found that mysql takes very long because of the ORDER BY date.
    So I decide to change it to ORDER by id , which is unique in database. It runs twice faster, but today I figure out that id is set as PRIMARY key, so my question is , if I will change it to UNIQUE , would I get some performance from it ? just because UNIQUE key its more easy to sort ?

    or what else I can do to increase ORDER by speed ?
     
    deriklogov, Sep 1, 2009 IP
  2. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How many records are you including in your ORDER? I have tables with several hundred thousand records in them and my queries rarely take more than two seconds to execute. It might not be your query but the number of simultaneous connections to the database, and if you are on a shared host, times that by the number of sites also accessing the database server.
     
    nyxano, Sep 1, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    There's no difference in speed between UNIQUE or PRIMARY key. Besides, you should keep it as PRIMARY to enjoy auto-incremented keys.

    If you're ordering on other columns, you'll need to add indexes to those. You can get an idea of what is wrong by doing EXPLAIN SELECT ... (your query) in phpmyadmin.
     
    premiumscripts, Sep 2, 2009 IP