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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:16:54+00:00 2026-05-13T06:16:54+00:00

I feel like this question has probably been asked a thousand times already, so

  • 0

I feel like this question has probably been asked a thousand times already, so I apologize if it’s been answered. And if so, can someone point me to the right posts/links?

What I’m trying to do is build a faceted navigation for my site. It uses MySQL and here’s a rough sketch of the tables I’m using:

products:
- id
- title
- description
attributes:
- product_id
- name
- value
categories:
- id
- name
products_to_categories:
- product_id
- category_id

What I want to do is display a list of available attributes when you are in a category, allowing you to select one or more values for each of those attributes. To give you an example, look at this page from Office Depot: http://www.officedepot.com/a/browse/binders/N=5+2177/

So far I’ve used a lot of joins to filter on multiple attributes:

SELECT products.*, a_options.*
FROM products_to_categories AS pc, products,
attributes AS a_options,    /* list of attribute/value pairs I can continue to refine on */
attributes AS a_select1     /* first selected attribute */
attributes AS a_select2     /* second selected attribute */
...
WHERE pc.category_id = 1
AND products.id = pc.product_id
AND a_options.product_id = products.id
AND a_options.name != 'Color' AND a_options.name != 'Size'
AND a_select1.product_id = products.id
AND a_select1.name = 'Color' AND (a_select1.value = 'Blue' OR a_select1.value = 'Black')
AND a_select2.product_id = products.id
AND a_select2.name = 'Size' AND a_select2.value = '8.5 x 11'

Basically a_options will return all the attributes for those products that are a subset of the filters I’ve applied using a_select1 and a_select2. So if I use the Binders example from Office Depot, I want to show all available attributes after selecting Blue or Black for Color and “8.5 x 11” for the Size.

I then use PHP code to remove duplicates and arrange the resulting attributes into an array like this:

attributes[name1] = (val1, val2, val3, ...)
attributes[name2] = (val1, val2, val3, ...)

Is there a way I can speed up my query or write it more efficiently? I have setup indexes on the name and value in the attributes table (and also on all the ID numbers). But if someone selects a couple of attributes, then the query runs slow.

Thanks for your help in advance,
Sridhar

  • 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-13T06:16:55+00:00Added an answer on May 13, 2026 at 6:16 am

    “I then use PHP code to remove duplicates”

    It will not scale then.

    After I read http://www.amazon.com/Data-Warehouse-Toolkit-Techniques-Dimensional/dp/0471153370 I was rolling out facets & filtering mechanisms non stop.

    The basic idea is you use a star schema..

    You create a fact table that stores facts

    customerid | dateregisteredid | datelastloginid
    1 | 1 | 1
    2 | 1 | 2
    

    You use foreign keys into dimension tables that store attributes

    date_registered
    Id | weekday | weeknumber | year | month | month_year | daymonth | daymonthyear
    1 | Wed      | 2            | 2009 | 2   |2-2009      | 4        | 4-2-2009
    

    Then whichver date “paradigm” you are using, grab all the ids from that dimension table and

     select * from the fact table where the fact.dateregisteredid is IN( ... the ids from the date dimension table that represent your time period)
    

    These “indexed views” of your data should reside in a seperate database, and a change to an object in production should queue that record for re-indexing in the analytics system. Large sites might batch their records at non-peak times to the stats reporting application always lags behind a few hours or days. I always try to keep it up to the second, if the architecture supports it.

    If you are displaying rowcount previews, you might have quite some optimization or caching to implement as well.

    Basically to sum it up, you copy data and denormalize. The technique goes by the name “data warehousing” or OLAP (online analytics processing).

    There are better ways, using commercial databases like Oracle, but the star schema makes it available to anyone with an open source relational database and some time.

    You should definitely read the toolkit but he discusses a lot of things that can save you considerable time. Like strategies for dealing with updated data, and retaining audit history in the reporting application. For every problem he outlines multiple solutions, each of which are applicable in different contexts.

    It can scale up to millions of rows if you don’t take the easy ways out and use a ton of needless joins.

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

Sidebar

Related Questions

I feel like this one has been asked before, but I'm unable to find
First of all I'm sorry if you feel this question has been raised before,
I feel like this question has a really easy answer and I'm just overlooking
I've seen this question but feel like there has to be a cleaner jQuery
I feel like this is a stupid question because it seems like common sense
I feel like this is a dumb question and I'm missing something, but I
I feel like I should know this, but I haven't been able to figure
I know that the question has been asked before , but it's been two
This question probably has no definite answer, so if it's considered subjective and, let's
I was originally going to make this a longer question, but I feel like

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.