Subqueries In the rewritten query,  REJECT_IF()  represents an internal function which tests a given condition (here, the comparison  ct > 1 ) and raises a given error (in this case,  ER_SUBQUERY_NO_1_ROW ) if the condition is true. This reflects the cardinality check that the optimizer performs as part of evaluating the  JOIN  or WHERE  clause, prior to evaluating any lifted predicate, which is done only if the subquery does not return more than one row. This type of transformation can be performed, provided the following conditions are met: See also Section 13.2.11.8, “Derived Tables” . This section discusses general characteristics of derived tables. For information about lateral derived tables preceded by the  LATERAL  keyword, see Section 13.2.11.9, “Lateral Derived Tables” . A derived table is an expression that generates a table within the scope of a query  FROM  clause. For example, a subquery in a  SELECT  statement  FROM  clause is a derived table: SELECT ... FROM ( subquery ) [AS]  tbl_name  ... 2690 13.2.11.8 Derived Tables •The subquery can be part of a  SELECT  list,  WHERE  condition, or  HAVING  condition, but cannot be part of a  JOIN  condition, and cannot contain a  LIMIT  or  OFFSET  clause. In addition, the subquery cannot contain any set operations such as  UNION . •The  WHERE  clause may contain one or more predicates, combined with  AND . If the  WHERE  clause contains an  OR  clause, it cannot be transformed. At least one of the  WHERE  clause predicates must be eligible for transformation, and none of them may reject transformation. •To be eligible for transformation, a  WHERE  clause predicate must be an equality predicate in which each operand should be a simple column reference. No other predicates—including other comparison predicates—are eligible for transformation. The predicate must employ the equality operator  =  for making the comparison; the null-safe  ≪ =>  operator is not supported in this context. •A  WHERE  clause predicate that contains only inner references is not eligible for transformation, since it can be evaluated before the grouping. A  WHERE  clause predicate that contains only outer references is eligible for transformation, even though it can be lifted up to the outer query block. This is made possible by adding a cardinality check without grouping in the derived table. •To be eligible, a  WHERE  clause predicate must have one operand that contains only inner references and one operand that contains only outer references. If the predicate is not eligible due to this rule, transformation of the query is rejected. •A correlated column can be present only in the subquery’s  WHERE  clause (and not in the  SELECT  list, a  JOIN  or  ORDER BY  clause, a  GROUP BY  list, or a  HAVING  clause). Nor can there be any correlated column inside a derived table in the subquery’s  FROM  list. •A correlated column can not be contained in an aggregate function’s list of arguments. •A correlated column must be resolved in the query block directly containing the subquery being considered for transformation. •A correlated column cannot be present in a nested scalar subquery in the  WHERE  clause. •The subquery cannot contain any window functions, and must not contain any aggregate function which aggregates in a query block outer to the subquery. A  COUNT()  aggregate function, if contained in the SELECT  list element of the subquery, must be at the topmost level, and cannot be part of an expression.