As discussed in
SERVER-57225, SBE plans with large top-level ANDs may result in a stack overflow. While fixing this particular scenario is straightforward, there may be other queries which cause stack overflow in SBE that we have not discovered yet.
We should spend some time investigating whether any such queries exist, and if so, build a more generic mechanism for tracking SBE tree depth during plan construction. If the plan exceeds some fixed depth, we'd have to bail out and either use the classic engine (or, eventually fail the query).
A few ideas for queries which may be able to trigger this:
-A query with a filter or projection on a very long path (a.b.c.d.e.f...)
-A query with many nested $and and $ors
-A query with a $slice or positional projection on a very long path