This is a followup to
For certain WHERE clauses, range optimizer may consume O(N^2) memory.
The cause of this is that tree_or() allocates its result on MEM_ROOT, while the arguments also remain allocated on MEM_ROOT (See
MDEV-21958 for details). MDEV-21958 itself is marked as closed because I've pushed a limited-scope fix that prevented this behavior for a subset of queries.