MySQL 9.0.0
Source Code Documentation File Reference
#include <assert.h>
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_func.h"
#include "sql/sql_executor.h"
#include "sql/sql_list.h"
#include "template_utils.h"


namespace  anonymous_namespace{}


Itemanonymous_namespace{}::OrGroupWithSomeRemoved (Item_cond_or *or_item, const List< Item > &items_to_remove)
 For an OR disjunction, return a new disjunction with elements from “items_to_remove” logically set to TRUE (ie., removed). More...
bool anonymous_namespace{}::IsOr (const Item *item)
bool anonymous_namespace{}::AlwaysPresent (Item *expr, const Item *item)
 Check if “item” is necessary to make the expression true. More...
bool anonymous_namespace{}::MatchesAny (Item *item, const List< Item > &items)
 Check if “item” matches any item in “items”. More...
void anonymous_namespace{}::ExtractItemsExceptSome (Item_cond_and *and_item, const List< Item > &items_to_remove, List< Item > *output)
 For all items in an AND conjunction, add those (possibly none) that are not in “items_to_remove”. More...
ItemCommonSubexpressionElimination (Item *cond)
 Do simple CSE (common subexpression elimination) on “item”, and return the answer. More...

Function Documentation

◆ CommonSubexpressionElimination()

Item * CommonSubexpressionElimination ( Item cond)

Do simple CSE (common subexpression elimination) on “item”, and return the answer.

The CSE done is exclusively moving common expressions out of conjunctions-of-disjunctions, ie. it rewrites

(a AND b) OR (a AND c)


a AND (b OR c)

The primary motivation is that such split-out items are more versatile; they can be pushed independently, be made into hash join conditions etc. However, an added bonus is that the expressions will simply execute faster.

This function does not descend into subexpressions that are not AND/OR conjunctions, so e.g. an expression like

1 + ((a AND b) OR (a AND c))

will be left as-is.