1. A method, implemented at least partly by a device, for generating an execution plan for a database query of a database, wherein the database query requires multiple sub-queries to be executed as multiple iterations such that a result of a first one of the sub-queries is needed to be determined in a first iteration of the iterations in order to determine the result of a second one of the sub-queries in a second iteration of the iterations to be performed after the first iteration, and wherein the method comprises: estimating at least one result associated with execution of multiple iterations of the iterations at least partly based on a sampling or sampling-based technique by at least iteratively computing one or more join values, wherein the estimating of the at least one result of execution of the multiple iterations of the iterations comprises: using a sampling or sampling-based technique that estimates the at least one size of at least one result by sampling a subset of data of one or more database tables of the database associated with the database query; and wherein the using of the sampling technique comprises: selecting a starting value from the one or more database tables as a sample of the sampling technique; and iteratively computing all joining values of the starting value from the one or more database tables while storing the size of a first result at each iteration of the first number of iterations in a respective slot; and generating at least partly based on the at least one estimated result of the multiple iterations, a first execution plan for executing the multiple iterations.