One possible solution to optimize the query is to use a subquery instead of a large IN clause.
Here's an example of how you can rewrite the query using a subquery:
SELECT * FROM employees
WHERE company_id IN (SELECT id FROM companies WHERE supervisor_id = :supervisorId)
AND employees.deleted_at IS NULL
ORDER BY created_at DESC
LIMIT 10 OFFSET 0
In this solution, you would replace :supervisorId with the actual ID of the supervisor who is accessing the data. The subquery (SELECT id FROM companies WHERE supervisor_id = :supervisorId) retrieves the IDs of the companies that the supervisor has access to, and then the main query filters the employees based on those company IDs.
This approach can be more efficient because the subquery will only return the necessary company IDs for the supervisor, rather than comparing against a large list of IDs in the IN clause.
Remember to replace supervisor_id with the actual column name in your database table.
I hope this helps! Let me know if you have any further questions.