I'm developing a site (MLM) where there are around 155000 rows in "memberdata" table with 63 column. All member searches frequently from that table for different Data. my SQL query is like:
$search=htmlentities($_POST['search_field']); /// The field which will be selected
$value=htmlentities($_POST['search_value']); /// The value which will be compared
SELECT * FROM memberdata WHERE $search='$value' AND (senior='".$_SESSION['id']."' OR id > '".$_SESSION['id']."')
But no field is indexed except "id". "id" is "PRIMARY with AUTO_INCREMENT".
My query is takes too long time and sometime shows "maximum server execution time 30 sec exceeded" etc. what should I do? how can I make my query faster without indexing ? i'm on Apache server at shared host.
Why you don't want to add indexes? You can always do some tricks to fasten things up but it would never be as fast as an index.
As for answering your actual answer, you can try to narrow as far as you can the search in the database by removing the unnecessary fields from the SELECT
/ WHERE
clauses. Or try to do many smaller queries instead of a big one... I'm afraid you will have to try some solutions and then do some benchmarking on them to select the best one for your setup.
But adding indexes is way simpler and faster (but will not fix magically a bad database design / bad application).
Why not select the fields you need instead of all of them? you won't need the field that auto increments. The more things you leave out of your search the quicker the search will become because that is a lot less data it has to go through.