Efficient query evaluation for DAG-shaped hierarchies