Description
Here is a simple example for a failing query:
with cse1 as (select * from (values (1)) T(a)) select count(*) from cse1 where a > (select avg(a) from cse1); *** ERROR[3288] A syntax error occurred. WITH clause redefined. WITH name CSE1 . *** ERROR[8822] The statement was not prepared.
There are really two things going on here:
- We hit an assert in RelRoot::transformNode() that assumes there are no subqueries above the RelRoot.
- The error we see is different, however. That's because the initial assert triggers AQR (auto-query retry). When we compile the query a second time, it still has the CTE from the first time, and that causes the error 3288. So, we also need to initialize the parser list of CTEs before a recompilation.
This is the original assert we hit:
// We are currently assuming that no subqueries have been introduced above me; // any new subquery parent would just silently be ignored! CMPASSERT( this == locationOfPointerToMe ); // Genesis 10-970828-6025