vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.67k stars 2.1k forks source link

SET timestamp Syntax Error in Vitess #17170

Open systay opened 1 week ago

systay commented 1 week ago

When running the following SQL command, which is commonly issued by some ORMs and works as expected on vanilla MySQL, an error occurs in Vitess:

# vanilla mysql
mysql> SET timestamp=1690891202;
Query OK, 0 rows affected (0.01 sec)

# vitess
mysql> SET timestamp=1690891202;
syntax error at position 14 near 'timestamp'
GuptaManan100 commented 2 days ago

I was looking at this today, and I found something interesting! MySQL doesn't allow setting non-reserved keywords in general. That means the following fails -

mysql [localhost:8032] {msandbox} ((none)) > set temporary=12;
ERROR 1193 (HY000): Unknown system variable 'temporary'
mysql [localhost:8032] {msandbox} ((none)) > SET timestamp=1690891202;
Query OK, 0 rows affected (0.00 sec)

But, timestamp is special in its handling. Look at the MySQL docs - https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_timestamp This suggests that the output of NOW() is gonna depend on this variable. How do we want to handle this? Its a session setting. We can keep track of this in vtgate, but then we would have to add special handling for NOW() function too, so that we know to substitute this variables valuw whenever the user uses NOW() in this session.