private boolean nonIdenticalTrees(Item root1, Item root2) {
        if (root1 instanceof CompositeItem) {
            boolean nonID = root1 != root2;
            Iterator<?> i1 = ((CompositeItem) root1).getItemIterator();
            Iterator<?> i2 = ((CompositeItem) root2).getItemIterator();

            while (i1.hasNext() && nonID) {
                nonID &= nonIdenticalTrees((Item) i1.next(), (Item) i2.next());
            }
            return nonID;

        } else {
            return root1 != root2;
        }
    }
Check copy of query trees is a deep copy
container-search/src/test/java/com/yahoo/prelude/query/test/QueryTestCase.java