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

fix: HEAD unnecessarily executing aggregates #2857

Merged
merged 2 commits into from
Jul 10, 2023

Conversation

steve-chavez
Copy link
Member

Previously:

curl -I localhost:3000/projects -H "Prefer: count=exact"

tail -f /run/user/1000/postgrest/postgrest-with-postgresql-15-vGF/db.log

WITH pgrst_source AS ( SELECT "test"."projects".* FROM "test"."projects"     )  SELECT null::bigint AS total_result_set, pg_catalog.count(_postgrest_t) AS page_total,
coalesce(json_agg(_postgrest_t), '[]') AS body, -- note here
nullif(current_setting('response.headers', true), '') AS response_headers, nullif(current_setting('response.status', true), '') AS response_status FROM ( SELECT * FROM pgrst_source ) _postgrest_t

Now:

curl -I localhost:3000/projects -H "Prefer: count=exact"

tail -f /run/user/1000/postgrest/postgrest-with-postgresql-15-N94/db.log

WITH pgrst_source AS ( SELECT "test"."projects".* FROM "test"."projects"     ) , pgrst_source_count AS (SELECT 1 FROM "test"."projects") SELECT (SELECT pg_catalog.count(*) FROM pgrst_source_count) AS total_result_set, pg_catalog.count(_postgrest_t) AS page_total, 
''::text AS body, -- note here
nullif(current_setting('response.headers', true), '') AS response_headers, nullif(current_setting('response.status', true), '') AS response_status FROM ( SELECT * FROM pgrst_source ) _postgrest_t

It's a bit hard to test it as mentioned on #2849 (comment) but the new types make sure this behavior is clear. I've added a ResultAggregate(previously on #2825) that has a NoAgg value.

Closes #2849.

@steve-chavez steve-chavez merged commit e332f03 into PostgREST:main Jul 10, 2023
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

HEAD request unnecessarily sends query data back to PostgREST
2 participants