WL#12108: Inject type cast nodes into the item tree to avoid data type mismatches

Affects: Server-8.0   —   Status: Complete

Add implicit type cast operations into the item tree inside expressions and
conditions that have a mismatch between the provided argument's data type and
the expected data type.

MySQL can compare arguments of any data type with arguments of any other data
type, either by internally converting one of the arguments to the other one's
data type, or converting both to DOUBLE, but in many cases this is not standard
compliant. The standard SQL way of converting to different data types is to use
explicit type casts. A step in this direction is to transparently inject CAST
nodes, this way the query will get converted into a compliant query and executed
with the semantics of a compliant query. This change implies MySQL will go
through the item tree and insert the type cast nodes automatically if the user
neglects to do so, at least for the time being. This way, the behavior of the
server is backward compatible and the executed query becomes equivalent to a
standard compliant one.

Example:
when t1.d_time is TIME and t2.d_date is DATE

  SELECT * from t1 inner join t2 on t1.d_time = t2.d_date;

after this WL the query will be executed as:

  SELECT * from t1 inner join t2 ON CAST(t1.d_time AS DATETIME) = 
    CAST(t2.d_date AS DATETIME);

This is not a solution to handle the problem with data types with different
value ranges ex. for SMALLINT and LONGINT the operation will be executed on the
longest type of integer without inserting any cast nodes.

Why do it this way?
- long term solution
- internally, converts MySQL's non standard functionality into
standard-compliant functionality
- mostly transparent to the end-users (still, EXPLAIN shows the actual query
that gets executed internally)
- in the long run it will help us ditch the val_* functions