Bug #119444 Union with bound variable silently trims result
Submitted: 22 Nov 11:32 Modified: 22 Nov 11:34
Reporter: Michal Vorisek Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:any OS:Any
Assigned to: CPU Architecture:Any
Tags: bind value, corrupt, trimmed, UNION

[22 Nov 11:32] Michal Vorisek
Description:
The following query:
```
select v
from (
  select ? v
  union all
  select ? v
) t
```

silently trims the `v` column when the column is longer than 65536 bytes.

This is highly dangerous as UNION and bind value is basic SQL functionality frequently used.

In our usecase, such query was built by ORM and MySQL silently corrupted our data.

How to repeat:
full repro: https://3v4l.org/2IHsS

Suggested fix:
Please reproduce on your side and fix. There should be no artificial limit of the string length.
[22 Nov 11:34] Michal Vorisek
The repro script currently outputs:
```
expected:
Array
(
    [0] => Array
        (
            [v] => xxx...65540*...xxx
        )

    [1] => Array
        (
            [v] => yxxx...65540*...xxx
        )

)

actual using mysqli driver:
Array
(
    [0] => Array
        (
            [v] => xxx...65535*...xxx
        )

    [1] => Array
        (
            [v] => yxxx...65534*...xxx
        )

)
bool(false)

actual using PDO driver:
Array
(
    [0] => Array
        (
            [v] => xxx...65535*...xxx
        )

    [1] => Array
        (
            [v] => yxxx...65534*...xxx
        )

)
bool(false)
```