Fix n+1 for categories in for to_donut_segments_json in budget #1693

Merged
tapalilov merged 1 commits from fix-category-n_plus_1 into main 2025-01-27 22:34:13 +08:00
tapalilov commented 2025-01-26 04:12:14 +08:00 (Migrated from github.com)

Finished in 16.365568s, 24.9915 runs/s, 87.9896 assertions/s.
409 runs, 1440 assertions, 0 failures, 0 errors, 1 skips

Before:
14 queries

Category Load (0.1ms)  SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2  [["id", "3e52d767-8730-4c71-b870-9ba746188025"], ["LIMIT", 1]]

After:
1 query

  Category Load (0.6ms)  SELECT "categories".* FROM "categories" WHERE "categories"."id" IN ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)  [["id", "9a7827c4-afc3-4aeb-9a5d-adee
25019d1d"], ["id", "df234040-a03d-4df5-9d9e-9f612be21ebd"], ["id", "5171d8f1-1b5d-40c5-b5b2-c2e2dcd10063"], ["id", "526b1534-88ed-4e6c-b864-059e3262a311"], ["id", "88fe1e70-8a26-44ee-8da6-721f
ce5121f9"], ["id", "26ba0979-6dde-4f31-83de-c8e774f4156c"], ["id", "9c4d849b-04f0-4976-9140-67de6d219969"], ["id", "3e52d767-8730-4c71-b870-9ba746188025"], ["id", "242f10bd-bdef-4f44-a3ec-a6b5
e8ea36e3"], ["id", "dc2c5d30-3c56-4d78-b8f3-575abb085a2c"], ["id", "13ee71d8-df19-4df6-8960-a8430baa45f7"], ["id", "c3772497-3623-49e8-b221-d9e033577742"], ["id", "8687406d-5ce9-4802-9fec-2956
43c1107c"], ["id", "4058260a-adb2-4d47-88da-d746cce8e55c"]]
>Finished in 16.365568s, 24.9915 runs/s, 87.9896 assertions/s. > 409 runs, 1440 assertions, 0 failures, 0 errors, 1 skips Before: 14 queries ``` Category Load (0.1ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2 [["id", "3e52d767-8730-4c71-b870-9ba746188025"], ["LIMIT", 1]] ``` After: 1 query ``` Category Load (0.6ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" IN ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) [["id", "9a7827c4-afc3-4aeb-9a5d-adee 25019d1d"], ["id", "df234040-a03d-4df5-9d9e-9f612be21ebd"], ["id", "5171d8f1-1b5d-40c5-b5b2-c2e2dcd10063"], ["id", "526b1534-88ed-4e6c-b864-059e3262a311"], ["id", "88fe1e70-8a26-44ee-8da6-721f ce5121f9"], ["id", "26ba0979-6dde-4f31-83de-c8e774f4156c"], ["id", "9c4d849b-04f0-4976-9140-67de6d219969"], ["id", "3e52d767-8730-4c71-b870-9ba746188025"], ["id", "242f10bd-bdef-4f44-a3ec-a6b5 e8ea36e3"], ["id", "dc2c5d30-3c56-4d78-b8f3-575abb085a2c"], ["id", "13ee71d8-df19-4df6-8960-a8430baa45f7"], ["id", "c3772497-3623-49e8-b221-d9e033577742"], ["id", "8687406d-5ce9-4802-9fec-2956 43c1107c"], ["id", "4058260a-adb2-4d47-88da-d746cce8e55c"]] ```
zachgoll (Migrated from github.com) approved these changes 2025-01-27 22:31:09 +08:00
zachgoll (Migrated from github.com) left a comment

Awesome, nice catch and thanks for the fix!

Awesome, nice catch and thanks for the fix!
Sign in to join this conversation.