iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2004, 08:47 PM
WebProWorld New Member
 
Join Date: Oct 2004
Location: sb in us
Posts: 12
dr.p RepRank 0
Default Large Search Index

I need help, all you gurus. I'll try to give you as clear a picture as I can, of what I have.

Very large images table with several fields that contain keywords/phrases that are searchable (currently contains ~320K records). Each image has image_id auto_incremented field.

The words from the required fields in each image record are pulled and stored in a word list table (contains ~330K records), where each record is (word_id, word_text).

And a match table is created, where word_id and image_id are stored, and the field(s) (from the images table) contain a 0 or 1 depending on their match status. So, if image_field1 in image_table matches word_id, then match_table's image_field1=1. The match table contains ~6 million records.

The search script (in PHP) takes 5+ seconds to do a query like:

Code:
SELECT image_id FROM match_table WHERE word_id=###
I've racked my brains trying to get this one query sped up. match_table has a key for (word_id, image_id).

Any ideas at all as to how to speed up a query like this?
Reply With Quote
  #2 (permalink)  
Old 12-02-2004, 05:57 PM
Guest
 
Posts: n/a
Default

hi dr.p,

Is there any way your search results can be cached in the database to speed up popular searches?

You may wish to see if you can integrate your php search program with the phpCache program at:

http://0x00.org/php/phpCache/

I hope this helps.
Reply With Quote
  #3 (permalink)  
Old 12-03-2004, 06:17 AM
WebProWorld Member
 
Join Date: Nov 2004
Posts: 33
imported__sam_ RepRank 0
Default

Hello Dr.P.

Are you using MySQL? If so, try examining the query via "EXPLAIN", to make sure the index is used. In your case, there should be even no access to the actual table, because image_id is also in the index. If that's the case, thre is nothing you can do to make it faster from an index design point of view. You have to dig into the MySQL configuration parameters, which perhaps are not optimized for large tables.

I wonder, however, why you store word/image combinations that do not match (match status 0). A straightforward implemetation would be to store only the matching pairs, which would make your table smaller and faster.

best regards

Sam
__________________
Software-Pointers.com - Directory of Software Development Sites - Free submission.
Reply With Quote
  #4 (permalink)  
Old 12-03-2004, 09:39 AM
WebProWorld New Member
 
Join Date: Oct 2004
Location: sb in us
Posts: 12
dr.p RepRank 0
Default

Thanks for your replies. I've tried the explain command before, and it didn't explain much... yeah I'm using MySQL, btw. I will dig into the setup, though, as much as I can.

As for caching, it was caching before, but that wasn't helping the speed at all... tho, I'm sure caching in the right way will help.

Thanks again.
Reply With Quote
  #5 (permalink)  
Old 12-04-2004, 01:27 AM
WebProWorld New Member
 
Join Date: Oct 2004
Location: sb in us
Posts: 12
dr.p RepRank 0
Default Problem Fixed!

I had a combined index/key image_word_id (word_id, image_id) on the table with 5million records. Removed that and added individual keys word_id and image_id, and the speed issue is gone! Is there a heads up in the MySQL docs that I missed about this?

Thanks again for your help.
Reply With Quote
  #6 (permalink)  
Old 12-04-2004, 01:04 PM
WebProWorld Member
 
Join Date: Nov 2004
Posts: 33
imported__sam_ RepRank 0
Default Re: Problem Fixed!

Quote:
Originally Posted by dr.p
I had a combined index/key image_word_id (word_id, image_id) on the table with 5million records. Removed that and added individual keys word_id and image_id, and the speed issue is gone! Is there a heads up in the MySQL docs that I missed about this?
Nothing I'm aware of. On the contary, in the section "How MySQL Uses Indexes" it says:

Quote:
If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to find rows.
which means, your original index should work fine, and I personally never had a problem with such indexes not being used.

At least, you got it working, best regards

Sam
__________________
Software-Pointers.com - Directory of Software Development Sites - Free submission.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:25 AM.



Search Engine Optimization by vBSEO 3.3.0