1. A computer-implemented method of optimizing a nested database query that includes at least one inner sub-query, at least one outer subquery, one or more window functions in the at least one inner sub-query, and one or more filtering operations in the at least one outer sub-query, wherein evaluation of the inner and outer sub-queries requires construction of one or more intermediate tables, and wherein the computer-implemented method comprises: obtaining the nested database query for processing by a database system; evaluating the obtained nested database query by at least the following: (i) determining that the inner sub-query includes a sampling operation, and (ii) determining that the nested database query includes at least one inner join operation joining at least two inner sub-queries, wherein at least one of the inner sub-queries includes one or more window functions; determining based on the evaluating whether to represent the one or more filtering operations of the at least one outer sub-query as one or more corresponding qualification operations associated with the one or more window functions in the at least one inner sub-query, (iii) wherein it is determined not to represent the one or more filtering operations as the one or more corresponding qualification operations when it is determined that the inner sub-query includes a sampling operation; and (iv) wherein it is determined to represent at least one filtering operation of an outer sub-query as a qualification operation of one or more window functions in either one of the inner sub-queries when it is determined that the query includes at least one inner join operation joining at least two inner sub-queries; effectively representing the one or more filtering operations of the at least one outer sub-query as the one or more corresponding qualification operations associated with the one or more window functions in the at least one inner subquery when the determining determines to represent the one or more filtering operations as the one or more corresponding qualification operations; obtaining a modified database query which is equivalent to the nested database query but is evaluated with intermediate tables that are reduced in size with respect to the one or more intermediate tables that are required to evaluate the database query in its original form and; evaluating the modified database query with the intermediate tables that are reduced in size with respect to the one or more intermediate tables that are required to evaluate the database query in its original form, in order to process that obtained nested database query.