dolthub / dolt

Dolt – Git for Data
Apache License 2.0
17.96k stars 513 forks source link

Incorrect type inference for `COALESCE` of system variables #8448

Closed fanyang01 closed 4 weeks ago

fanyang01 commented 1 month ago

Hi Dolt creators,

I have observed that the type inference for the COALESCE function does not work as expected when used with system variables. For instance, COALESCE(@@admin_port, @@port) is inferred to be a longtext field. This issue can be reproduced using the _example implementation:

$ cd _example
$ go run .
mysql -h127.0.0.1 -uroot -P3306;
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.33 Dolt

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database db01;
Query OK, 1 row affected (0.00 sec)

mysql> use db01;
Database changed
mysql> select @@admin_port, @@port;
+--------------+--------+
| @@admin_port | @@port |
+--------------+--------+
|        33062 |   3306 |
+--------------+--------+
1 row in set (0.00 sec)

mysql> create table t as select @@admin_port as port1, @@port as port2, COALESCE(@@admin_port, @@port) as
 port3;
Query OK, 1 row affected (0.00 sec)

mysql> desc t;
+-------+------------+------+-----+---------+-------+
| Field | Type       | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| port1 | system_int | NO   |     | NULL    |       |
| port2 | system_int | NO   |     | NULL    |       |
| port3 | longtext   | NO   |     | NULL    |       |
+-------+------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> select * from t;
+-------+-------+-------+
| port1 | port2 | port3 |
+-------+-------+-------+
| 33062 |  3306 | 33062 |
+-------+-------+-------+
1 row in set (0.00 sec)
timsehn commented 1 month ago

I'm going to move this one to the actual Dolt repo for visibility.