groqd icon indicating copy to clipboard operation
groqd copied to clipboard

GROQD params are nested, which cause very slow query times.

Open kadencartwright opened this issue 4 months ago • 1 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

Code Sandbox link

No response

Bug report

There is currently a bug in sanity's query engine which causes very poor performance in certain scenarios. Take the two queries and their corresponding params

Query 1: `*[_type == "video"][references($parameters.contributorId)] { _id }`
Params 1: `{"parameters":{"contributorId":"de21f586-6660-477a-8ca5-48aba9b844b5"}}`


Query 2: `*[_type == "video"][references($contributorId)] { _id }`
Params 2: `{"contributorId":"de21f586-6660-477a-8ca5-48aba9b844b5"}`


When you run any query from sanity studio's vision tool with nested parameters like Query 1, the execution time is an order of magnitude longer than if you use a flat parameter object such as in Query 2.

GROQD by default produces all queries in a manner that matches Query 1. I'm not sure if there is a different way around this, but in my codebase i have used this workaround.

export const runQuery = makeSafeQueryRunner((query, options) => sanityClient.fetch(query, options));
export const runQuery = makeSafeQueryRunner((query, options) => {
  const unnestedQuery = query.replace(/\$parameters./g, "$");
  return sanityClient.fetch(unnestedQuery, { ...options, ...options.parameters });
});


 This is not technically a bug in groqd, but all groqd users will experience poor performance because of the current implementation.

kadencartwright avatar Oct 15 '25 14:10 kadencartwright

The following is a link to my post in the sanity discord regarding this issue. This is where the sanity team confirmed that this is a bug on their end, but is not likely to be a high priority. https://discord.com/channels/1304483263171264613/1427782032439902320

kadencartwright avatar Oct 15 '25 14:10 kadencartwright