baptisteArno
04/10/2022, 6:36 PMSELECT u.id FROM "User" u
JOIN "Typebot" t ON u.id = t."ownerId"
WHERE (SELECT count(*) FROM "Result" r WHERE r."typebotId" = t.id) >= 30
Result table has 66,000 records. I'm wondering, is there a way to optimize this?tourdownunder
04/11/2022, 2:00 AMsql
SELECT u.id FROM "User" u
JOIN "Typebot" t ON u.id = t."ownerId"
WHERE (SELECT count(*) FROM "Result" r WHERE r."typebotId" = t.id LIMIT 30) >= 30
tourdownunder
04/11/2022, 2:02 AMtourdownunder
04/11/2022, 2:02 AMtourdownunder
04/11/2022, 2:06 AMsql
WITH result_count AS (
SELECT r."typebotId", count(*) FROM "Result" r GROUP BY r."typebotId"
)
SELECT u.id FROM "User" u
JOIN "Typebot" t ON u.id = t."ownerId"
JOIN result_count ON r."typebotId" = t.id
baptisteArno
04/12/2022, 4:46 PMbaptisteArno
04/12/2022, 4:47 PMtourdownunder
04/12/2022, 9:25 PMtourdownunder
04/12/2022, 9:27 PMtourdownunder
04/12/2022, 9:29 PMsql
WITH result_count AS (
SELECT r."typebotId", count(*) FROM "Result" r GROUP BY r."typebotId" HAVING count(*) > 30
)
baptisteArno
04/16/2022, 9:16 PMbaptisteArno
04/16/2022, 9:16 PMsql
CREATE VIEW active_users AS
WITH result_count AS (
SELECT r."typebotId", count(*) FROM "Result" r GROUP BY r."typebotId" HAVING count(*) > 30
)
SELECT u.id FROM "User" u
JOIN "Typebot" t ON u.id = t."ownerId"
JOIN result_count r ON r."typebotId" = t.id
baptisteArno
04/16/2022, 9:16 PM