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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:42:44+00:00 2026-06-11T18:42:44+00:00

I have query: EXPLAIN SELECT * FROM _mod_news USE INDEX ( ind1 ) WHERE

  • 0

I have query:

EXPLAIN SELECT * FROM _mod_news USE INDEX ( ind1 )  WHERE show_lv =1 AND active =1 AND START <= NOW( ) 
AND ( END >= NOW( )  OR END =  "0000-00-00 00:00:00" ) AND id <>  "18041" AND category_id =  "3" AND leta =1 ORDER BY sort_id ASC , DATE DESC  LIMIT 7

result:

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  _mod_news   ref ind1    ind1    2   const,const 11386   Using where; Using filesort

mysql is performing full table scan

ind1 =

ALTER TABLE `_mod_news` ADD INDEX ind1 ( `show_lv`, `active`,  `start`, `end`, `id`, `category_id`, `leta`, `sort_id`, `date`);

I tested on following index, but nothing changes

ALTER TABLE `_mod_news` ADD INDEX ind1 ( `show_lv`, `active`,  `start`, `end`, `id`, `category_id`, `leta`);

Question is: where i can learn how to create indexes on many where conditions? Or someone can explain how to tell to mysql to use and index and not to scan whole table.
Thanks.

  • 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-11T18:42:45+00:00Added an answer on June 11, 2026 at 6:42 pm

    I would suggest not forcing index. Mysql is a great at selecting the best possible index unless you have better understanding of the data you are querying.

    You cannot use ORDER BY optimization because you are mixing the ASC and DESC in that part.

    Therefore your only option is to create index such that:

    • constant values before range
    • integers before dates, dates before strings, smaller size vales before bigger size values

    Creating a large index also adds an overhead to storage and insert-update time, so i would not add to index fields that are not eliminating a lot of rows (i.e 90% or rows have a value of 1 or i.e id<>"18041" but that most likely eliminates < 1% of rows).

    If you want to learn more about optimizing: http://dev.mysql.com/doc/refman/5.0/en/select-optimization.html

    Create multiple different indexes (on decent size of data you expect seeing in the table), see which one mysql chooses, benchmark them by forcing each one of them, then use your common sense to cut down on index space usage.

    You can see from you EXPLAIN output that it is actually NOT performing a full table scan because in that case it would not display it using the index even when you are forcing it.

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

Sidebar

Related Questions

I have the following mysql query: EXPLAIN SELECT id, name, title, description, time FROM
I have this query: SELECT `country` FROM `geoip_base` WHERE 1840344811 BETWEEN `start` AND `stop`
I have the following query: EXPLAIN EXTENDED SELECT * FROM ( `photo_data` ) LEFT
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
i have a query that goes like this: SELECT * FROM table_a LEFT JOIN
I have the following query I am trying to optimize. EXPLAIN select clb.f_name, clb.l_name,
Have follow query: SELECT tbl_yaca_sites.`id_site` FROM `tbl_yaca_sites` INNER JOIN `tbl_relation` ON tbl_relation.id_website = tbl_yaca_sites.id_site
I have the following query: SELECT AVG(time) FROM (SELECT UNIX_TIMESTAMP(max(datelast)) - UNIX_TIMESTAMP(min(datestart)) AS time
I have this query: SELECT * FROM table WHERE x >= 500 AND x
I have the following query: SELECT * FROM shop_user_member_spots WHERE delete_flag = 0 ORDER

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.