Jump to content

Search overload


Thierry

Recommended Posts

I have a table with about 5000 records in it and roughly 50 fields, all with a lot of data in them.

Naturally you can search in that table, but sometimes the results seem to be more then SQL can handle, the limit seems to be around 2000 records.

Its not a question of getting the information, but having 2000 times an "OR id = '$id'" in the query.

Right now I can't think of an alternative to get all the possible returned records, since it could be anywhere between zero and 5000.

 

Any ways to get all the record id's without overloading the query with OR's?

Link to comment
https://forums.phpfreaks.com/topic/49462-search-overload/
Share on other sites

ORs are expensive.  First simply make sure you have indexes on the fields you're searching, and unique indexes where possible.  That'll help the database find records faster.  For such a small set of data this might suffice.  Also don't use LIKE conditionals unless you have to, and if you do try to not use a wildcard at the start of the field (i.e. LIKE 'smith%' instead of '%smith%').

 

If it's still too slow after all that, use the EXPLAIN statement and post the output of it here so we can investigate the details.

Link to comment
https://forums.phpfreaks.com/topic/49462-search-overload/#findComment-242432
Share on other sites

Its not the searching in the database that's the problem, its showing all the ids.

For instance, I could (in theory) have record 1,3,5,7,9 and then all the way to 5000.

The only way in which it could show all the ids then would be by using "OR id = '1' OR id = '3' etc".

 

I suppose I could do it differently, running a thousand queries with one id (using a loop) then one query with a thousand ids but I think that would be very slow loading.

Link to comment
https://forums.phpfreaks.com/topic/49462-search-overload/#findComment-247914
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.