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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:43:31+00:00 2026-06-09T09:43:31+00:00

I have a table ‘posts’ in database which has non-unique index on user_id (Key:

  • 0

I have a table ‘posts’ in database which has non-unique index on user_id (Key: MUL).

mysql> show columns from posts;
+---------+--------------+------+-----+-------------------+----------------+
| Field   | Type         | Null | Key | Default           | Extra          |
+---------+--------------+------+-----+-------------------+----------------+
| id      | int(11)      | NO   | PRI | NULL              | auto_increment |
| user_id | int(11)      | YES  | MUL | NULL              |                |
| post    | varchar(140) | NO   |     | NULL              |                |
+---------+--------------+------+-----+-------------------+----------------+

For this table, explain gives expected explanation where type is ‘REF‘

mysql> explain select * from posts where posts.user_id=1;
+----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key     | key_len | ref   | rows | Extra       |
+----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+
|  1 | SIMPLE      | posts | ref  | user_id       | user_id | 5       | const |   74 | Using where |
+----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+

I have a second table ‘followers’ where ‘user_id’ and ‘follower’ are part of non-unique index

mysql> show columns from followers;
+---------------+-----------+------+-----+---------------------+----------------+
| Field         | Type      | Null | Key | Default             | Extra          |
+---------------+-----------+------+-----+---------------------+----------------+
| id            | int(11)   | NO   | PRI | NULL                | auto_increment |
| user_id       | int(11)   | YES  | MUL | NULL                |                |
| follower      | int(11)   | YES  | MUL | NULL                |                |
+---------------+-----------+------+-----+---------------------+----------------+

But in this table, type is ‘ALL‘. I expected it to be ‘REF‘ as similar to ‘user_id’ in previous table, this ‘user_id’ also has non-unique index. Is there any explanation for this?

mysql> explain select * from followers where followers.user_id=1;
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table     | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | followers | ALL  | user_id       | NULL | NULL    | NULL |    6 | Using where |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
  • 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-09T09:43:33+00:00Added an answer on June 9, 2026 at 9:43 am

    I’ll post it as an answer, cause I’m pretty sure this is the case.

    I think you get differences because in followers table you have a composite key from both user_id and follower fields, rather than just a key on user_id.

    Therefore index will be used for queries that use both user_id AND follower in WHERE clause.

    Add a separate index on user_id field and you will get the same explanation.

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

Sidebar

Related Questions

I have table in my database which has fields of ID,NAME,CONTEXT. I am showing
I have table named as contacts which has nearly 1.2 million records we use
i have table question (mysql with php) which contains question,category(multiple) and subcat(multiple) its belong.
I have table in which I am inserting rows for employee but next time
I have table in an MS Access database that looks like this: ID Symbol
I have table view which is populated from an array grabbed from a url.
I have table X, and each record in X has many records in Y.
I have table Owner in my database where one of the field (System) saved
I have table A(id). I need to create table B(id) add a foreign key
I have table view which is showing list of files to download. When I

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.