[ENH]: Optimize GetCollections and remove usage of raw gorm (#5274)
## Description of changes An earlier [change](https://github.com/chroma-core/chroma/pull/5268) attempted to use a CTE to optimize the GetCollections query in the event where the databases pkey is fully specified. This led to using raw gorm which led to a few unexpected binding issues when converting from gorm sql to raw sql, leading us to [revert](https://github.com/chroma-core/chroma/commit/71aae948da980954d89994132def214a27ccfcaa) that change here. In this change, we achieve the same goal of optimizing GetCollections but avoid the use of CTE's entirely. We get the required database_id from databases within a predicate subquery. If the predicate subquery has a LIMIT 1 in it, Postgres is known to treat this as a CTE. Since gorm plays much more nicely with subqueries than CTE's this is a much better fix. - Improvements & Bug fixes - ... - New functionality - ... ## Test plan _How are these changes tested?_ - [ ] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Migration plan _Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?_ ## Observability plan _What is the plan to instrument and monitor this change?_ ## Documentation Changes _Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs section](https://github.com/chroma-core/chroma/tree/main/docs/docs.trychroma.com)?_ --------- Co-authored-by: propel-code-bot[bot] <203372662+propel-code-bot[bot]@users.noreply.github.com>
T
tanujnay112 committed
982b1f1d5c293b510d0786e5a00b9d13ce431ce1
Parent: 209d2ca
Committed by GitHub <noreply@github.com>
on 8/14/2025, 8:08:29 PM