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

Wrong behavior when ENUM column meet Aggregation #13027

Closed
winoros opened this issue Oct 30, 2019 · 4 comments
Closed

Wrong behavior when ENUM column meet Aggregation #13027

winoros opened this issue Oct 30, 2019 · 4 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/bug The issue is confirmed as a bug.

Comments

@winoros
Copy link
Member

winoros commented Oct 30, 2019

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
create table t(a enum('a', 'b'));
insert into t values('a'), ('b');
select cast(a as signed) from (select a from t group by a) t;
  1. What did you expect to see?

Two row. 1 and 2.

  1. What did you see instead?

Two row. Both are 0, with warning Data Truncated

  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

current master 02b7634

@winoros winoros added the type/bug The issue is confirmed as a bug. label Oct 30, 2019
@winoros
Copy link
Member Author

winoros commented Oct 30, 2019

max(a) and min(a) should also return the correct result without warning.

@winoros winoros added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Dec 5, 2019
@pingyu
Copy link
Contributor

pingyu commented Dec 7, 2019

Is it caused by (*baseFuncDesc).typeInfer4MaxMin ?

if a.RetTp.Tp == mysql.TypeEnum || a.RetTp.Tp == mysql.TypeSet {
	a.RetTp = &types.FieldType{Tp: mysql.TypeString, Flen: mysql.MaxFieldCharLength}
}

So we should add a typeInfer4FirstRow, which will infer to a same type as argument. Shouldn't we ?

PS. I found another issue when ENUM met aggregation: #13961

@winoros
Copy link
Member Author

winoros commented Dec 8, 2019

I think the one you found shares the same cause of this issue. You can have a try to do a cast as signed on the result after MAX/MIN.
If these two are the same cause, no need to add a new typeInfer4FirstRow. Change the original typeInfer4MaxMin is enough. (Also we need to change the execution logic).

@pingyu
Copy link
Contributor

pingyu commented Dec 11, 2019

@winoros
Thanks for your advise. I had tried to fix it (#14035), would you please take a look ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants