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

  • Home
  • SEARCH
  • 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 3402334
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:07:31+00:00 2026-05-18T05:07:31+00:00

I have a large mysql table (about 5M rows) on which i frequently insert

  • 0

I have a large mysql table (about 5M rows) on which i frequently insert data.

This table is the same i have to read data from and sometimes the entire database gets slow because of selecting data while there are many pending inserts.

I put indexes on each field i use in the WHERE statment, so i really don’t know why select gets so slow.

Could anyone provide me a hint to solve this problem ?

here is the sql of table and query

CREATE TABLE `messages` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `user_id` int(10) unsigned NOT NULL default '0',
  `dest` varchar(20) character set latin1 default NULL,
  `body` text character set latin1,
  `sent_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `md5` varchar(32) character set latin1 NOT NULL default '',
  `interface` enum('mobile','desktop') default NULL,
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`),
  KEY `md5` (`md5`),
  FULLTEXT KEY `dest` (`dest`,`body`),
  FULLTEXT KEY `body` (`body`)
) ENGINE=MyISAM AUTO_INCREMENT=7074256 DEFAULT CHARSET=utf8

and here the query:

EXPLAIN SELECT SQL_CALC_FOUND_ROWS id, sent_on, dest AS who, body,interface FROM messages WHERE user_id = 2 ORDER BY sent_on DESC LIMIT 0,50 \G;
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: messages
         type: ref
possible_keys: user_id
          key: user_id
      key_len: 4
          ref: const
         rows: 13997
        Extra: Using where; Using filesort
1 row in set (0.00 sec)
  • 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-05-18T05:07:31+00:00Added an answer on May 18, 2026 at 5:07 am

    Note the following in your EXPLAIN output:

    Extra: Using where; Using filesort
    

    The Using filesort means that MySQL is dumping the query results to a file to sort it, then reading the results back in to get the top 50 rows.

    While I’m no expert, I think that you could optimize this process by providing an index which can both satisfy the selection criteria and sort order all in one go; then the selection and ordering can be determiend by an index scan only, without having to sort the result set every time.

    In this case, your WHERE is on user_id, and your ORDER BY is on sent_on. So, in theory, if you provide a single index on those two columns (in that order), then the engine will be able to use the first half of the index to filter the results, and because the second half of the index is on the sent_on column, the index results will already be in order according to that column, allowing MySQL to simply retrieve the first 50 results from that index. No additional sorting required.

    Disclaimer: I’m not a DBA. I may be completely wrong.

    See Also: Mysql.com: Multiple Column Indexes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 100thousand rows in a mysql table, where each row has about
I have a problem here. I have about 13K rows of data that I
I'm looking for the fastest way to insert multiple rows in a MySql table
I have been starting to write some reasonably large and or confusing MySQL queries
I have large data sets (10 Hz data, so 864k points per 24 Hours)
I have a large database and would like to select table names that have
I have a large table with 1 million+ records. Unfortunately, the person who created
I have a large text template which needs tokenized sections replaced by other text.
I have to JOIN to large tables in a MySQL query and it takes
I have a large SQL Server database with about 40 columns and hundreds of

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.