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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:02:34+00:00 2026-06-18T09:02:34+00:00

Let’s suppose that database is big. I have a very complex query for search

  • 0

Let’s suppose that database is big. I have a very complex query for search results page. In the below query, you can see that I retrieve from user_profile table some attribute value ids, the education is one attribute for example. When I have value id for attribute education, I retrieve label name for this id from array (php code) where id is array key.

  public static $education        = array(0 => 'No answer', 
                                          1 => 'High school',
                                          2 => 'Some college',
                                          3 => 'In college',
                                          4 => 'College graduate',
                                          5 => 'Grad / professional school',                                    
                                          6 => 'Post grad');     

Similar is with about 10 other attributes. Otherwise my query would be even more complex, I would need to create table attribute_id_label and make for each attribute another join to retrieve label name for value id of each attribute. This means extra 10 joins which could slow query. But still this would be the correct way.

So my question is:
If table attribute_id_label have only about 500 records. Will 10 joins with this table make any big difference since the table is very small? Even if the table user_profile is very big and the query is already quite complex as you see?

And here is my query:

    SELECT 
    group_concat(DISTINCT looking.looking_for SEPARATOR ',') as lookingFor, 
    group_concat(DISTINCT photo.photo ORDER BY photo.photo_id DESC SEPARATOR ',') as photos, 
    profile.user_id as userId, 
    url as profileUrl, 
    nickname, 
    avatar.photo, 
    city, 
    ethnicity, 
    education, 
    occupation, 
    income, 
    //and 10 more fields like education, occupation, ethnicity...
    FROM user_profile profile 
    LEFT JOIN user_profile_photo photo ON photo.user_id=profile.user_id 
    LEFT JOIN user_profile_photo avatar ON avatar.photo_id=profile.photo_id 
    INNER JOIN user_profile_looking_for looking ON looking.user_id=profile.user_id 
    LEFT JOIN user_profile_txt txt ON txt.user_id = profile.user_id 
    INNER JOIN place a ON a.place_id=profile.place_id 
    INNER JOIN (SELECT lat, lon FROM place WHERE place_id = :place_id) b ON (3959 * acos( cos( radians(b.lat) ) * cos( radians( a.lat ) ) * cos( radians( a.lon ) - radians(b.lon) ) + sin( radians(b.lat) ) * sin( radians( a.lat ) ) ) ) < :within 
    GROUP BY profile.user_id LIMIT 0,12 

Most attributes won’t be filled by user and since you advise non-NULLable, what would be the best to use for those unfilled attributes? I can use for each attribute extra field No answer. Each attribute would have extra value No answer. Let’s give attributes education and want for example. Attribute education have id 1, want is 2.

eav_attribute_option 
option_id | attr_id | label 
1 | 1 | No answer 
2 | 1 | High school 
3 | 1 | ...  
4 | 2 | No answer 
5 | 2 | Opportunities 
6 | 2 | ... 

But now the problem is repeated No answer value for each attribute. But this is the way to avoid NULL values. I am not sure if this is correct.

  • 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-18T09:02:35+00:00Added an answer on June 18, 2026 at 9:02 am

    I have done a lot of this kind of codelist work. It typically helps performance more than it hurts. @alxklx pointed out the truth: that you must make sure your codelist tables (e.g. education) are well formed. That is,

    • the education_id column must be the unique primary key in the codelist table.
    • the education_id column should be a simple primitive data type. That is, make it an int instead of a decimal or varchar.
    • when education_id shows up in your data tables, it must be the same datatype that you use in the codelist table, and it must be non-NULLable. In other words, don’t use NULL in your data table to indicate missing data.

    If you do these things your JOINs can look this simple

      FROM people p
      JOIN education e ON p.education_id = e.education_id
    

    and the RDBMS’s optimizer knows they’re straightforward 1:1 joins.

    All that being said, any complex query needs to be examined both for functionality and performance before you put it into a live system.

    If you have missing data in your people use an education_id (or some other attribute_id) of either zero or one. Put a row in each codelist table with id zero or one and a value of “unknown” or “user didn’t tell us” or whatever makes sense. (You can choose either zero or one based on convenience for your application. I prefer zero, but that’s just personal preference.)

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

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's suppose that we have multi-site CMS and every website in this CMS having
Let suppose I have this class diagram in UML: How can I do, in
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I have a table with a Color column. Color can have various
Let's say for a moment that I have the following module in python: class
Let's say I have to use an ASP master page and setup a Kendo
Let's say I have some text as follows: do this, do that, then this,
Let's say, I have a .NET 2 installed. Can I programmatically install version 4

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.