Fix for the "(x AND y) OR z" bug backported to version 3.6.21.