Actually it's a simple question but I'm lacking of experience and know how about the internal optimization of a database system (in general, but T-SQL in my specific case).
Assumed I have a database with integer data fields (for simplification 1-3):
table Data (D1, D2, D3)
I have a collection of match criteria:
D1 > 3 D2 < 100 D3 all
D1 >= 50 D2 all D3 > 50
and so on...
The naive way to perform a query would be to AND
every expression of a criteria an OR
every criteria expression. But obviously an optimized query would be (see edit)D1 >= 50 and D2 < 100 and D3 > 50
So here's the question: Is a database (T-SQL in my case) able to optimize my naive query?
If not: Can someone point me to the right direction (i'm sure there must be some algorithm for that case I can't figure it out).
Edit:
Obviously the optimization assumption was wrong :-D
D1 >= 50 D2 < 100 D3 all
D1 >= 50 D2 all D3 > 50
and so on...
This one could be optimized from
D1 >= 50 and D2 < 100 or D1 >= 50 and D3 > 50
to
D1 >= 50 and (D2 < 100 or D3 = 50
)
And somehow I assume, that a database should be that smart (if I think about how complex queries become this must be child's play for the database).
The question should be: How much criteria can it handle (X data fields and Y criterias). But that's something I have to figure out. I'll report when we collect some date here (could take a while).