1. A method for constructing a histogram, comprising: sampling attributes in a column of a database on a server; determining a bucket set comprising a number of buckets that represents a distribution of the attributes with minimum error, wherein at least one bucket includes boundaries and an approximation of a count of attributes falling within the boundaries; determining a precision for encoding the approximation, wherein a histogram having the bucket set fits within a storage limit and wherein the precision includes a bit threshold for the approximation of the count of the attributes; and storing the histogram for the database by encoding the approximation with the precision for encoding the approximation.