Some complex queries containing (non-recursive) CTEs cannot be decorrelated by the current Calcite decorrelator. Sometimes decomposing such queries into a sequence of LOCAL VIEWs, one for each CTE, makes the query compilable. Implement a compiler analysis which performs this rewrite.
This will have to be performed on the SqlNode layer, after validation, since the Rel layer does not have a notion of CTE.
This could be exposed as a compiler option for manual use.
It should also be an automatic strategy to try recompiling a query if the decorrelator fails.
Some complex queries containing (non-recursive) CTEs cannot be decorrelated by the current Calcite decorrelator. Sometimes decomposing such queries into a sequence of LOCAL VIEWs, one for each CTE, makes the query compilable. Implement a compiler analysis which performs this rewrite.
This will have to be performed on the SqlNode layer, after validation, since the Rel layer does not have a notion of CTE.
This could be exposed as a compiler option for manual use.
It should also be an automatic strategy to try recompiling a query if the decorrelator fails.