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

having for aggregate field alias name bug #179

Closed
siddontang opened this issue Sep 17, 2015 · 8 comments
Closed

having for aggregate field alias name bug #179

siddontang opened this issue Sep 17, 2015 · 8 comments
Assignees
Labels
type/bug This issue is a bug.

Comments

@siddontang
Copy link
Member

create table t1 (a int, b int) engine=innodb;
insert into t1 values (1,2), (1,3), (2,3), (2,4), (2,5), (3,4), (4,5), (4,100);

mysql> select a, sum(b) as b from t1 group by a having b > 4;
+------+------+
| a    | b    |
+------+------+
|    1 |    5 |
|    2 |   12 |
|    4 |  105 |
+------+------+

but we only get one row result.

@siddontang siddontang added the type/bug This issue is a bug. label Sep 17, 2015
@xwb1989
Copy link
Contributor

xwb1989 commented Oct 1, 2015

A simpler test case is:
select a as b from t1 having b > 4;
mysql gives
empty set
but TiDB gives

+---+
| b |
+---+
| 2 |
| 4 |
| 4 |
+---+

@qiuyesuifeng
Copy link
Member

@xwb1989 Thanks for report.
Yes, that is a problem.
I will fix it later.

@xwb1989
Copy link
Contributor

xwb1989 commented Oct 1, 2015

Following is problematic in HavingRset.CheckAndUpdateSelectList, :

if field.ContainFieldName(name, selectList.ResultFields, field.OrgFieldNameFlag) {
    continue
}       
if field.ContainFieldName(name, selectList.ResultFields, field.FieldNameFlag) {
    if field.ContainFieldName(name, tableFields, field.OrgFieldNameFlag) {
        selectList.CloneHiddenField(name, tableFields)
    }
    continue
}

not having enough time to really dig into yet, but commenting out

    if field.ContainFieldName(name, tableFields, field.OrgFieldNameFlag) {
        selectList.CloneHiddenField(name, tableFields)
    }

Can solve this particular problem(but might break others :(

Just FYI

@qiuyesuifeng
Copy link
Member

@xwb1989
Thanks for your suggestion.

We used hidden fields for having fields which not in select or group by fields, and we have not distinguished aggregate and none aggregate fields, so we have the problem as @siddontang mentioned.

As for select a as b from t1 having b > 4;, because some having conditions has some confused results, like select a as b from t1 having b + 1 or select a as b from t1 having a + b or select a + b as b from t1 having a + b > 0 and so on, now we only process alias field as origin field first, so select a as b from t1 having b > 4; may equal to select a from (select a, b from t1 having b > 4) c;.

Later we will discuss and fix this problem.
Thanks again.

@qiuyesuifeng
Copy link
Member

@xwb1989
We have fixed this problem, u can update master branch and have a try:)

@xwb1989
Copy link
Contributor

xwb1989 commented Oct 20, 2015

Thank you for letting me know :)

@xwb1989
Copy link
Contributor

xwb1989 commented Oct 20, 2015

I could confirm that the test cases mentioned above is passing.

@siddontang
Copy link
Member Author

Cool @xwb1989

YuJuncen pushed a commit to YuJuncen/tidb that referenced this issue Apr 23, 2021
The character is too exotic and breaks TiDB and some old git.
YuJuncen pushed a commit to YuJuncen/tidb that referenced this issue Apr 23, 2021
* tests: stable cluster start up

Signed-off-by: Neil Shen <overvenus@gmail.com>

* tests: fix unbound var

Signed-off-by: Neil Shen <overvenus@gmail.com>

* restore: speed retry on not leader

Signed-off-by: Neil Shen <overvenus@gmail.com>

* address comments

Signed-off-by: Neil Shen <overvenus@gmail.com>

* tests: add --cacert flag

Signed-off-by: Neil Shen <overvenus@gmail.com>

* make codecov green

Signed-off-by: Neil Shen <overvenus@gmail.com>

* address comments

Signed-off-by: Neil Shen <overvenus@gmail.com>
nolouch pushed a commit to tidblabs/tidb that referenced this issue Jan 6, 2023
Signed-off-by: zeminzhou <zhouzemin@pingcap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants