In a computer database system, queries are applied against stored data including at least one hierarchy representing divisions of the stored data and responses to queries depend on the hierarchy, a hierarchical data structure representing parent-child pairings is input and a flattened hierarchical data structure representing a transitive closure of the hierarchy represented by the hierarchical data structure is generated. The flattened hierarchical data structure is used in generating a response to a query.