Slow Join Filter via Javascript Client (SQL is fast)

Hey there,

I'm creating a new JS Client query to retrieve rows according to a filter on a foreign table via reference. Something like this:

  const { data, error } = await supabase
    .from('rooms')
    .select(`*, hotels!inner (*)`)
    .eq('hotels.company_id', '1234');


This query times out each time it's run with the error:
{
  error: {
    code: '57014',
    details: null,
    hint: null,
    message: 'canceling statement due to statement timeout'
  }
}


When I run this query using a Postgres SQL command, however, it completes in a second.
SELECT *
FROM rooms r
         join hotels h on r.hotel_id = h.id
where h.company_id = '1234'


(I've changed the names of the tables from the originals)
Stats
rooms: 609956
hotels: 159549

Additionally, I've added indexes to both:
  1. rooms.hotel_id
  2. hotels.company_id
Does anyone know why this command may be so slow, only while using the JS Client
Was this page helpful?