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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:30:03+00:00 2026-06-06T05:30:03+00:00

The following query is taking more than 25 seconds to complete: SELECT c.* ,

  • 0

The following query is taking more than 25 seconds to complete:

SELECT c.* , (c.age+ (UNIX_TIMESTAMP()-UNIX_TIMESTAMP(c.newdate))) AS ranking , IF(uc.id_user = 7,1,0) AS favorite
FROM c 
LEFT OUTER JOIN uc ON uc.id_cluster = c.id AND uc.id_user = '7' 
LEFT OUTER JOIN d ON d.id_cluster = c.id 
LEFT OUTER JOIN dt0 ON dt0.id_document = d.id 
LEFT OUTER JOIN t0 ON dt0.id_term = t0.id 
WHERE MATCH(t0.normalizacion) AGAINST ('term' IN NATURAL LANGUAGE MODE) 
GROUP BY c.id 
ORDER BY ranking ASC 
LIMIT 30

Indexes:

  • c.id PRIMARY
  • c.age INDEX
  • c.newdate INDEX
  • uc.id_user, uc.id_cluster PRIMARY
  • d.id PRIMARY
  • d.id_cluster INDEX
  • dt0.id_document, dt0.id_term PRIMARY
  • dt0.id_document INDEX
  • dt0.id_term INDEX
  • t0.id PRIMARY
  • t0.normalizacion FULLTEXT

If I remove the ORDER BY clause, it takes only 2 seconds.

I’ve been searching and found that the same index has to be used for both GROUP BY and ORDER BY (tried ordering by c.id and took 2 or 3 seconds). How can I change the query to be 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-06T05:30:04+00:00Added an answer on June 6, 2026 at 5:30 am

    (consolidating the discussion above)

    You can’t order efficiently by a computation result. To make this query work fast, create a ranking column that contains c.age-UNIX_TIMESTAMP(c.newdate). Then create an index on id and ranking, i.e. CREATE INDEX id_ranking ON c (id, ranking) to make both GROUP BY and ORDER BY indexed.

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

Sidebar

Related Questions

By taking reference from here I had made the following query: SELECT INSTITUTE.ID INST_ID,
Following query does not work in access. SELECT Fields.FieldId, PrecisionSettings.DecimalPlaces from Fields left outer
The following query will not execute mysql_query(SELECT * FROM order WHERE orderID = 102;);
The following query: SELECT DISTINCT ClassName FROM SiteTree ORDER BY ClassName is returning things
I'm executing the following query SELECT COUNT(*) FROM table WHERE field1='value' AND (field2 >=
I'm returning results from the following query which is taking too long when running.
I have the following query: SELECT M.Col7, M.Col8, M.Col9, M.Col10 FROM [MyTable] M WHERE
Following query is taking really long to execute: SELECT HISTORY.VERSION_ID , HISTORY.ACTION , HISTORY.STATUS
So I have following as part of my query SELECT * FROM $table WHERE
I have the following query? SELECT id_service, creation_date, SUM(ammount) FROM transactions WHERE DATE_FORMAT(creation_date, '%m/%d/%Y')

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.