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

use ONLY_FULL_GROUP_BY but same columns report error #38597

Closed
Minorli opened this issue Oct 21, 2022 · 1 comment
Closed

use ONLY_FULL_GROUP_BY but same columns report error #38597

Minorli opened this issue Oct 21, 2022 · 1 comment
Assignees
Labels
severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@Minorli
Copy link

Minorli commented Oct 21, 2022

Bug Report

1. Minimal reproduce step (Required)

1,create table test_1 (
TARM_ID VARCHAR(20) PRIMARY KEY ,
TARM_NM VARCHAR(240),
TARVAL VARCHAR(600),
TARAM_DATA_TPCD VARCHAR(19),
TARM_FMCTD VARCHAR(90) ,
STRTUS_DT DATE,
DSABL_DT DATE );

SQL 1:
SELECT
O.TARVAL ,
(CASE O.TARM_ID
when 'CP102' THEN '1' -- (only one space after CP102)
when 'CP11' THEN '2'
END) ID ,
count(*)
FROM test_1 O
WHERE
O.TARM_ID IN ('CP11','CP142','CP102','CP137')
group by
O.TARVAL ,
(CASE O.TARM_ID
when 'CP102' THEN '1' -- (only one space after CP102)
when 'CP11' THEN '2'
END);

it works .

SQL 2:
SELECT
O.TARVAL ,
(CASE O.TARM_ID
when 'CP102' THEN '1' --(the only diffence between sql1 and sql2 ,after 'CP102',more than one space)
when 'CP11' THEN '2'
END) ID ,
count(*)
FROM test_1 O
WHERE
O.TARM_ID IN ('CP11','CP142','CP102','CP137')
group by
O.TARVAL ,
(CASE O.TARM_ID
when 'CP102' THEN '1' -- (only one space after CP102)
when 'CP11' THEN '2'
END);

ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'example.O.TARM_ID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.

I think its a bug.and sql2 works on mysql server.

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

sql 1 and sql2 all works on tidb server.

3. What did you see instead (Required)

an error 1055 .

4. What is your TiDB version? (Required)

all tidb version. and test in v6.3.

@Minorli Minorli added the type/bug The issue is confirmed as a bug. label Oct 21, 2022
@AilinKid
Copy link
Contributor

AilinKid commented Oct 27, 2022

old function dependency check is based on the text check between fields in the select list and group by field. you better keep them the same or just use the alias name ID in the group field like below.

SELECT O.TARVAL , (CASE O.TARM_ID when 'CP102'  THEN '1'   when 'CP11' THEN '2' END) ID , count(*) FROM test_1 O WHERE O.TARM_ID IN ('CP11','CP142','CP102','CP137') group by O.TARVAL , ID;
Empty set (0.01 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants