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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:08:50+00:00 2026-05-13T14:08:50+00:00

I need to attach unlimited attributes to a record in a table, and I’ve

  • 0

I need to attach unlimited attributes to a record in a table, and I’ve already designed a system using #3 below using mysql. Unfortunately I am finding that searching across a million records is getting slow. Is #2 a better approach, or is there a better way alltogether? Is this a case for using a view? I’d like to have my keys table separate so I know what attributes are being stored for each record.

1: simple:

table records: id, recordname, valname

select recordname from records where valname = 'myvalue'

2: a little more complex:

table records: id recordname
table keyvalues: id recordid keyname valname

    select r.recordname 
    from records r
    right join keyvalues kv on kv.recordid = r.id 
       and kv.keyname='mykey' 
       and kv.valname = 'myvalue'

3: most complex:

table records: id recordname
table keys: id keyname
table values: id recordid keyid valname   

 select r.recordname 
    from records r
    right join keys k on k.keyname='mykey'
    right join values v on v.recordid = r.id 
       and v.keyid = k.id 
       and v.valname = 'myvalue'
  • 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-13T14:08:51+00:00Added an answer on May 13, 2026 at 2:08 pm

    I would use inner joins. This will give a smaller result set and the one you want.

    Did you try this query?

    select r.recordname
    from records r
    left join values link on link.recordid = r.id and link.valname = 'myvalue'
    left join keys k on r.keyid = link.key.id and k.keyname = 'mykey'
    

    However, I think the real way to do it is to have 4 tables

    table records: id recordname
    table keys: id keyname
    table values : id valuename
    table joins : id recordid keyid valueid
    

    Then (with the right indexes) you can have a query like this

    select r.recordname
    from joins j
    left join records r on j.recordid = r.id
    left join keys k on j.keyid = k.id
    left join values v on j.valueid = v.id
    where v.valuename = 'myvalue' and k.keyname = 'mykey'
    

    This should be quite fast… all it has to do is find the id in values and keys and then do a scan on j. If you have the right indexes these will be quick.

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

Sidebar

Related Questions

I need to attach a single event handler to multiple DOM elements using jQuery.
When debugging, sometimes you need to attach an already running process instead of just
I've a listview and i need to attach this listview table into FlowDocumentReader, can
i am trying to traverse a node attributes ..in below xml ,i need to
I need to attach a file with mailx but at the moment I am
I need to attach some javascript to the onchange event of the Zend_Form_Element. How
I need to attach text labels to objects that are spread randomly across the
Lets say you need to attach some JavaScript functionality to an ASP.NET User Control
When I attach functionality to an element do I need to call .widgetName('destroy') before
Normally to attach a debuger to a running jvm you would need start 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.