-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
DISTINCT doesn't work with jsonb_build_object #46709
Comments
rohany
added a commit
to rohany/cockroach
that referenced
this issue
Mar 28, 2020
Fixes cockroachdb#46709. A recent change was made to fix encodings to perform aggregations on JSONB and ARRAY columns. That change missed a case in for DISTINCT aggregations, causing a runtime error when executing these queries. Release justification: fixes a bug Release note (bug fix): This PR fixes a bug with distinct aggregations on JSONB columns.
Hi @Bessonov, thanks for pointing this out! This is actually related to the change that you linked here, and it seems like I missed a case in the original fix. I've put up a fix, and it should be in v20.1. |
craig bot
pushed a commit
that referenced
this issue
Mar 29, 2020
46711: rowexec: fix bug with distinct aggregations on JSONB columns r=yuzefovich a=rohany Fixes #46709. A recent change (#45229) was made to fix encodings to perform aggregations on JSONB and ARRAY columns. That change missed a case in for DISTINCT aggregations, causing a runtime error when executing these queries. Release justification: fixes a bug Release note (bug fix): This PR fixes a bug with distinct aggregations on JSONB columns. Co-authored-by: Rohan Yadav <[email protected]>
@rohany thank you very much for very quick resolution! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the problem
Goal:
We have a relation from an user to postal addresses and phones. The goal is to get whole net for the user (1 or <=100) as json. We distinct between projection and filtering. If we filter by phone (filtering) or want to show phones (projection),
left join
clause is "automatically" added.Because of
join
and projection we have a problem, if user has for example 2 phones and 1 postal address. We get the same postal two times. It's possible to get rid of this problem with postgres, but I don't found a solution with cockroachdb. See reproduction.To Reproduce
Data snippet for postgres:
Data snippet for crdb:
This query shows the problem on both dbs (filtering omitted, because not relevant for the output):
Result:
The closest workaround/solution is to use
DISTINCT
beforejsonb_build_object
, and it works on postgres (see sqlfiddle to play with it):but not on crdb:
I've seen that something similar was fixed by @rohany , but even after upgrade from
19.2.0
to unstable:nothing changes.
Expected behavior
I'm not sure if there is an efficient way to workaround it. It can be achieved if instead of usage of
postal
/phone
in the select, a subselect is fired:It doesn't feel right and breaks count:
May be there is another solution. But it would be nice to have a little bit more alignment to postgres.
Additional data / screenshots
Environment:
cockroach sql
Thanks!
The text was updated successfully, but these errors were encountered: