Class ImplementLimitWithTies

java.lang.Object
io.trino.sql.planner.iterative.rule.ImplementLimitWithTies
All Implemented Interfaces:
Rule<LimitNode>

public class ImplementLimitWithTies extends Object implements Rule<LimitNode>
Transforms:

 - Limit (row count = x, tiesResolvingScheme(a,b,c))
    - source
 
Into:

 - Project (prune rank symbol)
    - Filter (rank <= x)
       - Window (function: rank, order by a,b,c)
          - source
 
  • Constructor Details

    • ImplementLimitWithTies

      public ImplementLimitWithTies(Metadata metadata)
  • Method Details

    • getPattern

      public Pattern<LimitNode> getPattern()
      Description copied from interface: Rule
      Returns a pattern to which plan nodes this rule applies.
      Specified by:
      getPattern in interface Rule<LimitNode>
    • apply

      public Rule.Result apply(LimitNode parent, Captures captures, Rule.Context context)
      Specified by:
      apply in interface Rule<LimitNode>
    • rewriteLimitWithTiesWithPartitioning

      public static PlanNode rewriteLimitWithTiesWithPartitioning(LimitNode limitNode, PlanNode source, Session session, Metadata metadata, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator, List<Symbol> partitionBy)
      Rewrite LimitNode with ties to WindowNode and FilterNode, with partitioning defined by partitionBy.

      This method does not prune outputs of the rewritten plan. After the rewrite, the output consists of source's output symbols and the newly created rankSymbol. Passing all input symbols is intentional, because this method is used for de-correlation in the scenario where the original LimitNode is in the correlated subquery, and the rewrite result is placed on top of de-correlated join. It is the responsibility of the caller to prune redundant outputs.