-
Notifications
You must be signed in to change notification settings - Fork 688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 Feature Request: D1 max expression tree depth example and discussion #4094
Comments
There sounds like two issues at play here:
What you are likely seeing is differences in local dev as later versions of wrangler (3.4 and later) use the new backend. You can use an older version of wrangler, but we strongly suggest you migrate your data to the new backend, which has been the default for a few months now. While we will not forcibly stop you from using it, we aren’t supporting creating new databases on the old backend - this is unfortunately the risk of a public alpha. We can consider increasing the expression tree depth but without knowing your queries depth (via EXPLAIN) we can’t know what will work for you. |
Yes, I am aware why this happens, like what is causing it. I just don't particularly like it and I can't really do anything against it right now.
Fair enough, I'll keep using it for as long until the depth tree issue is resolved.
I am not exactly sure how the SQL query is constructed and couldn't find any way to extract the SQL query. I'll forward this to issue to the drizzle team as well so they may be able to give us raw queries or a way to get raw queries. |
I've got the query. For reference I'll give you two versions, the original one which is at above 20 depth and one where I leave out the nested (The queries themselves might have lowercase-uppercase mistakes in the field names because I used an online autoformatter. The EXPLAIN QUERY PLAN and EXPLAIN were done with the original everything-in-one-line query.) Original query: SELECT "id",
"createdat",
"googlecountry",
"title",
"searchquery",
"snippeturl",
"snippetcontent",
"videosranking",
"relatedsearches",
"relatedquestions",
"userid",
(SELECT COALESCE(Json_group_array(Json_array("id", "articleid",
"pineconeids")),
Json_array()) AS "data"
FROM "pineconereferences" "articles_pineconeReferences"
WHERE "articles_pineconeReferences"."articleid" = "articles"."id") AS
"pineconeReferences",
(SELECT COALESCE(Json_group_array(Json_array("id", "createdat",
"articleid",
(SELECT COALESCE(
Json_group_array(
Json_array
("id", "createdat", "headinglevel",
"headingtext"
,
"position"
,
"selected"
, "content", "contentbrief",
"outlinedraftid")), Json_array()) AS "data"
FROM "draftpieces"
"articles_outlineDrafts_draftPieces"
WHERE
"articles_outlineDrafts_draftPieces"."outlinedraftid" =
"articles_outlineDrafts"."id"))), Json_array()) AS
"data"
FROM "outlinedrafts" "articles_outlineDrafts"
WHERE "articles_outlineDrafts"."articleid" = "articles"."id") AS
"outlineDrafts"
FROM "articles"
WHERE "articles"."userid" = ? -- params: [1] Working query: SELECT "id",
"createdat",
"googlecountry",
"title",
"searchquery",
"snippeturl",
"snippetcontent",
"videosranking",
"relatedsearches",
"relatedquestions",
"userid",
(SELECT COALESCE(Json_group_array(Json_array("id", "articleid",
"pineconeids")),
Json_array()) AS "data"
FROM "pineconereferences" "articles_pineconeReferences"
WHERE "articles_pineconeReferences"."articleid" = "articles"."id") AS
"pineconeReferences",
(SELECT COALESCE(Json_group_array(Json_array("id", "createdat",
"articleid")),
Json_array()) AS "data"
FROM "outlinedrafts" "articles_outlineDrafts"
WHERE "articles_outlineDrafts"."articleid" = "articles"."id") AS
"outlineDrafts"
FROM "articles"
WHERE "articles"."userid" = ? -- params: [1] Original query EXPLAIN QUERY PLAN:
Working query EXPLAIN QUERY PLAN:
Original query EXPLAIN:
Working query EXPLAIN:
|
Getting the same error for almost all the queries with multiple nested tables using Drizzle ORM. Here is the example of a query that's failing select
"id",
"title",
"description",
"slug",
"sku",
"stock",
"is_always_in_stock",
"is_visible",
"product_unit_value",
"product_unit",
"mrp",
"sale_price",
"created_at",
"category_id",
"organization_id",
"tax_id",
"status",
"priority",
"length",
"width",
"height",
"weight",
(
select
json_array("id",
"name",
"description",
"slug",
"is_visible",
"image",
"created_at",
"organization",
"priority",
"parent") as "data"
from
(
select
*
from
"categories" "products_category"
where
"products_category"."id" = "products"."category_id"
limit ?) "products_category") as "category",
(
select
coalesce(json_group_array(json_array("product_id",
"media_id",
(
select
json_array("id",
"created_at",
"url",
"thumbnail_url",
"organization_id",
"media_type") as "data"
from
(
select
*
from
"media" "products_mediaOnProducts_media"
where
"products_mediaOnProducts_media"."id" = "products_mediaOnProducts"."media_id"
limit ?) "products_mediaOnProducts_media"))),
json_array()) as "data"
from
"products_to_media" "products_mediaOnProducts"
where
"products_mediaOnProducts"."product_id" = "products"."id") as "mediaOnProducts",
(
select
coalesce(json_group_array(json_array("id",
"type",
"name",
"product_id",
(
select
coalesce(json_group_array(json_array("id",
"name",
"value",
"product_variant_id")),
json_array()) as "data"
from
"product_variant_items" "products_variants_items"
where
"products_variants_items"."product_variant_id" = "products_variants"."id"))),
json_array()) as "data"
from
"product_variants" "products_variants"
where
"products_variants"."product_id" = "products"."id") as "variants",
(
select
coalesce(json_group_array(json_array("combination_id",
"price",
"stock",
"product_id",
"media_id",
"combination_description",
(
select
coalesce(json_group_array(json_array("combination_id",
"product_variant_item_id")),
json_array()) as "data"
from
"product_variant_combination_items" "products_variantCombinations_items"
where
"products_variantCombinations_items"."combination_id" = "products_variantCombinations"."combination_id"),
(
select
json_array("id",
"created_at",
"url",
"thumbnail_url",
"organization_id",
"media_type") as "data"
from
(
select
*
from
"media" "products_variantCombinations_media"
where
"products_variantCombinations_media"."id" = "products_variantCombinations"."media_id"
limit ?) "products_variantCombinations_media"))),
json_array()) as "data"
from
"product_variant_combinations" "products_variantCombinations"
where
"products_variantCombinations"."product_id" = "products"."id") as "variantCombinations"
from
"products"
where
"products"."id" = ?
limit ? |
This is something we're looking into. The |
Thanks, unfortunately, I deleted my alpha database today and created a new one and now I am facing this problem almost in my entire app. Is there a workaround? Do multiple joins add to the query depth? |
Yes, the more joins and/or CTEs -> the deeper the query tree. |
Are you planning to increase the depth? If yes, anytime soon? |
I provided the actual EXPLAIN without QUERY PLAN as well. Do you need anything else or was that comment not for me (assuming it was because I was the only one giving a EXPLAIN QUERY PLAN) |
@elithrar Thank you - Quick question though, what exactly would you need to get the exact expression tree depth? |
For those following: we expect this increased limit to be released within the next week. |
When is this getting released? |
@subhendupsingh This is now deployed. We typically like to wait until the release has been stable for a few days before commenting. |
Got it, should I update my wrangler now to get the changes? |
@subhendupsingh - this change is not related to wrangler (which is client-side). Your queries, provided they fall within the new limit, should work. Again, because SQLite's query plan does not make the expression depth of a query obvious, if your query is still hitting the new limit of 100 then I would suggest working to reduce the complexity of your query. |
I am still running into the error and it explicitly says that the max depth is 20. I haven't updated anything. |
If you're using
|
Describe the solution
I upgraded my wrangler v2 to v3 and in that process I start getting
Expression tree is too large (maximum depth 20)
for some queries.In the Discord, we figured out that wrangler v2 and my prod database are on the alpha backend (which explains why it's been working on prod for the whole time). But the new version of wrangler seems to have created a beta-d1 binding.
I've been asked to submit the query here so we can discuss potential use cases where a higher depth than 20 may be necessary and useful. The query is in drizzle, I have done research but haven't found a good way to extract the generated SQL:
While increasing the limit would be nice of course, since I need basic queries like the one above all the time but the two most important things right now for me:
The text was updated successfully, but these errors were encountered: