1. A method for optimizing a query of a table based on one or more values in one or more columns of the table, the table having available rows, comprising the steps of: repeating the following steps for a series of rows in the table and optimizing an execution plan for the query based at least in part on a calculated number of rows per unique value; reading the one or more values for the one or more columns; determining whether the read values are different from all previously read values; and if the read values are different, recording the one or more values in a first data structure pointed to by an entry in a second data structure, including determining a location of the entry in the second data structure by applying a hash function to the one or more values.