A tagging tree that defines a hierarchical output data structure and
relational database query operations that retrieve the data to be
included in each hierarchical section is accepted and processed. A query
optimizer analyzes the tagging tree to determine database query
operations that can be combined into a single query command. An
outer-union query command is generated to allow efficient combination of
multiple query commands, some of which are predicates to others. The
tagging tree is modified to replace the database queries that were
combined into the outer-union query to extract data from the results set
produced by the outer-union query as opposed to submitting queries to the
database manager. The optimized queries can be reused an arbitrary number
of times to leverage the optimizing resources that were used in their
creation.