Patent ID: 9501536
Filing Date: 2016-11-22
CPC Classification: G06F

Claim Text:
1. A computer-implemented method comprising: receiving an initial query plan generated for a query that includes a common expression that occurs multiple times in the query; identifying two or more matching subtrees of the initial query plan that each include operators for computing results for the common expression; generating an alternative query plan that includes a common table expression producer operator and having an instance of one of the matching subtrees as one or more descendant operators of the common table expression producer operator wherein the common table expression producer operator receives a result computed by the descendent operators and stores the result, the generating including replacing at least one instance of an identified matching subtree in the initial query plan with a common table expression consumer operator corresponding to the common table expression producer operator, wherein the common table expression consumer operator retrieves the stored result; computing respective costs for the initial query plan and the alternative query plan; selecting the alternative query plan based on the cost for the alternative query plan; and computing a result for the query using the alternative query plan instead of the initial query plan.