Hello, I have a following question: How should I c...
# help
d
Hello, I have a following question: How should I create an index on my column when I'm using the supabase javascript sdk? I have a following query:
Copy code
let query = this.supabase.from<SupabaseMessage>('request').select('*').order('created_at', { ascending: false }).limit(limit);
Then I created index in supabase's SQL editor:
Copy code
CREATE INDEX idx_request_created_at 
ON request(created_at);
It works well in the SQL editor, however it looks like it doesn't work when I'm querying data via the sdk (the index is not used, it takes ages to fetch these data).
c
Can you check the query that is actually generated by PostgREST - it should be in the logs in the dashboard (Settings -> Logs -> Database)
d
I can see logs of api requests (when I use the POST/PATCH template), however I can't see any Database logs, there is just: No data returned from the query. I'm not sure how should I search in the Database Logs
c
Not sure why you don't see any logs - maybe your project is from BEFORE they introduced the logs
In my logs, I see the actual query that is made against the DB
d
my project is aprox. 1 month old
this is exactly what I see on that page
c
not sure what to tell, I see plenty of log items in this page - I would contact support if I were you
g
As far as performance, do you have RLS on? That would not be used in UI query editor.
d
@User I have RLS off
I tried to restart the server and now I can see the logs from the database this query comes from the js sdk via http:
Copy code
SELECT "public"."request".*FROM "public"."request" ORDER BY "public"."request"."created_at" DESC NULLS LAST LIMIT 100 OFFSET 0
this one is from sql editor:
Copy code
SELECT * FROM request ORDER BY created_at DESC LIMIT 100
why the js sdk adds the
NULLS LAST
? the column is not nullable
c
Just to verify that this is the problem - can you run the query from the logs in your sql editor and confirm that it is indeed slow?
d
yea, I had to add
nullsFirst: true
to the
order
method
after that it looks fine
c
👍
d
thank you for the help guys!
g
It is interesting supabase imposes the nullslast by default where PostgREST api it is optional to even have the null parameter…
If neither of you object I'm going to post this as an issue as descending sort should default to nullsfirst OR default should be no nullsfirst or nullslast so PostgREST and Postgres can do their normal default choices.
d
I didn't do it yet, feel free to do it, send the link to the issue to this topic please, I wanna see the conclusion