1. A method of optimizing a database query, the method comprising: accessing a first database query, the first database query including selection operations directed to one or more tables in a database; determining a first hierarchical tree that corresponds to the first database query, the first hierarchical tree including at least one source node for each of the one or more tables in the first database query; identifying a source node of the first hierarchal tree as highly selective if a selectivity condition is satisfied by a corresponding table for the source node or as not highly selective if the selectivity condition is not satisfied by the corresponding table for the source node, the selectivity condition corresponding to a limit on a number of rows accessed in the corresponding table; determining a filtered selection of the corresponding table from a larger table in the database by selecting one or more values of a data-access key that identifies rows of the larger table based on an access condition that restricts access to values of the larger table; determining a second hierarchical tree from the first hierarchal tree by replacing the source node with a sub-tree that corresponds to the filtered selection of the corresponding table from the larger table in the database, the sub-tree including an intermediate table that characterizes the filtered selection from the larger table if the source node is identified as not highly selective, and the sub-tree not including an intermediate table that characterizes the filtered selection from the larger table if the corresponding source node is identified as highly selective; determining a second database query that corresponds to the second hierarchical tree; and providing the second database query to the database for execution.