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

Got interface conversion error when there are get_sys_var expr #43527

Closed
guo-shaoge opened this issue May 4, 2023 · 3 comments · Fixed by #51395
Closed

Got interface conversion error when there are get_sys_var expr #43527

guo-shaoge opened this issue May 4, 2023 · 3 comments · Fixed by #51395
Assignees
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@guo-shaoge
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table test (a datetime , b bigint,c bigint);
insert into test values('2010-10-10 10:10:10', 100, 100);
select a,b as 'asd',@total:=@total+b from (select date(a) as a,sum(c) as b from test group by date(a)) as temp,(select @total:=0) as T1 order by a;

2. What did you expect to see? (Required)

runs ok

3. What did you see instead (Required)

ERROR 1105 (HY000): interface conversion: interface {} is nil, not *types.MyDecimal

4. What is your TiDB version? (Required)

MySQL [test]> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.2.0-alpha
Edition: Community
Git Commit Hash: 7eff8ce629d00cf4ab1eeda82a1ecd5a4e394b02
Git Branch: heads/refs/tags/v7.2.0-alpha
UTC Build Time: 2023-05-03 14:33:44
GoVersion: go1.20.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.009 sec)
@guo-shaoge guo-shaoge added the type/bug The issue is confirmed as a bug. label May 4, 2023
@guo-shaoge
Copy link
Collaborator Author

guo-shaoge commented May 4, 2023

  1. (select @total:=0) makes @total as int type
  2. @total:=@total+b: b is decimal type, so + will call getVar.evalDecimal, but @total is actually a int value, so we got error here

A cast expr is missing for getVar, check how getVar is built, will not add cast, we should add cast when build getVar expr

@ti-chi-bot ti-chi-bot bot added may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels May 8, 2023
@zanmato1984 zanmato1984 added sig/planner SIG: Planner and removed sig/execution SIG execution labels May 10, 2023
@zanmato1984
Copy link
Contributor

This is variable related so changing sig to planner.

@ti-chi-bot ti-chi-bot added the affects-7.5 This bug affects the 7.5.x(LTS) versions. label Oct 23, 2023
@Rustin170506 Rustin170506 moved this to 📋 Backlog in 🎒My Work Feb 21, 2024
@Rustin170506 Rustin170506 moved this from 📋 Backlog to 🏊WIP in 🎒My Work Feb 26, 2024
@Rustin170506
Copy link
Member

I tested it on MySQL:

use test;
create table test (a datetime, b bigint, c float);
insert into test values('2010-10-10 10:10:10', 100, 100.0);
SELECT @total := @total + c FROM (SELECT c FROM test) AS temp, (SELECT @total := 200) AS T1;

It outputted:

mysql> SELECT @total := @total + c FROM (SELECT c FROM test) AS temp, (SELECT @total := 200) AS T1;
+----------------------+
| @total := @total + c |
+----------------------+
|                  300 |
+----------------------+
1 row in set, 2 warnings (0.00 sec)

mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                                                              |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'. |
| Warning | 1287 | Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'. |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

@Rustin170506 Rustin170506 added affects-7.1 This bug affects the 7.1.x(LTS) versions. and removed may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 affects-7.1 This bug affects the 7.1.x(LTS) versions. labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants