You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vitess rewrites select a from (select a, count(*) as count from data where ... group by ... order by ...) t1 where t1.count >= :daysLimit
as select a from (select a, count(*) as count from data where ... and count(*) >= :v2 group by ... order by ...) as t1
which is incorrect: it doesn't understand that count is an aggregate column and cannot be used in WHERE and must be used in HAVING. This results in the error Invalid use of group function
Workaround is to make the query more explicit so as to prevent that edge case:
select a from (select a, count(*) as count from data where ... group by ... having count(*) >= :daysLimit order by ...)
This seems similar to #11311 but we have that fix pulled in already, so this seems like another variant
Reproduction Steps
select t1.portalId, t1.flowId from (select portalId, flowId, count(*) as count from suspect_high_cost_flow_data where localDate > :v1 group by portalId, flowId order by null) t1 where t1.count >= :v2
CREATE TABLE `suspect_high_cost_flow_data` (
`portalId` int(10) unsigned NOT NULL,
`flowId` bigint(20) unsigned NOT NULL,
`localDate` int(10) unsigned NOT NULL,
`totalObjects` bigint(20) unsigned NOT NULL,
`enrollmentsOfTheDay` bigint(20) unsigned NOT NULL,
`executionsOfTheDay` bigint(20) unsigned NOT NULL,
`uniqueEnrollments` bigint(20) unsigned NOT NULL,
`totalEnrollments` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`portalId`,`flowId`,`localDate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8
the query you listed under “Reproduction Steps” already has the count(*) >= :v2 expression in the WHERE clause
I'm guessing that is not the correct query
Ah sorry about that, here's the actual query: select t1.portalId, t1.flowId from (select portalId, flowId, count(*) as count from suspect_high_cost_flow_data where localDate > :v1 group by portalId, flowId order by null) t1 where t1.count >= :v2
Overview of the Issue
Vitess rewrites
select a from (select a, count(*) as count from data where ... group by ... order by ...) t1 where t1.count >= :daysLimit
as
select a from (select a, count(*) as count from data where ... and count(*) >= :v2 group by ... order by ...) as t1
which is incorrect: it doesn't understand that count is an aggregate column and cannot be used in
WHERE
and must be used inHAVING
. This results in the errorInvalid use of group function
Workaround is to make the query more explicit so as to prevent that edge case:
select a from (select a, count(*) as count from data where ... group by ... having count(*) >= :daysLimit order by ...)
This seems similar to #11311 but we have that fix pulled in already, so this seems like another variant
Reproduction Steps
Binary Version
Operating System and Environment details
Log Fragments
No response
The text was updated successfully, but these errors were encountered: