public abstract class Sort extends SingleRel implements Hintable
RelNode.Context| Modifier and Type | Field and Description |
|---|---|
RelCollation |
collation |
@Nullable RexNode |
fetch |
protected com.google.common.collect.ImmutableList<RelHint> |
hints |
@Nullable RexNode |
offset |
digest, id, rowType, traitSet| Modifier | Constructor and Description |
|---|---|
protected |
Sort(RelInput input)
Creates a Sort by parsing serialized output.
|
protected |
Sort(RelOptCluster cluster,
RelTraitSet traits,
List<RelHint> hints,
RelNode child,
RelCollation collation,
@Nullable RexNode offset,
@Nullable RexNode fetch)
Creates a Sort.
|
protected |
Sort(RelOptCluster cluster,
RelTraitSet traits,
RelNode child,
RelCollation collation)
Creates a Sort.
|
protected |
Sort(RelOptCluster cluster,
RelTraitSet traits,
RelNode child,
RelCollation collation,
@Nullable RexNode offset,
@Nullable RexNode fetch)
Creates a Sort.
|
| Modifier and Type | Method and Description |
|---|---|
RelNode |
accept(RexShuttle shuttle)
Accepts a visit from a shuttle.
|
@Nullable RelOptCost |
computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq)
Returns the cost of this plan (not including children).
|
Sort |
copy(RelTraitSet traitSet,
List<RelNode> inputs)
Creates a copy of this relational expression, perhaps changing traits and
inputs.
|
Sort |
copy(RelTraitSet traitSet,
RelNode newInput,
RelCollation newCollation) |
abstract Sort |
copy(RelTraitSet traitSet,
RelNode newInput,
RelCollation newCollation,
@Nullable RexNode offset,
@Nullable RexNode fetch) |
RelWriter |
explainTerms(RelWriter pw)
Describes the inputs and attributes of this relational expression.
|
RelCollation |
getCollation()
Returns the array of
RelFieldCollations asked for by the sort
specification, from most significant to least significant. |
com.google.common.collect.ImmutableList<RelHint> |
getHints()
Returns the hints of this relational expressions as an immutable list.
|
List<RexNode> |
getSortExps()
Returns the sort expressions.
|
boolean |
isEnforcer()
Indicates whether it is an enforcer operator, e.g.
|
childrenAccept, deriveRowType, estimateRowCount, getInput, getInputs, replaceInputaccept, collectVariablesSet, collectVariablesUsed, deepEquals, deepHashCode, equals, explain, getCluster, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getRelDigest, getRelTypeName, getRowType, getTable, getTraitSet, getVariablesSet, hashCode, isValid, metadata, onRegister, recomputeDigest, register, sole, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitattachHints, withHintsexplain, fieldIsNullablepublic final RelCollation collation
public final @Nullable RexNode offset
public final @Nullable RexNode fetch
protected final com.google.common.collect.ImmutableList<RelHint> hints
protected Sort(RelOptCluster cluster, RelTraitSet traits, List<RelHint> hints, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch)
cluster - Cluster this relational expression belongs totraits - Traitshints - Hints for this nodechild - input relational expressioncollation - array of sort specificationsoffset - Expression for number of rows to discard before returning
first rowfetch - Expression for number of rows to fetchprotected Sort(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelCollation collation)
cluster - Cluster this relational expression belongs totraits - Traitschild - input relational expressioncollation - array of sort specificationsprotected Sort(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelCollation collation, @Nullable RexNode offset, @Nullable RexNode fetch)
cluster - Cluster this relational expression belongs totraits - Traitschild - input relational expressioncollation - array of sort specificationsoffset - Expression for number of rows to discard before returning
first rowfetch - Expression for number of rows to fetchprotected Sort(RelInput input)
public final Sort copy(RelTraitSet traitSet, List<RelNode> inputs)
RelNodeSub-classes with other important attributes are encouraged to create variants of this method with more parameters.
copy in interface RelNodecopy in class AbstractRelNodetraitSet - Trait setinputs - Inputspublic final Sort copy(RelTraitSet traitSet, RelNode newInput, RelCollation newCollation)
public abstract Sort copy(RelTraitSet traitSet, RelNode newInput, RelCollation newCollation, @Nullable RexNode offset, @Nullable RexNode fetch)
public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
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:
fetch is zero, CPU cost is zero; otherwise,
min(fetch + offset, inputRowCount) * bytesPerRow; otherwise
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.
computeSelfCost in interface RelNodecomputeSelfCost in class AbstractRelNodeplanner - Planner for cost calculationmq - Metadata querypublic RelNode accept(RexShuttle shuttle)
RelNodeaccept in interface RelNodeaccept in class AbstractRelNodeshuttle - Shuttlepublic boolean isEnforcer()
RelNodeisEnforcer in interface RelNodeisEnforcer in class AbstractRelNodepublic RelCollation getCollation()
RelFieldCollations asked for by the sort
specification, from most significant to least significant.
See also RelMetadataQuery.collations(RelNode),
which lists all known collations. For example,
ORDER BY time_id might also be sorted by
the_year, the_month because of a known monotonicity
constraint among the columns. getCollation would return
[time_id] and collations would return
[ [time_id], [the_year, the_month] ].
public RelWriter explainTerms(RelWriter pw)
AbstractRelNodesuper.explainTerms, then call the
RelWriter.input(String, RelNode)
and
RelWriter.item(String, Object)
methods for each input and attribute.explainTerms in class SingleRelpw - Plan writerCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.