Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the correct collation for temporal results #602

Conversation

dbussink
Copy link

When functions like GREATEST, LEAST and COALESCE return a temporal result, the collation is not set to binary as expected.

The collation for temporal types normally is always binary which is the case for fields and for functions inheriting from Item_temporal_func.

The comparison functions mentioned here though don't inherit from that and can return various types. Internally they do set the numeric collation correctly, but at the protocol level (and for what the COLLATION function returns), it is translated to the binary collation.

This translation does not happen before this change for the given functions, so we add it here.

Before:

mysql> select collation(date'2010-01-01');
+-----------------------------+
| collation(date'2010-01-01') |
+-----------------------------+
| binary                      |
+-----------------------------+
1 row in set (0.00 sec)

mysql> select collation(greatest(date'2010-01-01', date'2009-01-01'));
+---------------------------------------------------------+
| collation(greatest(date'2010-01-01', date'2009-01-01')) |
+---------------------------------------------------------+
| latin1_swedish_ci                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)

After:

mysql> select collation(date'2010-01-01');
+-----------------------------+
| collation(date'2010-01-01') |
+-----------------------------+
| binary                      |
+-----------------------------+
1 row in set (0.00 sec)

mysql> select collation(greatest(date'2010-01-01', date'2009-01-01'));
+---------------------------------------------------------+
| collation(greatest(date'2010-01-01', date'2009-01-01')) |
+---------------------------------------------------------+
| binary                                                  |
+---------------------------------------------------------+
1 row in set (0.00 sec)

This issue applies to all supported MySQL versions, starting from 8.0.x and later at least.

When functions like `GREATEST`, `LEAST` and `COALESCE` return a temporal
result, the collation is not set to `binary` as expected.

The collation for temporal types normally is always `binary` which is
the case for fields and for functions inheriting from
`Item_temporal_func`.

The comparison functions mentioned here though don't inherit from that
and can return various types. Internally they do set the numeric
collation correctly, but at the protocol level (and for what the
`COLLATION` function returns), it is translated to the binary collation.

This translation does not happen before this change for the given
functions, so we add it here.

Before:

```
mysql> select collation(date'2010-01-01');
+-----------------------------+
| collation(date'2010-01-01') |
+-----------------------------+
| binary                      |
+-----------------------------+
1 row in set (0.00 sec)

mysql> select collation(greatest(date'2010-01-01', date'2009-01-01'));
+---------------------------------------------------------+
| collation(greatest(date'2010-01-01', date'2009-01-01')) |
+---------------------------------------------------------+
| latin1_swedish_ci                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)
```

After:

```
mysql> select collation(date'2010-01-01');
+-----------------------------+
| collation(date'2010-01-01') |
+-----------------------------+
| binary                      |
+-----------------------------+
1 row in set (0.00 sec)

mysql> select collation(greatest(date'2010-01-01', date'2009-01-01'));
+---------------------------------------------------------+
| collation(greatest(date'2010-01-01', date'2009-01-01')) |
+---------------------------------------------------------+
| binary                                                  |
+---------------------------------------------------------+
1 row in set (0.00 sec)
```

Signed-off-by: Dirkjan Bussink <[email protected]>
@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@dbussink
Copy link
Author

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=117543 for updates.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants