prisma: Full-text search query is very slow with `search` API but fast with raw SQL
The Drizzle benchmarks use the search API for full-text search (that’s currently in Preview) in two routes:
The slow performance of the query has a heavy impact on the benchmark results leading to Prisma ORM being vastly slower than Drizzle.
When replacing the search query with raw SQL, the performances of Prisma ORM and Drizzle are on par. Here’s how you can replace the search queries with $queryRaw for better performance:
// /search-customer
const term = `${c.req.query("term")}:*`;
const result = await prisma.$queryRaw`select * from "products" where to_tsvector('english', "products"."name") @@ to_tsquery('english', ${term});`;
// /search-product
const term = `${c.req.query("term")}:*`;
const result = await prisma.$queryRaw`select * from "products" where to_tsvector('english', "products"."name") @@ to_tsquery('english', ${term});`;
The problem may be related with this issue mentioning that indexes are not properly used during FTS: https://github.com/prisma/prisma/issues/8950#issue-980473627
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 34
- Comments: 18 (2 by maintainers)
Hi, I would also like an update on this. It seems very strange that a problem that has been flagged for what is nearly 3 years based on https://github.com/prisma/prisma/issues/8950#issue-980473627 has not had any really update / fix. @janpio @nikolasburk can you provide any update on when this may potentially be fixed?
Hi!
Is there an update on this? Using raw query is not a great solution, as it goes against the spirit of using the library. Do you have a rough timeline to share? Would appreciate any updates. Thanks!
+1
+1
+1 need this as well
+1
+1 ?
+1
+1
Some initial investigation:
/search-productcode:For Prisma: https://github.com/drizzle-team/drizzle-benchmarks/blob/73107aadb3942489a3d9bd8093d1636fe7f87465/src/prisma-server.ts#L106-L116
For Drizzle: https://github.com/drizzle-team/drizzle-benchmarks/blob/73107aadb3942489a3d9bd8093d1636fe7f87465/src/drizzle-server.ts#L206-L211 https://github.com/drizzle-team/drizzle-benchmarks/blob/73107aadb3942489a3d9bd8093d1636fe7f87465/src/drizzle-server.ts#L90-L96
Generated SQL queries
For Prisma:
For Drizzle:
+100000