supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
967 stars 130 forks source link

Support for EXPLAIN / Execution plan in postgrest-js #352

Closed mansueli closed 1 year ago

mansueli commented 1 year ago

Feature request

It should be easy for the users to take advantage of the new execution plan feature released on PostgREST v10. Pehaps a modifier, command that would add the headers Accept: application/vnd.pgrst.plan when calling PostgREST. Example:

https://postgrest.org/en/stable/releases/v10.0.0.html?highlight=explain#execution-plan

Is your feature request related to a problem? Please describe.

I want this feature to be exposed in the postgrest-js client, to help uses to enhance queries/ investigate query performance easier.

Describe the solution you'd like

const { data, error } = await supabase
  .from('cities')
  .select('name', 'country_id')
  .order('id', { ascending: false })
  .explain()

Describe alternatives you've considered

Passing the EXPLAIN when creating the client:

const options = {
  db: {
    schema: 'public',
  },
  global: {
    headers: { 'Accept': 'application/vnd.pgrst.plan' },
  }
}
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY, options);
soedirgo commented 1 year ago

This is already implemented: https://github.com/supabase/postgrest-js/blob/94db7098ef9d75766b8ca84b1e888f34a3eb759d/src/PostgrestTransformBuilder.ts#L168-L222

It's not available on the Supabase platform yet, since this is only available on PostgREST v10, while the currently deployed version is v9.