Suppose the stored query S (stored in U) is:
and suppose the input query Q on T is:
We say that Q matches S because Q matches the evaluation of:
so the query R
can be evaluated on U.
This is so because g_sum on break-column city is indifferent to whether the selection occurs before or after the g_sum.
Now consider the following example:
Table T has columns state and city, and no city belongs to more than one state. The stored query S is as above, and the input query Q is:
The canselect attribute lists those columns whose extensions are supersets of the extensions of the break columns. We can therefore know that the evaluation of Q will match the evaluation of:
and therefore that we may replace Q on T with R on U: