As for SQL, you should strive to write down your search terms in conjunctive normal form ("sentence sir AND"). There are various rewriting rules to help with this.
In this case , the rewrite distribution law is useful , i.e.
( P AND Q ) OR R <=> ( P OR R ) AND ( Q OR R )
In your case:
( isinvoiced = 0 ) OR ( isinvoiced = 1 AND isrecurring = 1 )
can be rewritten as:
( isinvoiced = 0 OR isinvoiced = 1 ) AND ( isinvoiced = 0 OR isrecurring = 1 )
Therefore, the entire search term without bulky pars:
....
WHERE client = $id
AND ( isinvoiced = 0 OR isinvoiced = 1 )
AND ( isinvoiced = 0 OR isrecurring = 1 );
source
share