-
Roy Lyseng authored
During contextualization, substitute incomplete boolean expressions in conditions (WHERE, HAVING and ON) with full boolean expressions. The function make_condition() takes as input any expression and outputs a complete boolean expression. If the input expression is already a predicate or a condition, indicated by is_bool_func() returning true, it is returned immediately. Otherwise, [expression] is rewritten to "0 <> [expression]". An exception is MATCH predicates, for which a special match predicate node is generated. Negation of boolean expressions is also changed: Since incomplete expressions may be attempted negated, ensure that such expressions are made complete before they are negated. This is performed by function negate_condition() (former negate_expression()) located in item_cmpfunc.cc. The function is moved from sql_parse.cc. Itemization of AND, OR and XOR operators ensure that all operand expressions are complete boolean expressions. Boolean expressions are generally subclassed from Item_bool_func. However, some predicates (IN, EXISTS and ALL/ANY) are not subclassed from Item_bool_func. To handle all boolean expressions similarly, it is enforced that the function is_bool_func() returns true for all boolean expression items. Sometimes, a boolean expression is required to return an "always true" or "always false" value, either if a TRUE or FALSE constant value is specified as a predicate, or when simplifying conditions internally. These expressions are internally represented as classes Item_func_true and Item_func_false, with common base class Item_func_bool_const, subclassed from Item_bool_func. Whenever an Item_int object is used to represent a TRUE or FALSE constant, it is replaced with Item_func_true or Item_func_false. DBUG_ASSERT code is injected in selected parts of the optimizer to ensure that the processed boolean expressions are complete. Notice that some places, conditions wrapped in Item_aggregate_ref objects are accepted, meaning that a real_item() function must be applied to the condition within the assert. The function negate_condition() could be simplified slightly: when called with the condition NOT (NOT (<simple_condition>)) will now simply return <simple_condition>, since <simple_condition> can no longer be an incomplete predicate. The function neg_arguments() of class Item_cond is renamed to negate_arguments(). The Item_func_match function needs special treatment: The MATCH clause can be used as a function returning a floating point value in the SELECT list or the WHERE clause. However, it may also be used as a boolean function in the WHERE clause, where it has different semantics than when used together with a comparison operator. With a comparison operator, the match operation is performed with ranking. To preserve this behavior, the simplest solution was to wrap the Item_func_match object inside an object of the new class Item_func_match_predicate, which effectively transforms the function into a predicate. The overridden functions implemented in this class generally forward all evaluation to the underlying object. In EXPLAIN output, the boolean constants are now written as "true" and "false", changed from the earlier "1" and "0", because we now use the classes Item_func_true and Item_func_false to represent conditions that are always true and always false, respectively. This is a readability enhancement, but causes numerous changes in test result files. The test innodb_fts.fulltext_misc has a corrected result. Reviewed by: Chaithra Gopalareddy <chaithra.gopalareddy@oracle.com>
Roy Lyseng authoredDuring contextualization, substitute incomplete boolean expressions in conditions (WHERE, HAVING and ON) with full boolean expressions. The function make_condition() takes as input any expression and outputs a complete boolean expression. If the input expression is already a predicate or a condition, indicated by is_bool_func() returning true, it is returned immediately. Otherwise, [expression] is rewritten to "0 <> [expression]". An exception is MATCH predicates, for which a special match predicate node is generated. Negation of boolean expressions is also changed: Since incomplete expressions may be attempted negated, ensure that such expressions are made complete before they are negated. This is performed by function negate_condition() (former negate_expression()) located in item_cmpfunc.cc. The function is moved from sql_parse.cc. Itemization of AND, OR and XOR operators ensure that all operand expressions are complete boolean expressions. Boolean expressions are generally subclassed from Item_bool_func. However, some predicates (IN, EXISTS and ALL/ANY) are not subclassed from Item_bool_func. To handle all boolean expressions similarly, it is enforced that the function is_bool_func() returns true for all boolean expression items. Sometimes, a boolean expression is required to return an "always true" or "always false" value, either if a TRUE or FALSE constant value is specified as a predicate, or when simplifying conditions internally. These expressions are internally represented as classes Item_func_true and Item_func_false, with common base class Item_func_bool_const, subclassed from Item_bool_func. Whenever an Item_int object is used to represent a TRUE or FALSE constant, it is replaced with Item_func_true or Item_func_false. DBUG_ASSERT code is injected in selected parts of the optimizer to ensure that the processed boolean expressions are complete. Notice that some places, conditions wrapped in Item_aggregate_ref objects are accepted, meaning that a real_item() function must be applied to the condition within the assert. The function negate_condition() could be simplified slightly: when called with the condition NOT (NOT (<simple_condition>)) will now simply return <simple_condition>, since <simple_condition> can no longer be an incomplete predicate. The function neg_arguments() of class Item_cond is renamed to negate_arguments(). The Item_func_match function needs special treatment: The MATCH clause can be used as a function returning a floating point value in the SELECT list or the WHERE clause. However, it may also be used as a boolean function in the WHERE clause, where it has different semantics than when used together with a comparison operator. With a comparison operator, the match operation is performed with ranking. To preserve this behavior, the simplest solution was to wrap the Item_func_match object inside an object of the new class Item_func_match_predicate, which effectively transforms the function into a predicate. The overridden functions implemented in this class generally forward all evaluation to the underlying object. In EXPLAIN output, the boolean constants are now written as "true" and "false", changed from the earlier "1" and "0", because we now use the classes Item_func_true and Item_func_false to represent conditions that are always true and always false, respectively. This is a readability enhancement, but causes numerous changes in test result files. The test innodb_fts.fulltext_misc has a corrected result. Reviewed by: Chaithra Gopalareddy <chaithra.gopalareddy@oracle.com>
Loading