Who knows the rule of construct nested query?

Who knows the rule of construct nested query? And where is it in the source code? I can only find one place that looks related: metabase.driver.sql.query-processor/expressions-subselect function. Does all logic is in this function or have another code?

Hi @caidaoliuhai
Not sure what you're looking for, but if it the use of Saved Questions as the base, then it's part of the middleware:
https://github.com/metabase/metabase/blob/master/src/metabase/query_processor/middleware/fetch_source_query.clj

Not use of Saved Questions as the base, I mean when I create a custom query, how to judge nested query? So far I just know if the custom query contains an expression that will into expressions-subselect, So where is another rule about produce nested-query?

If contains expression and contains aggregation or breakout need nested
if contains expression and contains orderBy or filter need nested
Does these two rules is right?

@caidaoliuhai This depends on the database being queried, but yes, expressions causes nesting. And so does multiple aggregations/breakouts.

Only think sql(mysql) case, so I just can find code about expression, the question is where is code about aggregations/breakouts ?

also orderby and filter

@caidaoliuhai I don't know. Try searching for closed issues, which was related to what you're looking for and look at the PRs that fixed it.

Okay´╝î Thank you