Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

count operation should skip order by #138

Merged
merged 1 commit into from
Apr 9, 2021
Merged

Conversation

IgorNB
Copy link
Contributor

@IgorNB IgorNB commented Mar 29, 2021

One can use order by with subquery, that correctly requests data, but count request crashes

Data request SQL:

select sao0_.ID
from public.sao sao0_
         cross join public.sao sao1_
where sao0_.ID = sao1_.ID
order by (select MAX(GREATEST(sao.id, sa.id, sc.id, sr.id))
          from sao sao
                   left join sa on sa.id = sao.sma_id
                   left join sc on sa.id = sc.sma_id
                   left join sr on sc.id = sr.sc_id
          where sao.id = sao1_.id
          group by sao.id) desc
limit ?

count request produces error[42803] ERROR: subquery uses ungrouped column "sao1_.id" from outer query:

select count(sao0_.ID)
from public.sao sao0_
         cross join public.sao sao1_
where sao0_.ID = sao1_.ID
order by (select MAX(GREATEST(sao.id, sa.id, sc.id, sr.id))
          from sao sao
                   left join sa on sa.id = sao.sma_id
                   left join sc on sa.id = sc.sma_id
                   left join sr on sc.id = sr.sc_id
          where sao.id = sao1_.id
          group by sao.id) desc

fixed in this MR count succedes. SQL:

select count(sao0_.ID)
from public.sao sao0_
         cross join public.sao sao1_
where sao0_.ID = sao1_.ID

@IgorNB IgorNB force-pushed the count_must_skip_order_by branch from 251cba0 to 80bf30e Compare March 29, 2021 15:51
@IgorNB IgorNB changed the title count operation must skip order by count operation have to skip order by Mar 29, 2021
@IgorNB IgorNB changed the title count operation have to skip order by count operation should skip order by Mar 29, 2021
@IgorNB IgorNB requested a review from abratashev April 1, 2021 14:27
@xrav xrav merged commit 7c9e69c into master Apr 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants