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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:22:11+00:00 2026-06-13T09:22:11+00:00

In my project I have a loop that runs the same query but with

  • 0

In my project I have a loop that runs the same query but with different limit values. In the first 10 loop cycles, query is executed with acceptable speed, but then slow down. Table to which I’m making query has 150K registers and column1 is Integer and my query is:

SELECT * FROM my_table ORDER BY column1 ASC LIMIT 0,1000
...
SELECT * FROM my_table ORDER BY column1 ASC LIMIT 9000,10000

As I understood it sorts all 150K registers each time. But how can I sort register only between indicated range?
How can I make this query work faster?

  • 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-13T09:22:12+00:00Added an answer on June 13, 2026 at 9:22 am

    This might be a stupid question, but is column1 indexed?

    And think about the second question, it would make sence if the database needs to sort the entire dataset to determine the correct 1000 elements to return 🙂

    Imagine you have 10 numbers in arbitrary order

    4, 7, 1, 3, 9, 8, 5, 2, 6, 0
    

    and you want to select 5 numbers, ascending. If you just take the first 5, and sort them you would get

    1,3,4,7,9
    

    and if you sorted the whole list first, and then took 5 you would have

    0,1,2,3,4
    

    EDIT: Since it is a PK, I don’t know if LIMIT is clever enough to determine if your primary key is sequential, otherwise it would certainly need to read them all first. EXPLAIN would tell you if it is.

    EDIT BASED ON COMMENT

    If it is sequential, maybe something like this would help

    SELECT * FROM ... WHERE column1 >= 9000 ORDER BY column1 ASC LIMIT 1000
    

    the where will ensure that it ignores all rows with column1 values under 9000, so you are working on a smaller dataset.

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

Sidebar

Related Questions

I have a android project that runs fine on the vm, but when I
Im using MVC-Viewmodel, EF Model first on my project. I have a foreach loop
I have a project that I thought was going to be relatively easy, but
I have created a WCF method that runs an infinite loop, polling every 5
My project have no visible error but when i try to run it gives
I have a C++ project that have like 15+ external libraries installed with a
As a school project we've created a C# XNA 4.0 Game that runs perfectly
In my Flash project I have a movieclip that has 2 keyframes. Both frames
I have just started learning XNA. This is my first program that I am
I have a multithreading server application which runs fine for the first ca. 40

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.