There are two ways to approach this task: easy and hard.
- Easy.
When searching inside the query cache, also try to find the query after removal of LIMIT; LIMIT BY; ORDER BY; GROUP BY; WHERE. If found, construct a query pipeline that will use the data from the cache but apply the missing transformations.
- Hard.
Serialize the query plan and put it into the cache instead of the AST hash. Search for incomplete query plans that could be completed.
Obviously, we should choose the easy way.