1. A method for compiling a query, comprising: monitoring memory consumption of the query; processing the query to acquire one or more gateways if the amount of memory consumed by the query exceeds one or more gateway thresholds; and compiling the query as having acquired the one or more gateways.