1. A method of generating an optimized set of queries, comprising: determining a first set of queries that collect data from an intermediate data buffer for a data destination; determining, from the first set of queries, a second set of queries that collect data from a data source for the intermediate data buffer; and generating, by a computer, an optimized set of queries that collect data from the data source for the data destination based on the first and second sets of queries.