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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:16:37+00:00 2026-06-08T17:16:37+00:00

I realized, that the response to a MySQL query becomes much faster, when creating

  • 0

I realized, that the response to a MySQL query becomes much faster, when creating an index for the column you use for “ORDER BY”, e.g.

SELECT username FROM table ORDER BY registration_date DESC

Now I’m wondering which indices I should create to optimize the request time.
For example I frequently use the following queries:

SELECT username FROM table WHERE
    registration_date > ".(time() - 10000)."

SELECT username FROM table WHERE
    registration_date > ".(time() - 10000)."
    && status='active'

SELECT username FROM table WHERE
    status='active'

SELECT username FROM table ORDER BY registration_date DESC

SELECT username FROM table WHERE
    registration_date > ".(time() - 10000)."
    && status='active'
    ORDER BY birth_date DESC

Question 1:
Should I set up separate indices for the first three request types? (i.e. one index for the column “registration_date”, one index for the column “status”, and another column for the combination of both?)

Question 2:
Are different indices independently used for “WHERE” and for “ORDER BY”? Say, I have a combined index for the columns “status” and “registration_date”, and another index only for the column “birth_date”. Should I setup another combined index for the three columns (“status”, “registration_date” and “birth_date”)?

  • 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-08T17:16:38+00:00Added an answer on June 8, 2026 at 5:16 pm

    There are no hard-and-fast rules for indices or query optimization. Each case needs to be considered and examined.

    Generally speaking, however, you can and should add indices to columns that you frequently sort by or use in WHERE statements. (Answer to Question 2 — No, the same indices are potentially used for ORDER BY and WHERE) Whether to do a multi-column index or a single-column one depends on the frequency of queries. Also, you should note that single-column indices may be combined by mySQL using the Index Merge Optimization:

    The Index Merge method is used to retrieve rows with several range
    scans and to merge their results into one. The merge can produce
    unions, intersections, or unions-of-intersections of its underlying
    scans. This access method merges index scans from a single table; it
    does not merge scans across multiple tables.

    (more reading: http://dev.mysql.com/doc/refman/5.0/en/index-merge-optimization.html)

    Multi-column indices also require that you take care to structure your queries in such a way that your use of indexed columns matches the column order in the index:

    MySQL cannot use an index if the columns do not form a leftmost
    prefix of the index. Suppose that you have the SELECT statements shown
    here:

    SELECT * FROM tbl_name WHERE col1=val1; SELECT * FROM tbl_name WHERE
    col1=val1 AND col2=val2;

    SELECT * FROM tbl_name WHERE col2=val2; SELECT * FROM tbl_name WHERE
    col2=val2 AND col3=val3;

    If an index exists on (col1, col2, col3), only the first two queries
    use the index. The third and fourth queries do involve indexed
    columns, but (col2) and (col2, col3) are not leftmost prefixes of
    (col1, col2, col3).

    Bear in mind that indices DO have a performance consideration of their own — it is possible to “over-index” a table. Each time a record is inserted or an indexed column is modified, the index/indices will have to be rebuilt. This does demand resources, and depending on the size and structure of your table, it may cause a decrease in responsiveness while the index building operations are active.

    Use EXPLAIN to find out exactly what is happening in your queries. Analyze, experiment, and don’t over-do it. The shotgun approach is not appropriate for database optimization.

    Documentation

    • MySQL EXPLAIN – http://dev.mysql.com/doc/refman/5.0/en/explain.html
    • How MySQL uses indices – http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
    • Index Merge Optimization – http://dev.mysql.com/doc/refman/5.0/en/index-merge-optimization.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realized that I can have problems with single quotes in php arrays: <?php
I realized that appears this interface in .NET Framework 4.5 I was looking first
I realized that ShowHeaderWhenEmpty only works in PostBacks. Is there any way to make
I realized that my application doesn't show up in searches on Google Play if
I just realized that this piece of code works well in Firefox but not
I just realized that the MySQLWorkBench destroys the target (makes a replacement) when performing
Today I realized that I no longer have a Web Content Form option (where
I just realized that I need to synchronize a significant amount of data collection
I just realized that the method Element.getElementsByTagName(someTagName) returns a nodelist of all elements in
I just realized that i may not be following best practices in regards to

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.