Jump to content

Recommended Posts

Dear friends,

    I have a requirement to search based on all the fields in a table. How can I manage the index in the table.

 

For example, consider a table has,

name, id, class, sub-class, section, rank, priority and more.

 

I have to provide a option to search by all the the columns.

If I have to search by one column, I will set the index to the column for efficiency. But, here the requirement is to search by all the fields in the table.

 

Kindly help me in the above..,

Link to comment
https://forums.phpfreaks.com/topic/136205-how-to-design-the-database/
Share on other sites

You can put one index on each column (eg, if you have 10 columns then you have 10 indexes).  This means that an insert or update must update all 10 indexes though, so insert and update will be much slower.

 

If you are using a recent version of postgres then multi-column searches can also take advantage of multiple indexes.

I'm not sure if this is just the words, but it's not multi-column indexes I'm suggesting, it's multiple single-column indexes.

 

A multi-column index is like

 

CREATE INDEX tab_id_name_idx ON tab (id, name)

 

Multiple single column indexes

 

CREATE INDEX tab_id_idx ON tab (id)

CREATE INDEX tab_name_idx ON tab (name)

 

The multi-column index is usually only useful for queries involving id, but the two seperate indexes can also be used for queries on name, as well as queries on both name and id.

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.