1. A method of opt 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 to 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 second hierarchical tree from the first hierarchal tree by replacing the source node with a sub-tree that corresponds to a filtered selection of the corresponding table from a 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; and determining a second database query that corresponds to the second hierarchical tree.