If I’ve a statement:
select .. from .. where condition;
And I know beforehand the maximum number of times the condition can be false. How can I tell MySQL this number to increase performance? So that after the condition has been false that many times (while selecting the records), MYSQL will assume the condition to be true for the rest of the records.
Edit:
I don’t know what’s missing in my question. I’ll fill up the blanks:
select * from t where c3 > c2;
Here I know beforehand that out of 50 records there are only 5 records where the condition ‘c3 > c2’ is false. Can I and should I tell MySQL this number ‘5’ to increase the performence of this select statement? So that while executing this select statement, after this condition (c3 > c2) has been falsed 5 times, MySQL will ignore this condition for the rest of the records and will select all the records from then on.
The simple answer is you can’t.
But the thing you can do in your quest for performance is smart database design and well placed indexes.
MySQL “preformats” index columns so that it can check your where constraints against these columns very fast.
The MySQL website ( http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html ) list a few reasons why you should use indexes of which the top two are listed below, but you should read through all of that page:
To find the rows matching a WHERE clause quickly.
To eliminate rows from consideration. If there is a choice
between multiple indexes, MySQL normally uses the index that finds the
smallest number of rows
Also a simple example of how to build smarter tables could be that instead of storing the name “John Doe” in one column you could store it in two so that you can search for anyone with the last name “Doe” without splitting or doing LIKE searches.
You should try to avoid conditions such as LIKE as these are slow and tedious no matter how you write them.
Among the fastest columns to do logic on are integer and float columns.