Hi,
I have an SQL query that have recently massively increased in the time it takes to execute, the SQL for the query is:
SELECT
b0."id",
b0."additional_cancellation_reason",
b0."additional_refund_reason",
b0."booking_purpose_confirmed",
b0."canceled", b0."canceled_at",
b0."cancellation_reason",
b0."duration",
b0."ends_at_utc",
b0."full_price",
b0."incident_number",
b0."include_equipment_in_price",
b0."payment_id",
b0."payment_id_from_handler",
b0."power_on",
b0."price_paid",
b0."refund_reason",
b0."refunded",
b0."starts_at_local",
b0."starts_at_utc",
b0."status",
b0."uuid",
b0."studio_id",
b0."user_id",
b0."inserted_at",
b0."updated_at"
FROM "booking"
AS b0 INNER JOIN "studio"
AS s1 ON s1."id" = b0."studio_id" INNER JOIN "site"
AS s2 ON s2."id" = s1."site_id"
WHERE ((b0."user_id" = 71099)
AND (b0."canceled" = FALSE))
AND (NOT (b0."status" IN ('awaiting_payment','initialised')))
ORDER BY b0."ends_at_utc" DESC LIMIT 500
When I execute this directly on our production DB, the execution time is around a quarter of a second.
When I type this query out verbatim and run MyRepo.all(query) in the production app server, this takes around 5 seconds. When I execute the same command in my local terminal it’s back down to a fraction of a second.
Is there something happening between our production servers and the database? They’re hosted on AWS but my infra knowledge is pretty limited, if anyone has any areas I could investigate that would be appreciated.
Thanks in advance,
Mark






















