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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:59:38+00:00 2026-06-17T15:59:38+00:00

In the web page that I’m working on I need to show some statistics

  • 0

In the web page that I’m working on I need to show some statistics based on a different user details which are in three tables. So I have the following query that I join to more different tables:

SELECT *
FROM `user` `u`
LEFT JOIN `subscriptions` `s` ON `u`.`user_id` = `s`.`user_id`
LEFT JOIN `devices` `ud` ON `u`.`user_id` = `ud`.`user_id`
GROUP BY `u`.`user_id`

When I execute the query with LIMIT 1000 it takes about 0.05 seconds and since I’m using the data from all the three tables in a lot of queries I’ve decided to put it inside a VIEW:

CREATE VIEW `user_details` AS ( the same query from above )

And now when I run:

SELECT * FROM user_details LIMIT 1000

it takes about 7-10 seconds.

So my question is can I do something to optimize the view because the query seems to be pretty quick or I should the whole query instead of the view ?

Edit: this is what EXPLAIN SELECT * FROM user_details returns

+----+-------------+------------+--------+----------------+----------------+---------+------------------------+--------+-------+
| id | select_type | table      | type   | possible_keys  | key            | key_len | ref                    | rows   | Extra |
+----+-------------+------------+--------+----------------+----------------+---------+------------------------+--------+-------+
|  1 | PRIMARY     | <derived2> | ALL    | NULL           | NULL           | NULL    | NULL                   | 322666 |       |
|  2 | DERIVED     | u          | index  | NULL           | PRIMARY        | 4       | NULL                   | 372587 |       |
|  2 | DERIVED     | s          | eq_ref | PRIMARY        | PRIMARY        | 4       | db_users.u.user_id     |      1 |       |
|  2 | DERIVED     | ud         | ref    | device_id_name | device_id_name | 4       | db_users.u.user_id     |      1 |       |
+----+-------------+------------+--------+----------------+----------------+---------+------------------------+--------+-------+

4 rows in set (8.67 sec)

this is what explain retuns for the query:

+----+-------------+-------+--------+----------------+----------------+---------+------------------------+--------+-------+
| id | select_type | table | type   | possible_keys  | key            | key_len | ref                    | rows   | Extra |
+----+-------------+-------+--------+----------------+----------------+---------+------------------------+--------+-------+
|  1 | SIMPLE      | u     | index  | NULL           | PRIMARY        | 4       | NULL                   | 372587 |       |
|  1 | SIMPLE      | s     | eq_ref | PRIMARY        | PRIMARY        | 4       | db_users.u.user_id     |      1 |       |
|  1 | SIMPLE      | ud    | ref    | device_id_name | device_id_name | 4       | db_users.u.user_id     |      1 |       |
+----+-------------+-------+--------+----------------+----------------+---------+------------------------+--------+-------+

3 rows in set (0.00 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-17T15:59:39+00:00Added an answer on June 17, 2026 at 3:59 pm

    Views and joins are extremely bad if it comes to performance. This is more or less true for all relational database management systems. Sounds strange, since that is what those systems are designed for, but it is true nevertheless.

    Try to avoid the joins if this is a query in heavy usage on your page: instead create a real table (not a view) that is filled from the three tables. you can automate that process using triggers. So each time an entry is inserted into one of the original tables the triggers takes care that the data is propagated to the physical user_details table.

    This strategy certainly means a one time investment for the setup, but you definitely will get a much better performance.

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

Sidebar

Related Questions

I have a web page that prompts for user input via DropDownLists in some
I created a web page that print some text using JSF I've added spaces
I have this web page that begins with <!-- DOCTYPE html --> , which
I have a static web page that I need to turn off, I don't
I'm developing a Web page that uses different sizes for its different paragraphs, h...
I have a web page that I need to check the server for an
I have a web page that also has a popup where the user can
I just built a web page that is employing several different javascript elements. I
I have a web page that i'm working on and it has only one
I've created a web page that lets you input some information and then draws

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.