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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:36:07+00:00 2026-05-13T21:36:07+00:00

I have a large table (~1M rows now, soon ~10M) that has two ranked

  • 0

I have a large table (~1M rows now, soon ~10M) that has two ranked columns (in addition to the regular data):

  • avg_visited, a float 0-1 representing a %age popularity; higher is better
  • alexa_rank, an integer 1-N giving an a priori ranking

The a priori ranking is from external sources so can’t be changed. Many rows have no popularity yet (as no user has yet hit it), so the a priori ranking is the fallback ordering. The popularity however does change very frequently – both to update old entries and to add a popularity to ones that previously only had the a priori ranking, if some user actually hits it.

I frequently run SELECT id, url, alexa_rank, avg_visited FROMsitesORDER BY avg_visited desc, alexa_rank asc LIMIT 49500, 500 (for various values of 49500).

However, ORDER BY cannot use an index with mixed ascendency per http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html

This is in mysql 5.1, innodb.

How can I best change this situation to give me a sane, fully indexed query?

  • 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-13T21:36:07+00:00Added an answer on May 13, 2026 at 9:36 pm

    Unfortunately, MySQL does not support DESC clauses in the indexes, neither does it support indexes on derived expressions.

    You can store the negative popularity along with the positive one and use it in the ORDER BY:

    CREATE INDEX ix_mytable_negpopularity_apriori ON (neg_popularity, a_priori);
    
    INSERT
    INTO    mytable (popularity, neg_popularity)
    VALUES  (@popularity, -@popularity);
    
    SELECT  *
    FROM    mytable
    ORDER BY
            neg_popularity, a_priori
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather large (many gigabytes) table of data in SQL Server that
I have a database table with a large number of rows and one numeric
I have an already large table that my clients are asking for me to
I have a large database and would like to select table names that have
Suppose you have a really large table, say a few billion unordered rows, and
I have a large table with 1 million+ records. Unfortunately, the person who created
I have a large table (more than 10 millions records). this table is heavily
I have a large table with list of scores like this, one score per
HI, I have a large table from which i can query to get the
I am creating a large table dynamically using Javascript. I have realised the time

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.