1. A method for compiling a query, comprising: monitoring memory consumption of a first compilation of the query; acquiring a first gateway for the query if the memory consumption of the first compilation exceeds a first gateway threshold and the first gateway is available, wherein the first gateway is available if a number of queries as having acquired the first gateway is less than four queries per CPU; throttling the query if the memory consumption of the first compilation exceeds the first gateway threshold and the first gateway is not available; monitoring memory consumption of a second compilation of the query after having acquired the first gateway; acquiring a second gateway for the query if the memory consumption of the second compilation of the query exceeds a second gateway threshold and the second gateway is available, wherein the second gateway is available if a number of queries as having acquired the second gateway is less than one query per CPU; and throttling the query if the memory consumption of the second compilation exceeds the second gateway threshold and the second gateway is not available.