MySQL 9.1.0
Source Code Documentation
common_subexpression_elimination.h File Reference

Go to the source code of this file.

Functions

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)

into

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.