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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:15:32+00:00 2026-06-03T07:15:32+00:00

Table: CREATE TABLE `test` ( `uid` int(11) unsigned NOT NULL AUTO_INCREMENT, `rating` smallint(5) unsigned

  • 0

Table:

CREATE TABLE `test` (
  `uid` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `rating` smallint(5) unsigned NOT NULL DEFAULT '100',
  PRIMARY KEY (`uid`),
  KEY `rating` (`rating`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

This query runs quick enough(0.015s):

SELECT uid FROM test ORDER BY rating DESC LIMIT 0,100

But with big LIMIT offsets it runs very slow(2.215s):

SELECT uid FROM test ORDER BY rating DESC LIMIT 10000,100

How can I rid of huge LIMIT offsets?!

  • 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-03T07:15:34+00:00Added an answer on June 3, 2026 at 7:15 am

    The easiest way to improve performance is to ORDER BY a primary key.

    Since you can’t really do that with the rating column, you can cheat instead.

    Create this table:

    CREATE TABLE `test_ranks` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `uid` int(11) unsigned NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    

    Then put the following in a cron script that runs every X amount of time (1 minute, 5 minutes… basically a good compromise between update speed and the time it takes to run):

    CREATE TEMPORARY TABLE `_tmp_test_ranks` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `uid` int(11) unsigned NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    INSERT INTO `_tmp_test_ranks` (`uid`) VALUES (SELECT `uid` FROM `test` ORDER BY `rating` DESC);
    
    TRUNCATE `test_ranks`;
    
    INSERT INTO `test_ranks` SELECT * from `_tmp_test_ranks`;
    
    DROP TABLE `_tmp_test_ranks`;
    

    Now, instead of your slow-running select, you can run the faster:

    SELECT `uid` FROM `test_ranks` WHERE `id` BETWEEN 10000 AND 10100 ORDER BY `id` ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table having create table test(id int not null primary key, day
Assume I've got the table: CREATE TABLE test ( ID INT AUTO_INCREMENT PRIMARY KEY,
I've got the following SQL table: CREATE TABLE [dbo].[Test]( [TestID] [int] NOT NULL, [TestNum]
When I'm adding some constraints, e.g: create table Test( IDTest int primary key, Credit
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
This is my table: CREATE TABLE [Test].[dbo].[MyTest] ( [Id] BIGINT NOT NULL, [FId] BIGINT
For example: create table test (id numeric, t date not null); create trigger test_in
I have a mySQL table called test: create table test( locationExpect varchar(120) NOT NULL;
When I have the following table: CREATE TABLE test ( id integer NOT NULL,
CREATE TABLE test (id NUMBER PRIMARY KEY, name VARCHAR2(30)); CREATE SEQUENCE test1_sequence START WITH

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.