Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:24:30+00:00 2026-06-02T10:24:30+00:00

I have a mysql table storing members messages with 4 columns : message_id (primary

  • 0

I have a mysql table storing members messages with 4 columns :

  • message_id (primary key, auto incrementing)
  • sender_id (key)
  • receiver_id (key)
  • message_content

I do lots of SELECTs and I always sort them by message_id DESC, with queries such as :

SELECT message_content 
FROM table 
WHERE sender_id='3333' 
ORDER BY message_id DESC 
LIMIT 30

in such queries, the ORDER BY is expensive (it typically has to sort through thousands of rows, which generates some load when multiplied by many requests each second)

Is there a way to avoid having to sort the table each time? Since I always want to retrieve results in the same order, and since the message_id column doesn’t change over time, if each new table row was inserted in first position, the table would always be sorted and i wouldn’t need any “ORDER BY” anymore.
Is that possible ? Or are there other solutions?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:24:33+00:00Added an answer on June 2, 2026 at 10:24 am
    1. Specify 3333 as an integer, not a string (remove quotes)
    2. Add message_id column to the sender_id index (if you use myisam, because in innodb it is added automatically by so called “clustered index“)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table ( members ) with six columns ( FirstName, LastName,
I have a simple MySQL table for storing notification in a web with social
I have a MySQL database table that has a VARCHAR field storing a date
I have a table storing latitude, longitude, address and auto-generated id. The table contains
I have a members table in MySQL CREATE TABLE `members` ( `id` int(10) unsigned
I have a table of groups: id -- a unique ID (primary key) group
I have around 30 columns in a MySQL table. I want to calculate how
I have mysql table that has a column that stores xml as a string.
I have a MySQL table with approximately 3000 rows per user. One of the
I have a MySQL table containing domain names: +----+---------------+ | id | domain |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.