Jump to content

Multicolumn index and searching


ejaboneta

Recommended Posts

I'll try to provide as much details as possible. I'm creating a database of people with dynamic fields. To achieve this, I've created tables for `people`,`fields` and `values`.

  • people: has an id and name
  • fields: has an id and field name
  • values: has an id, peopleid, fieldid, value, and delta(because there may be multiple values for certain fields)

 

 

The index on the `values` table is set up with peopleid,fieldid,delta.

 

Question 1: is this the best way to index the table?

 

Question 2: if I wanted to search the table for first name(fieldid=0) and last name(fieldid=1), is this the best way to do it?

SELECT f0.peopleid FROM `values` f0 JOIN `values` f1 ON f0.peopleid=f1.peopleid WHERE (f0.fieldid= 0 AND f0.value='John') AND (f1.fieldid= 1 AND f1.value='Doe')

Please also let me know if there is a better way to structure the database and any other tips. Thank you.

Edited by ejaboneta
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.