How does MySQL optimize this?

Source: Internet
Author: User
SELECT *
From add
ORDER by LENGTH (title) DESC
LIMIT 10

Data 20W, execute more than 1 seconds .... How to optimize WOW


Reply to discussion (solution)

It's the simplest of all. It is recommended to use the cache bar query results cached without the need to repeatedly query

I'm afraid the order by will not be able to optimize, 1 seconds more not slow ah.

20W not much, it is recommended to redesign the database, create a new column, save length (title), when inserted, with strlen ($title) calculation. The new column is then indexed. (If the ID is self-increasing, you can try to use the ID and the new column as a primary key)
In addition, do not use SELECT *, with select Title,content,date and the like, the column you need to write out.

Make an index of LENGTH (title)
Your sort of rules are weird, yo.

Desc SELECT *
From add
ORDER by LENGTH (title) DESC
LIMIT 10

Parse the next SQL, key field plus index.

Keywords plus indexing can improve efficiency.

can select * Do not return all fields? You can store more than one field to hold the value of LENGTH (title), and maintain this value (update and insert) with two triggers, and then build the index on this column, it should be better.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.