[MDEV-12681] Wrong VIEW results for CHAR(0xDF USING latin1) Created: 2017-05-04  Updated: 2017-11-15  Resolved: 2017-11-15

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.1, 10.2, 10.3
Fix Version/s: 10.0.34, 10.1.30, 10.2.11, 10.3.3

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-12680 Crash when CREATE TABLE t1 AS SELECT ... Closed

 Description   

In Linux console, I run

SET NAMES utf8;
SELECT CHAR(0xDF USING latin1);

+-------------------------+
| CHAR(0xDF USING latin1) |
+-------------------------+
| ß                       |
+-------------------------+

Notice, it correctly returned LATIN SMALL LETTER SHARP S.

Now I put the same expression into a view and query the view:

CREATE OR REPLACE VIEW v1 AS SELECT CHAR(0xDF USING latin1) AS c;
SELECT * FROM v1;

+---+
| c |
+---+
| �  |
+---+

Notice, it returned some garbage (Linux console changed garbage to U+FFFD REPLACEMENT CHARACTER).
Looks wrong. The expected result is to return the same SHARP S character.

The problem is that Item_func_char::print() does not display the USING clause:

SHOW CREATE VIEW v1;

+------+------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View                                                                                                      | character_set_client | collation_connection |
+------+------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| v1   | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select char(0xdf) AS `c` | utf8                 | utf8_general_ci      |
+------+------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+

Notice, it prints:

char(0xdf)

It should print:

char(0xdf using latin1)


Generated at Thu Feb 08 07:59:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.