# GROUP BY

Tuple filtering is applied for a GROUP BY when the following criteria are met:

- All grouping columns come from the same table and the optimizer has chosen the table in question to be the outermost table in the query block.
- The optimizer has chosen an index as the access path for the table in question.
- The grouping columns, plus any simple column references from the table that have equality predicates on them, are a prefix of the index that the optimizer selected as the access path for the table.

Here is the most common case in which tuple filtering will be applied:

    SELECT max(c2) FROM t1 GROUP BY c1

Equality predicates allow tuple filtering on the following:

    SELECT c2, SUM(c3)
    FROM t1
    WHERE c1 = 5 GROUP BY c2

    SELECT max(c4)
    FROM t1
    WHERE c1 = 5 AND c3 = 6 GROUP BY c2

Parent topic: Non-cost-based sort avoidance (tuple filtering)
Related concepts
DISTINCT