Class InnodbSort

All Implemented Interfaces:
Cloneable, InnodbRel, RelOptNode, Hintable, RelNode

public class InnodbSort extends Sort implements InnodbRel
Implementation of Sort relational expression for an InnoDB data source.
  • Method Details

    • computeSelfCost

      public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
      Description copied from class: Sort
      Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.

      NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getNonCumulativeCost(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about cost.

      The CPU cost of a Sort has three main cases:

      • If fetch is zero, CPU cost is zero; otherwise,
      • if the sort keys are empty, we don't need to sort, only step over the rows, and therefore the CPU cost is min(fetch + offset, inputRowCount) * bytesPerRow; otherwise
      • we need to read and sort inputRowCount rows, with at most min(fetch + offset, inputRowCount) of them in the sort data structure at a time, giving a CPU cost of inputRowCount * log(min(fetch + offset, inputRowCount)) * bytesPerRow.

      The cost model factors in row width via bytesPerRow, because sorts need to move rows around, not just compare them; by making the cost higher if rows are wider, we discourage pushing a Project through a Sort. We assume that each field is 4 bytes, and we add 3 'virtual fields' to represent the per-row overhead. Thus a 1-field row is (3 + 1) * 4 = 16 bytes; a 5-field row is (3 + 5) * 4 = 32 bytes.

      The cost model does not consider a 5-field sort to be more expensive than, say, a 2-field sort, because both sorts will compare just one field most of the time.

      Specified by:
      computeSelfCost in interface RelNode
      Overrides:
      computeSelfCost in class Sort
      Parameters:
      planner - Planner for cost calculation
      mq - Metadata query
      Returns:
      Cost of this plan (not including children)
    • copy

      public Sort copy(RelTraitSet traitSet, RelNode input, RelCollation newCollation, RexNode offset, RexNode fetch)
      Specified by:
      copy in class Sort
    • implement

      public void implement(InnodbRel.Implementor implementor)
      Specified by:
      implement in interface InnodbRel