[WIP] Fix EZP-22830: having query with LogicalNot generating subquery returns empty result set

This PR resolves issue https://jira.ez.no/browse/EZP-22830