Patent ID: 8396852

Claim:
A method comprising: creating an execution plan for a query; calculating a first wakeup threshold time period, wherein the calculating the first wakeup threshold time period further comprises setting the first wakeup threshold time period proportional to an amount of time taken by the creating the execution plan; executing a portion of the execution plan for the query to produce a portion of rows in a result set until the first wakeup threshold time period expires; and after the first wakeup threshold time period expires, evaluating changes to the execution plan, wherein the evaluating further comprises if a ratio of rows eliminated from the result set by successive joins of a first table and a second table is greater than a starvation threshold and a number of the portion of rows in the result set is more than a threshold difference from an estimated number of rows, determining whether an estimated cost of a forced primary join is less than an estimated cost of a star join, and if the estimated cost of the forced primary join is less than the estimated cost of the star join, moving the second table first in a join order in the execution plan, discarding the portion of rows in the result set, and re-starting the executing to produce a different portion of the rows.