This error can appear when the Query is extracting a high number of entries and your system is unable to extract all the data at the same time.
Studio 11.x and Higher
Enable the Data Chunking feature in Query to avoid extracting all the data at the same time. When selecting a value to chunk at we suggest testing different values to find the highest number that will give a successful run.
Studio 11.x / 12.x, in Developer Settings on the Run tab:
Query 10.x, in the Advanced Run Options panel: