Removing duplicate-ish paths generated from recursive CTE
You need NOT EXISTS and the contains operator reversed:

select 
    q1.* 
from 
    common_ancestors q1
where not exists
    ( select 1 
      from   common_ancestors q2
      where  q1.id_path_array @&gt; q2.id_path_array 
        and  q1.item_id &lt;&gt; q2.item_id
    ) ;


Test in dbfiddle.uk