This fixes accidental memory corruption leading to segfaults. When truncating a CTE we need to remove its nested target list truncation from the list of possibilities, otherwise we'll end up referencing an object that no longer exists. This PR uses std::mem::replace to return the previous SelectStmt so it can be removed from truncations before the next iteration.
Two other bugfixes:
don't attempt truncating target lists when they're empty (accidentally adds a ... which just makes the query longer)
if node truncations aren't sufficient, apply simple truncation as a fallback on the node-truncated string instead of on the source string
Review question: are there other truncation types where we could run into memory corruption? I tried subqueries in both SELECT and FROM and couldn't trigger another segfault.
Oh, I forgot to note: the std::mem::replace code is implemented in such a way that it should prevent the same bug from happening for any other statement type inside a CTE, not just selects.
This fixes accidental memory corruption leading to segfaults. When truncating a CTE we need to remove its nested target list truncation from the list of possibilities, otherwise we'll end up referencing an object that no longer exists. This PR uses
std::mem::replace
to return the previousSelectStmt
so it can be removed fromtruncations
before the next iteration.Two other bugfixes:
...
which just makes the query longer)Review question: are there other truncation types where we could run into memory corruption? I tried subqueries in both
SELECT
andFROM
and couldn't trigger another segfault.