database - Complex SQL where clause: whether to factor logic -
I have a complex SQL, where a requirement has just become more complex due to change. There are four basic set of cases, each of which is accompanied by a different combination of other factors. It is more readable (in my opinion) where there are different branches in four branches, where repeating redundant norms in each branch. But I do not know how well the database engine will optimize.
Here is an expression in my unnecessary form. I have changed the actual criteria with letters. I have a "branching" benchmark, which comes in four forms. All expressions are in the form of the field = 'value' , unless otherwise noted.
A1 and B and C and D or A2 and B and C and D and E and F1 and G or A3 and A3 A and B and C and D & E and In the A. The G form is not in thefield ('value1', 'value2')except for F1 and G or A4 and B and C & D and F2area> 'Value' field (subquery).Here is the expression, (I think) it is considered to be least redundant.
B and C and D and (A1 or (E and F1 & G End (A2 or (A3 and A3A)) or (A4 & F2)My question is that I want to have this simple expression in the simplest (least redundant) logical form, or to keep it in a more redundant but more readable form The target database is Sybase, but I want to know generally the answer for RDMBs.
I do not have a RDBMS in the world If you are worried about redundancy, efficiency is more important here.
In your case, I use the I have not seen See this article in my blog: and Update: You can a by a condition, like this: Select A1 and B and C union from mytable * Sybase for more than 7 , but in all the major RDBMS 's Unions are more efficient than >> or . Oracle :
unions in Oracle unions vs OR P> Functionality I think work out well for this approach Sybase too. UNION to
> Since the status g is a subquery, it may be possible that it adding hash is required to perform fast hash zone to all unfiltered The values require a full scan, so filtering all the values in a fullscan and then HASH JOIN :
SELECT * (SELECT * foo foo WHERE condition_set_1 UNION SELECT * Foo WHERE condition_set_2_but_no_g ...) Where G Any other decision For Mitigation, it is better to have too much to actually query.
Comments
Post a Comment