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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:05:49+00:00 2026-06-14T19:05:49+00:00

I have a query which seems to be taking a long time to run

  • 0

I have a query which seems to be taking a long time to run on occasion. The slowness may be unrelated but I wanted to check what could be done to make this more efficient.

The user table has about 40k rows. The code table has about 30k rows. user_id and code are unique values.

SELECT * 
FROM `user`, code 
WHERE `user`.user_id = code.user_id 
AND code.code = '50816ef96210415d1cad824bdb43';

I have an index setup on the code.user_id field. Anything else I can do? Should I have other indexes in place here?

Output from EXPLAIN on that query:

>> +----+-------------+-------+--------+---------------+---------+---------+----------------------+-------+-------------+
>> | id | select_type | table | type   | possible_keys | key     | key_len | ref                 | rows  | Extra       |
>> +----+-------------+-------+--------+---------------+---------+---------+----------------------+-------+-------------+
>> |  1 | SIMPLE      | code | ALL    | user_id       | NULL    | NULL    | NULL                 35696 | Using where | 
>> |  1 | SIMPLE      | user  | eq_ref | PRIMARY       | PRIMARY | 4       | mydb.code.user_id |     1 |             | 
>> +----+-------------+-------+--------+---------------+---------+---------+----------------------+-------+-------------+
>> 2 rows in set (10.11 sec)
  • 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-14T19:05:50+00:00Added an answer on June 14, 2026 at 7:05 pm

    You also need to add indexes on code.code and user.user_id fields, and it should start flying

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

Sidebar

Related Questions

I have the following xpath query which seems to be working but I just
I have this query which is a dependant query and taking much execution time
I have such problem which seems to be common, but in fact none of
I have the following MySQL query which seems to be consuming an inordinate amount
I have this query which on executing in my sql command line client executes
I have a query which returns two rows of data as count. I want
I have this query which groups the results by ORDER#. SELECT ORDER#, MAX(SHIPDATE -
I have a query which looks like this: SELECT LossCost, CoverageID FROM BGILossCost] WHERE
I have a query which produces a list of orders like this: Invoice Description
I have this query which works correctly in MySQL. More background on it here

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.