public abstract class Sort
extends org.apache.calcite.rel.SingleRel
implements org.apache.calcite.rel.hint.Hintable
Temporarily copy from calcite to cherry-pick [CALCITE-5107] and will be removed when upgrade the latest calcite.
Modifier and Type | Field and Description |
---|---|
org.apache.calcite.rel.RelCollation |
collation |
@Nullable org.apache.calcite.rex.RexNode |
fetch |
protected com.google.common.collect.ImmutableList<org.apache.calcite.rel.hint.RelHint> |
hints |
@Nullable org.apache.calcite.rex.RexNode |
offset |
Modifier | Constructor and Description |
---|---|
protected |
Sort(org.apache.calcite.rel.RelInput input)
Creates a Sort by parsing serialized output.
|
protected |
Sort(org.apache.calcite.plan.RelOptCluster cluster,
org.apache.calcite.plan.RelTraitSet traits,
List<org.apache.calcite.rel.hint.RelHint> hints,
org.apache.calcite.rel.RelNode child,
org.apache.calcite.rel.RelCollation collation,
@Nullable org.apache.calcite.rex.RexNode offset,
@Nullable org.apache.calcite.rex.RexNode fetch)
Creates a Sort.
|
protected |
Sort(org.apache.calcite.plan.RelOptCluster cluster,
org.apache.calcite.plan.RelTraitSet traits,
org.apache.calcite.rel.RelNode child,
org.apache.calcite.rel.RelCollation collation)
Creates a Sort.
|
|
Sort(org.apache.calcite.plan.RelOptCluster cluster,
org.apache.calcite.plan.RelTraitSet traits,
org.apache.calcite.rel.RelNode child,
org.apache.calcite.rel.RelCollation collation,
org.apache.calcite.rex.RexNode offset,
org.apache.calcite.rex.RexNode fetch)
Creates a Sort.
|
Modifier and Type | Method and Description |
---|---|
org.apache.calcite.rel.RelNode |
accept(org.apache.calcite.rex.RexShuttle shuttle) |
@Nullable org.apache.calcite.plan.RelOptCost |
computeSelfCost(org.apache.calcite.plan.RelOptPlanner planner,
org.apache.calcite.rel.metadata.RelMetadataQuery mq) |
Sort |
copy(org.apache.calcite.plan.RelTraitSet traitSet,
List<org.apache.calcite.rel.RelNode> inputs) |
Sort |
copy(org.apache.calcite.plan.RelTraitSet traitSet,
org.apache.calcite.rel.RelNode newInput,
org.apache.calcite.rel.RelCollation newCollation) |
abstract Sort |
copy(org.apache.calcite.plan.RelTraitSet traitSet,
org.apache.calcite.rel.RelNode newInput,
org.apache.calcite.rel.RelCollation newCollation,
@Nullable org.apache.calcite.rex.RexNode offset,
@Nullable org.apache.calcite.rex.RexNode fetch) |
org.apache.calcite.rel.RelWriter |
explainTerms(org.apache.calcite.rel.RelWriter pw) |
org.apache.calcite.rel.RelCollation |
getCollation()
Returns the array of
RelFieldCollation s asked for by the sort specification, from
most significant to least significant. |
com.google.common.collect.ImmutableList<org.apache.calcite.rel.hint.RelHint> |
getHints() |
List<org.apache.calcite.rex.RexNode> |
getSortExps()
Returns the sort expressions.
|
boolean |
isEnforcer() |
childrenAccept, deriveRowType, estimateRowCount, getInput, getInputs, replaceInput
accept, 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, toString
public final org.apache.calcite.rel.RelCollation collation
public final @Nullable org.apache.calcite.rex.RexNode offset
public final @Nullable org.apache.calcite.rex.RexNode fetch
protected final com.google.common.collect.ImmutableList<org.apache.calcite.rel.hint.RelHint> hints
protected Sort(org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.plan.RelTraitSet traits, org.apache.calcite.rel.RelNode child, org.apache.calcite.rel.RelCollation collation)
cluster
- Cluster this relational expression belongs totraits
- Traitschild
- input relational expressioncollation
- array of sort specificationspublic Sort(org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.plan.RelTraitSet traits, org.apache.calcite.rel.RelNode child, org.apache.calcite.rel.RelCollation collation, org.apache.calcite.rex.RexNode offset, org.apache.calcite.rex.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(org.apache.calcite.plan.RelOptCluster cluster, org.apache.calcite.plan.RelTraitSet traits, List<org.apache.calcite.rel.hint.RelHint> hints, org.apache.calcite.rel.RelNode child, org.apache.calcite.rel.RelCollation collation, @Nullable org.apache.calcite.rex.RexNode offset, @Nullable org.apache.calcite.rex.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(org.apache.calcite.rel.RelInput input)
public final Sort copy(org.apache.calcite.plan.RelTraitSet traitSet, List<org.apache.calcite.rel.RelNode> inputs)
copy
in interface org.apache.calcite.rel.RelNode
copy
in class org.apache.calcite.rel.AbstractRelNode
public final Sort copy(org.apache.calcite.plan.RelTraitSet traitSet, org.apache.calcite.rel.RelNode newInput, org.apache.calcite.rel.RelCollation newCollation)
public abstract Sort copy(org.apache.calcite.plan.RelTraitSet traitSet, org.apache.calcite.rel.RelNode newInput, org.apache.calcite.rel.RelCollation newCollation, @Nullable org.apache.calcite.rex.RexNode offset, @Nullable org.apache.calcite.rex.RexNode fetch)
public @Nullable org.apache.calcite.plan.RelOptCost computeSelfCost(org.apache.calcite.plan.RelOptPlanner planner, org.apache.calcite.rel.metadata.RelMetadataQuery mq)
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 org.apache.calcite.rel.RelNode
computeSelfCost
in class org.apache.calcite.rel.AbstractRelNode
public org.apache.calcite.rel.RelNode accept(org.apache.calcite.rex.RexShuttle shuttle)
accept
in interface org.apache.calcite.rel.RelNode
accept
in class org.apache.calcite.rel.AbstractRelNode
public boolean isEnforcer()
isEnforcer
in interface org.apache.calcite.rel.RelNode
isEnforcer
in class org.apache.calcite.rel.AbstractRelNode
public org.apache.calcite.rel.RelCollation getCollation()
RelFieldCollation
s 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 List<org.apache.calcite.rex.RexNode> getSortExps()
public org.apache.calcite.rel.RelWriter explainTerms(org.apache.calcite.rel.RelWriter pw)
explainTerms
in class org.apache.calcite.rel.SingleRel
public com.google.common.collect.ImmutableList<org.apache.calcite.rel.hint.RelHint> getHints()
getHints
in interface org.apache.calcite.rel.hint.Hintable
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.