-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Get the EXPLAIN output of a request #2354
Comments
Actually Searching IANA types, I found some related to cost( So we should go with our own vendor media type: |
Mentioned before, but repeating it here: So unfortunately that leaves TRACE out. Still, because of the different formats supported, the media type seems like the right interface. |
Getting the pg 14 Query ID would be good for debugging too. That way a request can be easily mapped to a query in the logs. Seems it's possible to get it with |
It's |
Oh, thanks for clarifying that Wolfgang. I guess we should have two media types then. Hm, I think it'd be cleaner to just have one. Maybe we can just do the EXPLAIN ANALYZE with the ROLLBACK. |
There's a problem with using a media type for this. We generate different queries for each of our supported media types. If we use I guess we could match the We could reuse our
Or maybe we could join all three into one # EXPLAIN
Prefer: return=plan
# EXPLAIN ANALYZE
Prefer: return=plan; analyze
# return the generated sql
Prefer: return=plan; statement
Bad thing about this is that Another option I checked is having multiple suffixes on a media type(possible) but that wouldn't help it seems.(it's about the subtypes that a response complies) An alternative would be having multiple ## would generate the json_agg query
application/vnd.pgrst.plan-json+{text,xml,json,yaml}
## would generate the string_agg query
application/vnd.pgrst.plan-text+{text,xml,json,yaml} Which is weird, but it allows for controlling the explain format plus the generated query. It would also allow us to provide a clean SQL output of the generated query by doing: application/vnd.pgrst.plan-json+sql
application/vnd.pgrst.plan-text+sql |
Since it leaks internal details of the table, we can enable the above preference with a config. In the same way is done for the |
Settling on a media type with parameters plus suffixes for this. This has the advantage of being able to generate the different queries plus obtain the EXPLAIN in different formats. # By default get the Accept: application/json generated query plus EXPLAIN FORMAT JSON
application/vnd.pgrst.plan
# Get the Accept: application/json generated query explicitly plus EXPLAIN FORMAT TEXT
application/vnd.pgrst.plan+text;for="application/json"
# Get the Accept: text/plain generated query explicitly plus EXPLAIN output in XML
application/vnd.pgrst.plan+xml;for="text/plain" Since the Edit: According to the token rules, we cannot use "/" inside a parameter unless it's within double quotes.
(x2F( With media type parameters, all the options in EXPLAIN can be manipulated as well:
Edit: Just noted that it's not allowed to have parameters without a value. I've seen other types that use commas inside double quotes for multiple values, e.g. codecs:
However this might cause an issue with the parseHttpAccept function we use, since it splits by commas. According to the token rules, we could use
For getting the generated SQL, we could do: # Get the Accept: text/xml generated query SQL
application/vnd.pgrst.plan+sql;for=text/xml Though it doesn't really make sense to have the same # by default get the generated sql(plain) for Accept: application/json
application/sql
# get the generated sql for text/xml
application/vnd.pgrst.sql;for="text/xml"
# in theory we could output the sql wrapped in json like so(but maybe not worth it)
application/vnd.pgrst.sql+json;for="text/xml" |
This library already has more complete(subtypes, parameters) parsing of media types than the functions we have in core: https://hackage.haskell.org/package/http-media-0.8.0.0/docs/Network-HTTP-Media-MediaType.html#g:2 Edit: doesn't have suffix support zmthy/http-media#15 |
Sometimes it's difficult to understand why a simple request like
/tbl?id=eq.1
can be slow while it's equivalent in SQL is fast. This is usually due to a bad RLS policy that only applies to a postgREST role.We could support an
Accept: application/vnd.pgrst.explain+json
media type that gets theEXPLAIN (FORMAT JSON)
output into a response. That would clarify that the query is expensive and is not because of us doing some extra processing.An
EXPLAIN ANALYZE
could also be supported withAccept: application/vnd.pgrst.explain-analyze+json
, coupled withPrefer: tx=rollback
it would be safe to do. We might also consider applyingtx=rollback
by default for it.References:
Accept: application/sql
to obtain the generated queryThe text was updated successfully, but these errors were encountered: