-
-
Notifications
You must be signed in to change notification settings - Fork 174
feat: add text format to explain() #301
Conversation
I'm wondering how the developer workflow for this will be? If I was building an app, I would probably want to do something like: createClient('URL', 'KEY', {
db: {
withQueryAnalyzer: process.env.ENVIRONMENT == 'test' ? 'explain' : null // leave room for "explain analyze"?
}
})
const { data, error, plan } = await supabase.from('table').select()
console.log('plan', plan) I think the key is that developers won't want to edit their code a lot to get both the plan and the data, but it looks like PostgREST returns either an explain or a request? (which would make this workflow difficult) Another workflow that they could adopt is const query = supabase.from('table').select()
const { data, error } = await query
if (process.env.ENVIRONMENT != 'production') {
const { data } = await query.explain()
console.log('query plan', data)
} Not sure what the best practice would be here. This is a really awesome feature, and I think it will be very powerful if we can build a simple workflow around it |
Main idea is to allow users to check how their RLS policies are affecting JS queries, from the JS client itself. Otherwise this requires some extra steps on the SQL editor; doable as shown on the slip blog post but doing it from JS provides quicker feedback.
I thought basically: const { user, session, error } = await supabase.auth.signIn({
email: 'example@email.com',
password: 'example-password',
})
const { data, error } = await supabase.from('table').select().explain({analyze: true})
console.log(data)
// check the plan, if the query takes too long
Note that this is already possible with
Using a different key for the plan seems like a good idea, like what we do for
Some issues with that interface:
So for this feature I believe it's better to stick to PostgreSQL behavior: a query cannot get data when using EXPLAIN.
Not sure either. I think it as the first step towards better observability for executions plans, so definitely not final. |
For me, the ideal workflow would involve using I've been trying to do that but seems I need browserify and additional stuff for getting a minified js library. It would be great if |
Co-authored-by: Div Arora <darora@users.noreply.github.com>
I'll move the plan from Edit: checking on the implementation I'm not sure if it's worth it as the users won't be able to get |
🎉 This PR is included in version 1.0.0-next.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 1.0.0-rc.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 1.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
json format for explain was added in #293 but it's hard to read. This PR adds a text format so it looks like: