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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:38:57+00:00 2026-06-10T07:38:57+00:00

I have the following mysql query select points_for_user from items where user_id = ‘38415’;

  • 0

I have the following mysql query

select points_for_user from items where user_id = '38415';

explain on the query returns this

id  select_type table   type    possible_keys   key                     key_len ref     rows    Extra
1   SIMPLE      items   index   NULL            points_for_user_index   2       NULL    1000511 Using index

The problem is, shouldn’t the number of rows be FAR less then the number of rows in the table because of the index?

user_id is the primary index, so I tried creating an index on just points_for_user and that still look through every row. An index on user_id AND points_for_user still searches every row.

What am I missing?

Thanks!

CREATE TABLE IF NOT EXISTS `items` (
  `capture_id` int(11) NOT NULL AUTO_INCREMENT,
  `id` int(11) NOT NULL,
  `creator_user_id` bigint(20) NOT NULL DEFAULT '0',
  `user_id` int(11) NOT NULL,
  `accuracy` int(11) NOT NULL,
  `captured_at` timestamp NOT NULL DEFAULT '2011-01-01 06:00:00',
  `ip` varchar(30) NOT NULL,
  `capture_type_id` smallint(6) NOT NULL DEFAULT '0',
  `points` smallint(6) NOT NULL DEFAULT '5',
  `points_for_user` smallint(6) NOT NULL DEFAULT '3',
  PRIMARY KEY (`capture_id`),
  KEY `capture_user` (`capture_id`,`id`,`user_id`),
  KEY `user_id` (`user_id`,`id`),
  KEY `id` (`id`),
  KEY `capture_creator_index` (`capture_id`,`creator_user_id`),
  KEY `points_capture_index` (`points_for_user`,`creator_user_id`),
  KEY `points_for_user_index` (`points_for_user`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1008992 ;

select count(*) from items where user_id = '38415'

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  captures    ref user_munzee_id  user_munzee_id  4   const   81  Using index
  • 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-10T07:38:59+00:00Added an answer on June 10, 2026 at 7:38 am

    the mysql optimizer try to use the best possible index during the query.

    In your first query the optimizer is considering points_for_user_index the best choice, in fact the Extra column show the “Using index” status, this means a “Covering index”.

    The “Covering index” occurs when all fields required for a query (in your case select points_for_user from … ) are contained in an index, this avoid the access to the full mysql data (.MYD) in favour of the direct index access (.MYI)

    First of all you can try to rebuild the index tree analyzing table

    ANALYZE TABLE itemes;

    Note for very large tables:

    ANALYZE TABLE analyzes and stores the key distribution for a table.
    During the analysis, the table is locked with a read lock for InnoDB
    and MyISAM. This statement works with InnoDB, NDB, and MyISAM tables.
    For MyISAM tables, this statement is equivalent to using myisamchk
    –analyze.

    If “the problem” persist and you want to bypass the optimizer choice you can explicit try to force the usage of an index

    EXPLAIN SELECT points_for_user FROM items USE INDEX ( user_id ) WHERE user_id = '38415'
    

    More details: http://dev.mysql.com/doc/refman/5.5/en/index-hints.html

    Cristian

    • 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 statement: SELECT * FROM table1 INNER JOIN table2
I have the following mysql query: $manufacturers_query = select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, mi.manufacturers_url from
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have the following query to select users and their locations, etc from MySQL
I have a problem with the following MySQL query: SELECT * FROM TPDSessions WHERE
I have following MySQL query: (SELECT c.Channel as name, count(*) as total_episode FROM (
I have the following MySQL-query: SELECT s.student_socialnr, s.student_lastname, s.student_firstname, cs.city_name, scp.cpl_startdate, scp.cpl_enddate, scp.cpl_invoice, cu.customer_name,
I have the following query: $result = mysql_query("SELECT option_value FROM wp_10_options WHERE option_name='homepage'"); $row
I have the following which returns soccertennisfootball $interestsquery = SELECT * FROM user_interests WHERE
I have the following query: $sql = SET @rownum := 0; SELECT * FROM

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.