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 6761453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:11:34+00:00 2026-05-26T14:11:34+00:00

The following MySQL query completes in under 0.02 seconds : SELECT * FROM `Table1`

  • 0

The following MySQL query completes in under 0.02 seconds:

 SELECT
    *
 FROM
    `Table1`
 WHERE
    `col1`     = '43532' AND
    `col2`     = 'N'
 ORDER BY col3 DESC 

However, if I add LIMIT 0, 5 at the end of it, it completes in over 7 seconds:

 SELECT
    *
 FROM
    `Table1`
 WHERE
    `col1`     = '43532' AND
    `col2`     = 'N'
 ORDER BY col3 DESC 
 LIMIT 0, 5

This is happening even when the query returns an empty result set.

Why is the addition of LIMIT 0, 5 causing this simple query to be 350 times slower? I need to be able to limit the results for pagination reasons, so how can I fix this?

EDIT:

WITHOUT LIMIT, EXPLAIN says:

id  select_type table   type    possible_keys   key     key_len   ref     rows  Extra
1   SIMPLE      Table1  ref     col1,col2       col1    5         const   2441  Using where; Using filesort

WITH LIMIT, EXPLAIN says:

id  select_type table   type    possible_keys   key   key_len   ref   rows  Extra
1   SIMPLE      Table1  index   col1,col2       col3  5         NULL  1050  Using where
  • 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-26T14:11:35+00:00Added an answer on May 26, 2026 at 2:11 pm

    The problem is that the limit causes MySQL to order the query first, forcing it to order the whole set, and then filter it, not using indexes.

    There are directives to tell MySQL which index to use, but it may be better to create a combined index on col1, col2 and col3. MySQL should use that index for filtering and sorting. You should experiment to see whether the query is faster if col3 is the first or the last column in that index.

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

Sidebar

Related Questions

GOT error for the following query in MYSQL(version5.1) SELECT year,month,sum(fact_1),sum(fact_2),sum(fact_3),sum(fact_4) from( select year,month,fact_1,fact_2,0 as
The following mysql query... SELECT a.*, b.*, ( SELECT COUNT( * ) FROM lp_units
Given the following MySQL query: SELECT `show`.`id` , GROUP_CONCAT( `showClips`.`clipId` ORDER BY `position` ASC
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have the following mysql query which I am running with php like so.
I use the following mysql query, DELIMITER $$ DROP PROCEDURE IF EXISTS `allied`.`aboutus_delete`$$ CREATE
I am having trouble with the following MYSQL query and are hoping that there
I would like to pass a MYSQL query via Coldfusion the following date: 03/13/2010
I am having a trouble matching a string in a MySQL-query with the following
The MySQL slow query log often shows a bunch of following entries in sequence.

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.