Freigeben über


Logical Operators (U-SQL)

Summary

U-SQL supports the C# logical operators &&, || and ! (not). Since C# guarantees order of execution and provides short-cutting on logical operators, these operators can incur a slight performance penalty. The C# semantics does not allow the optimizer to rewrite and reorder the query predicates. For example, the second predicate in a logical expression cannot be moved up in the execution tree to apply the filter early, because it would now be executed before the first predicate.

Since such query rewrites are often useful to improve query performance, U-SQL also supports the SQL-inspired AND, OR and NOT operators. In order to give the optimizer better choices, these operators should be used instead of the C# operators if the execution order among the two predicates does not need to be preserved.

When more than one logical operator is used in an expression, NOT operators bind stronger than AND which in turn bind stronger than OR. Parentheses can be used to change the binding precedence.

Note that unlike the ANSI SQL operators, these operators are still operating according to C#’s two-valued Boolean Logic, meaning that they do not support null values as a third logical value.

Logical Operators build up the Boolean_Expression as follows:

Syntax

Boolean_Expression :=                                                                                       
     bool_expression 
|    ('NOT' | '!') Boolean_Expression 
|    Boolean_Expression ('AND' | '&&') Boolean_Expression 
|    Boolean_Expression ('OR' | '||') Boolean_Expression.

Remarks

  • bool_expression
    A C# Boolean expression that returns a not-null value of type bool.

  • !, &&, ||
    C# logical operators that provide shortcutting and preserve order of expressions.

  • NOT, AND, OR
    U-SQL logical operators that provide faster execution with predicate reordering.

See Also