help fetching latest records from mysql table with 15 million records

Discussion in 'MySQL' started by ravish_83, Jul 7, 2009.

  1. #1
    I am having a website where one of my primary ( aka more frequently used table has grown to more then 15 miilion records.

    Now the problem with me is that i have to fetch the latest record first. I don't want to make the orderby query as it make the system slow the executuin time for a records whose index key is having 20000 + cardinality takes 0.8 sec. and when i fetch the execution time is .004 sec which is 200 times faster.

    please suggest how can i do fetch the latest records from mysql table without doing the order by.

    regards
     
    ravish_83, Jul 7, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Maybe try using a last_insert_id and retrieve the record via a second query with the result of that.
     
    jestep, Jul 7, 2009 IP
  3. ravish_83

    ravish_83 Peon

    Messages:
    221
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    here is bit more clarity

    this is like i am having end users messages in my database. and for a user named "U" i am having 20000 messages. Now i want fetch the last 10 messages for users "U". right now i am doing it with the order by command on primary key. But that sucks when it come about fetching the records for a users who have 20000 Messages in all.
     
    ravish_83, Jul 8, 2009 IP
  4. nvidura

    nvidura Well-Known Member

    Messages:
    1,780
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    150
    #4
    Why don't you change the storage engine?
     
    nvidura, Jul 16, 2009 IP
  5. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I think you will have to use the order by as you need the last ten exactly .. Also you can use the LIMIT to limit it to 10 messages.
     
    HivelocityDD, Jul 16, 2009 IP
  6. ravish_83

    ravish_83 Peon

    Messages:
    221
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    it takes even more time so no use of fetching the last 10 record. I need the table to be organized in a manner so that last entered should be fetched first.
     
    ravish_83, Jul 21, 2009 IP
  7. ravish_83

    ravish_83 Peon

    Messages:
    221
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    what engine will be be recommending ?
     
    ravish_83, Jul 21, 2009 IP