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

  • Home
  • SEARCH
  • 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 7558803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:28:00+00:00 2026-05-30T12:28:00+00:00

What is best practice, what delivers the best performance? I currently have a query

  • 0

What is best practice, what delivers the best performance?

I currently have a query with many LEFT JOINs that fetches a user and all his data, like friends, friend requests, and so on:

SELECT
    `user`.`id` AS `user_id`,
    `user`.`name` AS `user_name`,
    `manager`.`id` AS `manager_id`,
    `competition`.`id` AS `manager_competition_id`,
    `competition`.`name` AS `manager_competition_name`,
    `competition`.`week` AS `manager_competition_week`,
    `country`.`id` AS `manager_competition_country_id`,
    `country`.`name` AS `manager_competition_country_name`,
    `club_template`.`id` AS `manager_club_template_id`,
    `club_template`.`name` AS `manager_club_template_name`,
    `club`.`id` AS `manager_club_id`,
    `club`.`name` AS `manager_club_name`,
    `club`.`ready` AS `manager_club_ready`,
    `friend`.`friend_id` AS `friend_id`,
    `friend_user`.`name` AS `friend_name`
FROM
    `users` AS `user`
LEFT JOIN
    `managers` AS `manager`
ON
    `manager`.`user_id` = `user`.`id`
LEFT JOIN
    `competitions` AS `competition`
ON
    `competition`.`id` = `manager`.`competition_id`
LEFT JOIN
    `countries` AS `country`
ON
    `country`.`id` = `competition`.`country_id`
LEFT JOIN
    `club_templates` AS `club_template`
ON
    `club_template`.`id` = `manager`.`club_template_id`
LEFT JOIN
    `clubs` AS `club`
ON
    `club`.`id` = `manager`.`club_id`
LEFT JOIN
    `friends` AS `friend`
ON
    `friend`.`user_id` = `user`.`id`
LEFT JOIN
    `users` AS `friend_user`
ON
    `friend_user`.`id` = `friend`.`friend_id`
WHERE
    `user`.`id` = 1

As you can see, it’s a very big query. My reasoning behind this was that it’s better to have just one query that can be done in one API request, like this…

/api/users/1

…versus a few queries, each in their own API request, like this…

/api/users/1
/api/users/1/friends
/api/users/1/friend_requests
/api/users/1/managers

But now I’m worried, that since it’s become such a huge query that it will actually hurt performance more than to split it up in separate API requests.

What will scale better?

Update

I’ve changed the query to the full query. This is not the final query; I plan to add even more joins (or not, depends on the answer).

Each table has a PRIMARY KEY on id. All association columns (competition_id, club_id, and so on) have a regular INDEX. The database engine is InnoDB.

  • 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-05-30T12:28:01+00:00Added an answer on May 30, 2026 at 12:28 pm

    Of the two, I would recommend the latter: many niche queries. It gives the caller flexibility to pull back just what they want, and is less likely to silently introduce performance problems (e.g. only one option to retrieve data, so everyone uses it no matter how small a subset of that data they’re actually interested in).

    That said, it certainly isn’t immune from performance problems, it just means the caller may be more aware of them by virtue of issuing so many API calls.

    You could provide both though. Make it clear from your naming convention that the expensive version pulls back all data and is for use when the user might otherwise need to make, say, 20 – 30 calls to get the full picture.

    Examples:

    1 – imagine having to get that full user object just to find out the name. Really wasteful. And if done inadvertently in a big loop, a performance trap waiting to happen. Prefer a getUserName(id) method that just reads that one value back.

    2 – on the other hand, if you want to display the user’s full profile in a page, then a full getFullUserProfile(id) is most efficient (1 call rather than 10 – 20).

    Edit – a further useful example. Anticipate where many values are sought, e.g. rather than force the caller to run getUserName(id) 500 times to get all names for a certain condition (all admin users perhaps?), provide a List<String> getAdminUserNames() which provides all that data in one call.

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

Sidebar

Related Questions

I understand that the best practice now with Django 1.4 is to store all
The best practice seems to be to use assert for a condition that should
What's the best practice for making sure that certain ajax calls to certain pages
what is the best practice to avoid SQL injections. I have ran a McAfee
What is the best practice about HTML tags in internationalized strings. Is that OK
Another best-practice question to those with experience: How many models do you put in
What's the best practice for scoped search that will end up in the view
What is a best practice? To use try or use rescue ? user.try(:email) VS
What is the best practice for implementing a database revisioning? Assume i have a
What is the best practice for referencing nested objects? Let's say I have the

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.