Implementation of sql histograms