You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(db-*): querying joins with $exists on mongodb and improve performance when querying multiple times on postgres (#14315)
1. Fixes handling of `$exists` when querying a field nested to a join
field.
2. Avoids adding new SQL joins when querying a join field multiple times
before
```sql
SELECT DISTINCT
"categories"."id",
"categories"."created_at",
"categories"."created_at"
FROM
"categories"
LEFT JOIN "posts_rels" AS "c40660ed_b4bf_4644_bbd1_b7225045bb92"
ON (
"categories"."id" = "c40660ed_b4bf_4644_bbd1_b7225045bb92"."categories_id"
AND "c40660ed_b4bf_4644_bbd1_b7225045bb92"."path" LIKE ?
)
LEFT JOIN "posts" AS "6702692c_e77e_41b3_ab0c_038d8ca584f6"
ON "c40660ed_b4bf_4644_bbd1_b7225045bb92"."parent_id" = "6702692c_e77e_41b3_ab0c_038d8ca584f6"."id"
LEFT JOIN "posts" AS "b8d97c7b_51c7_448e_96dd_567ac0a24ccf"
ON "c40660ed_b4bf_4644_bbd1_b7225045bb92"."parent_id" = "b8d97c7b_51c7_448e_96dd_567ac0a24ccf"."id"
LEFT JOIN "posts" AS "89586995_3641_4226_b047_dc3c96b33d9f"
ON "c40660ed_b4bf_4644_bbd1_b7225045bb92"."parent_id" = "89586995_3641_4226_b047_dc3c96b33d9f"."id"
WHERE
"6702692c_e77e_41b3_ab0c_038d8ca584f6"."title" = ?
AND "b8d97c7b_51c7_448e_96dd_567ac0a24ccf"."title" IS NOT NULL
AND "89586995_3641_4226_b047_dc3c96b33d9f"."is_filtered" = ?
ORDER BY
"categories"."created_at" DESC
LIMIT ?
-- params: ["categories", "my-title", 1, 10]
```
now
```sql
SELECT DISTINCT
"categories"."id",
"categories"."created_at",
"categories"."created_at"
FROM
"categories"
LEFT JOIN "posts_rels" AS "b6ba04a3_a557_4321_abfb_7b58250baa2c"
ON (
"categories"."id" = "b6ba04a3_a557_4321_abfb_7b58250baa2c"."categories_id"
AND "b6ba04a3_a557_4321_abfb_7b58250baa2c"."path" LIKE ?
)
LEFT JOIN "posts" AS "86c9090f_c50b_485d_a9bb_1ca8b5ad079d"
ON "b6ba04a3_a557_4321_abfb_7b58250baa2c"."parent_id" = "86c9090f_c50b_485d_a9bb_1ca8b5ad079d"."id"
WHERE
"86c9090f_c50b_485d_a9bb_1ca8b5ad079d"."title" = ?
AND "86c9090f_c50b_485d_a9bb_1ca8b5ad079d"."title" IS NOT NULL
AND "86c9090f_c50b_485d_a9bb_1ca8b5ad079d"."is_filtered" = ?
ORDER BY
"categories"."created_at" DESC
LIMIT ?
-- params: ["categories", "my-title", 1, 10]
```
0 commit comments