-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fixes when using aggregates inside Spread Embedded Resources #3693
Conversation
16311f4
to
ab13868
Compare
ab13868
to
9e7b164
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Spread Resources I decided to use COUNT(<row>)
instead of COUNT(*)
. When there are nested spread resources, doing a COUNT(*)
may not return the expected values, since it would count all the columns *
from the intermediate resources.
For example, for this query:
curl 'localhost:3000/process_supervisor?select=...processes(factory_id,...process_costs(count()))'
The resulting SQL would be:
SELECT "process_supervisor_processes_1"."factory_id",
COUNT("process_supervisor_processes_1"."count") AS "count"
FROM "test"."process_supervisor"
LEFT JOIN LATERAL
(SELECT "processes_1"."factory_id",
"processes_process_costs_2"."count"
FROM "test"."processes" AS "processes_1"
LEFT JOIN LATERAL
(SELECT "process_costs_2" AS "count"
FROM "test"."process_costs" AS "process_costs_2"
WHERE "process_costs_2"."process_id" = "processes_1"."id") AS "processes_process_costs_2" ON TRUE
WHERE "processes_1"."id" = "test"."process_supervisor"."process_id") AS "process_supervisor_processes_1" ON TRUE
GROUP BY "process_supervisor_processes_1"."factory_id"
Using COUNT("process_supervisor_processes_1".*)
would not count correctly since there are processes
that do not have process_count
assigned.
9e7b164
to
98f7ad8
Compare
98f7ad8
to
dd2d813
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
… a field - @laurenceisla - Fixed "column reference <col> is ambiguous" error when selecting "?select=...table(col,count())" - Fixed "column <json_aggregate>.<alias> does not exist" error when selecting "?select=...table(aias:count())"
dd2d813
to
e44fbdd
Compare
Did not backport the fixes to v12 because the last one depends on a feature/performance commit, so it has a conflict with the code there. |
Missing:
These fixes are also needed for #3640