I'm curious why you added this check to the beginning and surrounded the rest with parentheses. Wouldn't it be better to follow the example of the surrounding clauses and an "AND NOT p.inherited" somewhere in the middle?
Good point. v2 moves the check inside the EXISTS as "AND NOT p.inherited", consistent with how the inheritance sections below handle it.