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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:26:58+00:00 2026-05-19T02:26:58+00:00

I need some advice regarding how to organize my data for effective and fast

  • 0

I need some advice regarding how to organize my data for effective and fast text search.

Background

I have an application (in PHP) where the user can organize articles and dynamically create forms and fields for that purpose. Meaning that one article can for example have Type,Brand,Color attributes and another article can for example have Type,Material,Color,Content as attributes.
The user can basically create as many attributes he likes…

Then I need to be able to search and sort among these “unknown” attributes.
I also need to be able to read back all the attributes in the case the user want to edit the article.

My solution

My first idea (and so far only idea) is to encode all the attributes into a single TEXT field with a FULLTEXT index (needs to be MyISAM to work), like:

__Type="3",__Brand="Nokia",__Color="6"
__Type="2",__Material="7",Color="2",Content="MP3 Player,2 Apples, 1 book: Larry King"

The attributes would get a prefix and/or postfix to not be confused with the values in the attributes. Or serialize the attributes with JSON.

Then I can build a query based on the selected attributes like:

SELECT * FROM Articles a
WHERE Attribute LIKE '%__TYPE="2"%'
AND Attribute LIKE '%__Color="2"%'

If an attribute is empty, it will not be included and this makes it possible to include a search on all articles that has a specific attribute set, regardless of its value.

Problem

Problem or not, what I’m worried about is the search performance when the database is filled with thousands of articles.

Another problem would also be to search for a particular word inside a specific attribute, such as:

Content=”MP3 Player,2 Apples, 1 book: Larry King”

Let’s say I only want to get rows where the attribute Content have the phrase “Larry King” somewhere. I don’t think I can do that in the same SQL question without getting a match on all rows that has “Larry King” somewhere.

I’m open for any kind of suggestion/discussion regarding what tables,fields and relations I should create to achieve the goals explained.

Thank you.

  • 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-19T02:26:58+00:00Added an answer on May 19, 2026 at 2:26 am

    If you are going to be often searching on the value of a particular attribute, why not make those attributes their own columns in the table? Or if you want a more flexible structure, make a second table like:

    CREATE TABLE attributes (
     my_id int unsigned not null default 0,
     attribute_key varchar(255) not null default '',
     attribute_value varchar(255) not null default '',
     KEY (my_id),
     KEY (attribute_key),
     KEY (attribute_value)
    );
    

    In this case, the my_id field is the primary key of your main table. So rather than serializing a string like:

    __Type="2",__Material="7",Color="2",Content="MP3 Player,2 Apples, 1 book: Larry King"
    

    You would instead create some rows like:

    INSERT INTO attributes VALUES (1, 'Type', '2');
    INSERT INTO attributes VALUES (1, 'Color', '2');
    INSERT INTO attributes VALUES (1, 'Content', 'MP3 Player,2 Apples, 1 book: Larry King');
    

    And then you would formulate your search query like:

    SELECT * FROM mytable 
    LEFT JOIN attributes ON mytable.my_id = attributes.my_id 
    WHERE attributes.attribute_key = 'Type' AND attributes.attribute_value = '2';
    

    This does not precisely solve the second problem of your question, but it will perform far, far better than doing a full text search across thousands of rows. You can of course then add a FULLTEXT index on the attribute_value field as well to query it for text fragments like your “Larry King” example.

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

Sidebar

Related Questions

I need some advice for a design which I have to implement in application.
Need some advice again please. This is regarding a single developer shop. I have
I need some advice regarding which database I should use. I want to create
I need some advice of how to setup my tables I currently have a
I need some advice from experts :) I will develop a website using PHP
im facing a problem where i need some advice. I want to have a
I need some advice regarding updating a large number of records in a MySql
Just after some advice regarding this database design situation. So I have two tables
I need an explanation regarding some advice I got on this site. I'm doing
I need some advice regarding conversion of an AJAX TreeView control to a LinkButton

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.