Querying collections of tree-structured records in the presence of within-record referential constraints