cockroach: github.com/cockroachdb/cockroach/pkg/sql/opt/norm Index | Files

package norm

import "github.com/cockroachdb/cockroach/pkg/sql/opt/norm"

Index

Package Files

custom_funcs.go decorrelate.go factory.go fold_constants.go groupby.go inline.go join.go list_sorter.go ordering.go project_builder.go prune_cols.go reject_nulls.go

Variables

var FoldFunctionWhitelist = map[string]struct{}{ /* 130 elements not displayed */

}

FoldFunctionWhitelist contains functions that are known to always produce the same result given the same set of arguments. This excludes impure functions and functions that rely on context such as locale or current user. See sql/sem/builtins/builtins.go for the function definitions. TODO(rytaft): This is a stopgap until #26582 is completed to identify functions as immutable, stable or volatile.

func DerivePruneCols Uses

func DerivePruneCols(e memo.RelExpr) opt.ColSet

DerivePruneCols returns the subset of the given expression's output columns that are candidates for pruning. Each operator has its own custom rule for what columns it allows to be pruned. Note that if an operator allows columns to be pruned, then there must be logic in the PruneCols method to actually prune those columns when requested.

func DeriveRejectNullCols Uses

func DeriveRejectNullCols(in memo.RelExpr) opt.ColSet

DeriveRejectNullCols returns the set of columns that are candidates for NULL rejection filter pushdown. See the Relational.Rule.RejectNullCols comment for more details.

type AppliedRuleFunc Uses

type AppliedRuleFunc func(ruleName opt.RuleName, source, target opt.Expr)

AppliedRuleFunc defines the callback function for the NotifyOnAppliedRule event supported by the optimizer and factory. It is invoked each time an optimization rule (Normalize or Explore) has been applied.

The function is called with the name of the rule and the expressions it affected. For a normalization rule, the source is always nil, and the target is the expression constructed by the replace pattern. For an exploration rule, the source is the expression matched by the rule, and the target is the first expression constructed by the replace pattern. If no expressions were constructed, it is nil. Additional expressions beyond the first can be accessed by following the NextExpr links on the target expression.

type CustomFuncs Uses

type CustomFuncs struct {
    // contains filtered or unexported fields
}

CustomFuncs contains all the custom match and replace functions used by the normalization rules. These are also imported and used by the explorer.

func (*CustomFuncs) AddColsToGrouping Uses

func (c *CustomFuncs) AddColsToGrouping(
    private *memo.GroupingPrivate, groupingCols opt.ColSet,
) *memo.GroupingPrivate

AddColsToGrouping returns a new GroupByDef that is a copy of the given GroupingPrivate, except with the given set of grouping columns union'ed with the existing grouping columns.

func (*CustomFuncs) AddColsToPartition Uses

func (c *CustomFuncs) AddColsToPartition(
    priv *memo.WindowPrivate, cols opt.ColSet,
) *memo.WindowPrivate

AddColsToPartition unions the given set of columns with a window private's partition columns.

func (*CustomFuncs) AddConstInts Uses

func (c *CustomFuncs) AddConstInts(first tree.Datum, second tree.Datum) tree.Datum

AddConstInts adds the numeric constants together. AddConstInts assumes the sum will not overflow. Call CanAddConstInts on the constants to guarantee this.

func (*CustomFuncs) AggregationOuterCols Uses

func (c *CustomFuncs) AggregationOuterCols(aggregations memo.AggregationsExpr) opt.ColSet

AggregationOuterCols returns the union of all outer columns from the given aggregation expressions.

func (*CustomFuncs) AggsCanBeDecorrelated Uses

func (c *CustomFuncs) AggsCanBeDecorrelated(aggs memo.AggregationsExpr) bool

AggsCanBeDecorrelated returns true if every aggregate satisfies one of the following conditions:

* It is CountRows (because it will be translated into Count),
* It ignores nulls (because nothing extra must be done for it)
* It gives NULL on no input (because this is how we translate non-null
  ignoring aggregates)

TODO(justin): we can lift the third condition if we have a function that gives the correct "on empty" value for a given aggregate.

func (*CustomFuncs) AllArePrefixSafe Uses

func (c *CustomFuncs) AllArePrefixSafe(fns memo.WindowsExpr) bool

AllArePrefixSafe returns whether every window function in the list satisfies the "prefix-safe" property.

Being prefix-safe means that the computation of a window function on a given row does not depend on any of the rows that come after it. It's also precisely the property that lets us push limit operators below window functions:

(Limit (Window $input) n) = (Window (Limit $input n))

Note that the frame affects whether a given window function is prefix-safe or not. rank() is prefix-safe under any frame, but avg():

* is not prefix-safe under RANGE BETWEEN UNBOUNDED PRECEDING TO CURRENT ROW
  (the default), because we might cut off mid-peer group. If we can
  guarantee that the ordering is over a key, then this becomes safe.
* is not prefix-safe under ROWS BETWEEN UNBOUNDED PRECEDING TO UNBOUNDED
  FOLLOWING, because it needs to look at the entire partition.
* is prefix-safe under ROWS BETWEEN UNBOUNDED PRECEDING TO CURRENT ROW,
  because it only needs to look at the rows up to any given row.

(We don't currently handle this case).

This function is best-effort. It's OK to report a function not as prefix-safe, even if it is.

func (*CustomFuncs) AllowNullArgs Uses

func (c *CustomFuncs) AllowNullArgs(op opt.Operator, left, right opt.ScalarExpr) bool

AllowNullArgs returns true if the binary operator with the given inputs allows one of those inputs to be null. If not, then the binary operator will simply be replaced by null.

func (*CustomFuncs) AnyType Uses

func (c *CustomFuncs) AnyType() *types.T

AnyType returns the wildcard Any type.

func (*CustomFuncs) AppendAggCols Uses

func (c *CustomFuncs) AppendAggCols(
    aggs memo.AggregationsExpr, aggOp opt.Operator, cols opt.ColSet,
) memo.AggregationsExpr

AppendAggCols constructs a new Aggregations operator containing the aggregate functions from an existing Aggregations operator plus an additional set of aggregate functions, one for each column in the given set. The new functions are of the given aggregate operator type.

func (*CustomFuncs) AppendAggCols2 Uses

func (c *CustomFuncs) AppendAggCols2(
    aggs memo.AggregationsExpr,
    aggOp opt.Operator,
    cols opt.ColSet,
    aggOp2 opt.Operator,
    cols2 opt.ColSet,
) memo.AggregationsExpr

AppendAggCols2 constructs a new Aggregations operator containing the aggregate functions from an existing Aggregations operator plus an additional set of aggregate functions, one for each column in the given set. The new functions are of the given aggregate operator type.

func (*CustomFuncs) AppendReducedGroupingCols Uses

func (c *CustomFuncs) AppendReducedGroupingCols(
    input memo.RelExpr, aggs memo.AggregationsExpr, private *memo.GroupingPrivate,
) memo.AggregationsExpr

AppendReducedGroupingCols will take columns discarded by ReduceGroupingCols and append them to the end of the given aggregate function list, wrapped in ConstAgg aggregate functions. AppendReducedGroupingCols returns a new Aggregations operator containing the combined set of existing aggregate functions and the new ConstAgg aggregate functions.

func (*CustomFuncs) AreFiltersSorted Uses

func (c *CustomFuncs) AreFiltersSorted(f memo.FiltersExpr) bool

AreFiltersSorted determines whether the expressions in a FiltersExpr are ordered by their expression IDs.

func (*CustomFuncs) AreProjectionsCorrelated Uses

func (c *CustomFuncs) AreProjectionsCorrelated(
    projections memo.ProjectionsExpr, cols opt.ColSet,
) bool

AreProjectionsCorrelated returns true if any element in the projections references any of the given columns.

func (*CustomFuncs) ArrayType Uses

func (c *CustomFuncs) ArrayType(inCol opt.ColumnID) *types.T

ArrayType returns the type of the given column wrapped in an array.

func (*CustomFuncs) BinaryType Uses

func (c *CustomFuncs) BinaryType(op opt.Operator, left, right opt.ScalarExpr) *types.T

BinaryType returns the type of the binary overload for the given operator and operands.

func (*CustomFuncs) BoolType Uses

func (c *CustomFuncs) BoolType() *types.T

BoolType returns the boolean SQL type.

func (*CustomFuncs) CanAddConstInts Uses

func (c *CustomFuncs) CanAddConstInts(first tree.Datum, second tree.Datum) bool

CanAddConstInts returns true if the addition of the two integers overflows.

func (*CustomFuncs) CanConsolidateFilters Uses

func (c *CustomFuncs) CanConsolidateFilters(filters memo.FiltersExpr) bool

CanConsolidateFilters returns true if there are at least two different filter conditions that contain the same variable, where the conditions have tight constraints and contain a single variable. For example, CanConsolidateFilters returns true with filters {x > 5, x < 10}, but false with {x > 5, y < 10} and {x > 5, x = y}.

func (*CustomFuncs) CanConstructBinary Uses

func (c *CustomFuncs) CanConstructBinary(op opt.Operator, left, right opt.ScalarExpr) bool

CanConstructBinary returns true if (op left right) has a valid binary op overload and is therefore legal to construct. For example, while (Minus <date> <int>) is valid, (Minus <int> <date>) is not.

func (*CustomFuncs) CanExtractJoinEquality Uses

func (c *CustomFuncs) CanExtractJoinEquality(
    a, b opt.ScalarExpr, leftCols, rightCols opt.ColSet,
) bool

CanExtractJoinEquality returns true if:

- one of a, b is bound by the left columns;
- the other is bound by the right columns;
- a and b are not "bare" variables;
- a and b contain no correlated subqueries;
- neither a or b are constants.

Such an equality can be converted to a column equality by pushing down expressions as projections.

func (*CustomFuncs) CanHaveZeroRows Uses

func (c *CustomFuncs) CanHaveZeroRows(input memo.RelExpr) bool

CanHaveZeroRows returns true if the input expression might return zero rows.

func (*CustomFuncs) CanInline Uses

func (c *CustomFuncs) CanInline(scalar opt.ScalarExpr) bool

CanInline returns true if the given expression consists only of "simple" operators like Variable, Const, Eq, and Plus. These operators are assumed to be relatively inexpensive to evaluate, and therefore potentially evaluating them multiple times is not a big concern.

func (*CustomFuncs) CanInlineConstVar Uses

func (c *CustomFuncs) CanInlineConstVar(f memo.FiltersExpr) bool

CanInlineConstVar returns true if there is an opportunity in the filters to inline a variable restricted to be a constant, as in:

SELECT * FROM foo WHERE a = 4 AND a IN (1, 2, 3, 4).

=>

SELECT * FROM foo WHERE a = 4 AND 4 IN (1, 2, 3, 4).

func (*CustomFuncs) CanInlineProjections Uses

func (c *CustomFuncs) CanInlineProjections(projections memo.ProjectionsExpr) bool

CanInlineProjections returns true if all projection expressions can be inlined. See CanInline for details.

func (*CustomFuncs) CanInlineWith Uses

func (c *CustomFuncs) CanInlineWith(binding, expr memo.RelExpr, private *memo.WithPrivate) bool

CanInlineWith returns whether or not it's valid to inline binding in expr. This is the case when: 1. binding has no side-effects (because once it's inlined, there's no

guarantee it will be executed fully), and

2. binding is referenced at most once in expr.

func (*CustomFuncs) CanMapJoinOpEqualities Uses

func (c *CustomFuncs) CanMapJoinOpEqualities(
    filters memo.FiltersExpr, leftCols, rightCols opt.ColSet,
) bool

CanMapJoinOpEqualities checks whether it is possible to map equality conditions in a join to use different variables so that the number of conditions crossing both sides of a join are minimized. See canMapJoinOpEquivalenceGroup for details.

func (*CustomFuncs) CanMapJoinOpFilter Uses

func (c *CustomFuncs) CanMapJoinOpFilter(
    filters memo.FiltersExpr, src *memo.FiltersItem, dst memo.RelExpr,
) bool

CanMapJoinOpFilter returns true if it is possible to map a boolean expression src, which is a conjunct in the given filters expression, to use the output columns of the relational expression dst.

In order for one column to map to another, the two columns must be equivalent. This happens when there is an equality predicate such as a.x=b.x in the ON or WHERE clause. Additionally, the two columns must be of the same type (see GetEquivColsWithEquivType for details). CanMapJoinOpFilter checks that for each column in src, there is at least one equivalent column in dst.

For example, consider this query:

SELECT * FROM a INNER JOIN b ON a.x=b.x AND a.x + b.y = 5

Since there is an equality predicate on a.x=b.x, it is possible to map a.x + b.y = 5 to b.x + b.y = 5, and that allows the filter to be pushed down to the right side of the join. In this case, CanMapJoinOpFilter returns true when src is a.x + b.y = 5 and dst is (Scan b), but false when src is a.x + b.y = 5 and dst is (Scan a).

If src has a correlated subquery, CanMapJoinOpFilter returns false.

func (*CustomFuncs) CanMapOnSetOp Uses

func (c *CustomFuncs) CanMapOnSetOp(src *memo.FiltersItem) bool

CanMapOnSetOp determines whether the filter can be mapped to either side of a set operator.

func (*CustomFuncs) CanMergeProjections Uses

func (c *CustomFuncs) CanMergeProjections(outer, inner memo.ProjectionsExpr) bool

CanMergeProjections returns true if the outer Projections operator never references any of the inner Projections columns. If true, then the outer does not depend on the inner, and the two can be merged into a single set.

func (*CustomFuncs) CanPruneAggCols Uses

func (c *CustomFuncs) CanPruneAggCols(target memo.AggregationsExpr, neededCols opt.ColSet) bool

CanPruneAggCols returns true if one or more of the target aggregations is not referenced and can be eliminated.

func (*CustomFuncs) CanPruneCols Uses

func (c *CustomFuncs) CanPruneCols(target memo.RelExpr, neededCols opt.ColSet) bool

CanPruneCols returns true if the target expression has extra columns that are not needed at this level of the tree, and can be eliminated by one of the PruneCols rules. CanPruneCols uses the PruneCols property to determine the set of columns which can be pruned, and subtracts the given set of additional needed columns from that. See the props.Relational.Rule.PruneCols comment for more details.

func (*CustomFuncs) CanPruneMutationFetchCols Uses

func (c *CustomFuncs) CanPruneMutationFetchCols(
    private *memo.MutationPrivate, neededCols opt.ColSet,
) bool

CanPruneMutationFetchCols returns true if there are any FetchCols that are not in the set of needed columns. Those extra FetchCols can be pruned.

func (*CustomFuncs) CanPruneMutationReturnCols Uses

func (c *CustomFuncs) CanPruneMutationReturnCols(
    private *memo.MutationPrivate, needed opt.ColSet,
) bool

CanPruneMutationReturnCols checks whether the mutation's return columns can be pruned. This is the pre-condition for the PruneMutationReturnCols rule.

func (*CustomFuncs) CanPruneWindows Uses

func (c *CustomFuncs) CanPruneWindows(needed opt.ColSet, windows memo.WindowsExpr) bool

CanPruneWindows is true if the list of window functions contains a column which is not included in needed, meaning that it can be pruned.

func (*CustomFuncs) CanReduceGroupingCols Uses

func (c *CustomFuncs) CanReduceGroupingCols(
    input memo.RelExpr, private *memo.GroupingPrivate,
) bool

CanReduceGroupingCols is true if the given GroupBy operator has one or more redundant grouping columns. A grouping column is redundant if it is functionally determined by the other grouping columns.

func (*CustomFuncs) CanReduceWindowPartitionCols Uses

func (c *CustomFuncs) CanReduceWindowPartitionCols(
    input memo.RelExpr, private *memo.WindowPrivate,
) bool

CanReduceWindowPartitionCols is true if the set of columns being partitioned on can be made smaller via use of functional dependencies (for instance, partitioning on (k, k+1) can be reduced to just (k)).

func (*CustomFuncs) CanRemoveAggDistinctForKeys Uses

func (c *CustomFuncs) CanRemoveAggDistinctForKeys(
    aggs memo.AggregationsExpr, private *memo.GroupingPrivate, input memo.RelExpr,
) bool

CanRemoveAggDistinctForKeys returns true if the given aggregations contain an aggregation with AggDistinct where the input column together with the grouping columns form a key. In this case, the respective AggDistinct can be removed.

func (*CustomFuncs) CanSimplifyExplainOrdering Uses

func (c *CustomFuncs) CanSimplifyExplainOrdering(
    in memo.RelExpr, private *memo.ExplainPrivate,
) bool

CanSimplifyExplainOrdering returns true if the ordering required by the Explain operator can be made less restrictive, so that the input operator has more ordering choices.

func (*CustomFuncs) CanSimplifyGroupingOrdering Uses

func (c *CustomFuncs) CanSimplifyGroupingOrdering(
    in memo.RelExpr, private *memo.GroupingPrivate,
) bool

CanSimplifyGroupingOrdering returns true if the ordering required by the grouping operator can be made less restrictive, so that the input operator has more ordering choices.

func (*CustomFuncs) CanSimplifyLimitOffsetOrdering Uses

func (c *CustomFuncs) CanSimplifyLimitOffsetOrdering(
    in memo.RelExpr, ordering physical.OrderingChoice,
) bool

CanSimplifyLimitOffsetOrdering returns true if the ordering required by the Limit or Offset operator can be made less restrictive, so that the input operator has more ordering choices.

func (*CustomFuncs) CanSimplifyOrdinalityOrdering Uses

func (c *CustomFuncs) CanSimplifyOrdinalityOrdering(
    in memo.RelExpr, private *memo.OrdinalityPrivate,
) bool

CanSimplifyOrdinalityOrdering returns true if the ordering required by the Ordinality operator can be made less restrictive, so that the input operator has more ordering choices.

func (*CustomFuncs) CanSimplifyWindowOrdering Uses

func (c *CustomFuncs) CanSimplifyWindowOrdering(in memo.RelExpr, private *memo.WindowPrivate) bool

CanSimplifyWindowOrdering is true if the intra-partition ordering used by the window function can be made less restrictive.

func (*CustomFuncs) CanaryColSet Uses

func (c *CustomFuncs) CanaryColSet(canaryCol opt.ColumnID) opt.ColSet

CanaryColSet returns a singleton set containing the canary column if set, otherwise the empty set.

func (*CustomFuncs) CandidateKey Uses

func (c *CustomFuncs) CandidateKey(input memo.RelExpr) (key opt.ColSet, ok bool)

CandidateKey returns the candidate key columns from the given input expression. If there is no candidate key, CandidateKey returns ok=false.

func (*CustomFuncs) CastToCollatedString Uses

func (c *CustomFuncs) CastToCollatedString(str opt.ScalarExpr, locale string) opt.ScalarExpr

CastToCollatedString returns the given string or collated string as a collated string constant with the given locale.

func (*CustomFuncs) ColsAreEmpty Uses

func (c *CustomFuncs) ColsAreEmpty(cols opt.ColSet) bool

ColsAreEmpty returns true if the column set is empty.

func (*CustomFuncs) ColsAreEqual Uses

func (c *CustomFuncs) ColsAreEqual(left, right opt.ColSet) bool

ColsAreEqual returns true if left and right contain the same set of columns.

func (*CustomFuncs) ColsAreSubset Uses

func (c *CustomFuncs) ColsAreSubset(left, right opt.ColSet) bool

ColsAreSubset returns true if the left columns are a subset of the right columns.

func (*CustomFuncs) ColsIntersect Uses

func (c *CustomFuncs) ColsIntersect(left, right opt.ColSet) bool

ColsIntersect returns true if at least one column appears in both the left and right sets.

func (*CustomFuncs) CommuteInequality Uses

func (c *CustomFuncs) CommuteInequality(
    op opt.Operator, left, right opt.ScalarExpr,
) opt.ScalarExpr

CommuteInequality swaps the operands of an inequality comparison expression, changing the operator to compensate:

5 < x

to:

x > 5

func (*CustomFuncs) ConcatFilters Uses

func (c *CustomFuncs) ConcatFilters(left, right memo.FiltersExpr) memo.FiltersExpr

ConcatFilters creates a new Filters operator that contains conditions from both the left and right boolean filter expressions.

func (*CustomFuncs) ConcatLeftDeepAnds Uses

func (c *CustomFuncs) ConcatLeftDeepAnds(left, right opt.ScalarExpr) opt.ScalarExpr

ConcatLeftDeepAnds concatenates any left-deep And expressions in the right expression with any left-deep And expressions in the left expression. The result is a combined left-deep And expression. Note that NormalizeNestedAnds has already guaranteed that both inputs will already be left-deep.

func (*CustomFuncs) ConsolidateFilters Uses

func (c *CustomFuncs) ConsolidateFilters(filters memo.FiltersExpr) memo.FiltersExpr

ConsolidateFilters consolidates filter conditions that contain the same variable, where the conditions have tight constraints and contain a single variable. The consolidated filters are combined with a tree of nested And operations, and wrapped with a Range expression.

See the ConsolidateSelectFilters rule for more details about why this is necessary.

func (*CustomFuncs) ConstructAnyCondition Uses

func (c *CustomFuncs) ConstructAnyCondition(
    input memo.RelExpr, scalar opt.ScalarExpr, private *memo.SubqueryPrivate,
) opt.ScalarExpr

ConstructAnyCondition builds an expression that compares the given scalar expression with the first (and only) column of the input rowset, using the given comparison operator.

func (*CustomFuncs) ConstructApplyJoin Uses

func (c *CustomFuncs) ConstructApplyJoin(
    joinOp opt.Operator, left, right memo.RelExpr, on memo.FiltersExpr, private *memo.JoinPrivate,
) memo.RelExpr

ConstructApplyJoin constructs the apply join operator that corresponds to the given join operator type.

func (*CustomFuncs) ConstructBinary Uses

func (c *CustomFuncs) ConstructBinary(op opt.Operator, left, right opt.ScalarExpr) opt.ScalarExpr

ConstructBinary builds a dynamic binary expression, given the binary operator's type and its two arguments.

func (*CustomFuncs) ConstructEmptyValues Uses

func (c *CustomFuncs) ConstructEmptyValues(cols opt.ColSet) memo.RelExpr

ConstructEmptyValues constructs a Values expression with no rows.

func (*CustomFuncs) ConstructNoColsRow Uses

func (c *CustomFuncs) ConstructNoColsRow() memo.RelExpr

ConstructNoColsRow returns a Values operator having a single row with zero columns.

func (*CustomFuncs) ConstructNonApplyJoin Uses

func (c *CustomFuncs) ConstructNonApplyJoin(
    joinOp opt.Operator, left, right memo.RelExpr, on memo.FiltersExpr, private *memo.JoinPrivate,
) memo.RelExpr

ConstructNonApplyJoin constructs the non-apply join operator that corresponds to the given join operator type.

func (*CustomFuncs) ConstructNonLeftJoin Uses

func (c *CustomFuncs) ConstructNonLeftJoin(
    joinOp opt.Operator, left, right memo.RelExpr, on memo.FiltersExpr, private *memo.JoinPrivate,
) memo.RelExpr

ConstructNonLeftJoin maps a left join to an inner join and a full join to a right join when it can be proved that the right side of the join always produces at least one row for every row on the left.

func (*CustomFuncs) ConstructNonRightJoin Uses

func (c *CustomFuncs) ConstructNonRightJoin(
    joinOp opt.Operator, left, right memo.RelExpr, on memo.FiltersExpr, private *memo.JoinPrivate,
) memo.RelExpr

ConstructNonRightJoin maps a right join to an inner join and a full join to a left join when it can be proved that the left side of the join always produces at least one row for every row on the right.

func (*CustomFuncs) ConstructProjectionFromDistinctOn Uses

func (c *CustomFuncs) ConstructProjectionFromDistinctOn(
    input memo.RelExpr, aggs memo.AggregationsExpr,
) memo.RelExpr

ConstructProjectionFromDistinctOn converts a DistinctOn to a projection; this is correct when the input has at most one row. Note that DistinctOn can only have aggregations of type FirstAgg or ConstAgg.

func (*CustomFuncs) ConstructSortedUniqueList Uses

func (c *CustomFuncs) ConstructSortedUniqueList(
    list memo.ScalarListExpr,
) (memo.ScalarListExpr, *types.T)

ConstructSortedUniqueList sorts the given list and removes duplicates, and returns the resulting list. See the comment for listSorter.compare for comparison rule details.

func (*CustomFuncs) ConvertConstArrayToTuple Uses

func (c *CustomFuncs) ConvertConstArrayToTuple(scalar opt.ScalarExpr) opt.ScalarExpr

ConvertConstArrayToTuple converts a constant ARRAY datum to the equivalent homogeneous tuple, so ARRAY[1, 2, 3] becomes (1, 2, 3).

func (*CustomFuncs) DerefOrderingChoice Uses

func (c *CustomFuncs) DerefOrderingChoice(result *physical.OrderingChoice) physical.OrderingChoice

DerefOrderingChoice returns an OrderingChoice from a pointer.

func (*CustomFuncs) DifferenceCols Uses

func (c *CustomFuncs) DifferenceCols(left, right opt.ColSet) opt.ColSet

DifferenceCols returns the difference of the left and right column sets.

func (*CustomFuncs) EmptyJoinPrivate Uses

func (c *CustomFuncs) EmptyJoinPrivate() *memo.JoinPrivate

EmptyJoinPrivate returns an unset JoinPrivate.

func (*CustomFuncs) EmptyOrdering Uses

func (c *CustomFuncs) EmptyOrdering() physical.OrderingChoice

EmptyOrdering returns a pseudo-choice that does not require any ordering.

func (*CustomFuncs) EnsureAggsCanIgnoreNulls Uses

func (c *CustomFuncs) EnsureAggsCanIgnoreNulls(
    in memo.RelExpr, aggs memo.AggregationsExpr,
) memo.AggregationsExpr

EnsureAggsCanIgnoreNulls scans the aggregate list to aggregation functions that don't ignore nulls but can be remapped so that they do:

- CountRows functions are are converted to Count functions that operate
  over a not-null column from the given input expression. The
  EnsureNotNullIfNeeded method should already have been called in order
  to guarantee such a column exists.
- ConstAgg is remapped to ConstNotNullAgg.
- Other aggregates that can use a canary column to detect nulls.

See the TryDecorrelateScalarGroupBy rule comment for more details.

func (*CustomFuncs) EnsureCanary Uses

func (c *CustomFuncs) EnsureCanary(in memo.RelExpr, canaryCol opt.ColumnID) memo.RelExpr

EnsureCanary makes sure that if canaryCol is set, it is projected by the input expression.

See the TryDecorrelateScalarGroupBy rule comment for more details.

func (*CustomFuncs) EnsureCanaryCol Uses

func (c *CustomFuncs) EnsureCanaryCol(in memo.RelExpr, aggs memo.AggregationsExpr) opt.ColumnID

EnsureCanaryCol checks whether an aggregation which cannot ignore nulls exists. If one does, it then checks if there are any non-null columns in the input. If there is not one, it synthesizes a new True constant column that is not-null. This becomes a kind of "canary" column that other expressions can inspect, since any null value in this column indicates that the row was added by an outer join as part of null extending.

EnsureCanaryCol returns the input expression, possibly wrapped in a new Project if a new column was synthesized.

See the TryDecorrelateScalarGroupBy rule comment for more details.

func (*CustomFuncs) EnsureKey Uses

func (c *CustomFuncs) EnsureKey(in memo.RelExpr) memo.RelExpr

EnsureKey finds the shortest strong key for the input expression. If no strong key exists, then EnsureKey wraps the input in a Ordinality operator, which provides a key column by uniquely numbering the rows. EnsureKey returns the input expression (perhaps wrapped by Ordinality).

func (*CustomFuncs) EqualsNumber Uses

func (c *CustomFuncs) EqualsNumber(datum tree.Datum, value int64) bool

EqualsNumber returns true if the given numeric value (decimal, float, or integer) is equal to the given integer value.

func (*CustomFuncs) ExtractBoundConditions Uses

func (c *CustomFuncs) ExtractBoundConditions(
    filters memo.FiltersExpr, cols opt.ColSet,
) memo.FiltersExpr

ExtractBoundConditions returns a new list containing only those expressions from the given list that are fully bound by the given columns (i.e. all outer references are to one of these columns). For example:

(InnerJoin
  (Scan a)
  (Scan b)
  (Filters [
    (Eq (Variable a.x) (Variable b.x))
    (Gt (Variable a.x) (Const 1))
  ])
)

Calling ExtractBoundConditions with the filter conditions list and the output columns of (Scan a) would extract the (Gt) expression, since its outer references only reference columns from a.

func (*CustomFuncs) ExtractDeterminedConditions Uses

func (c *CustomFuncs) ExtractDeterminedConditions(
    filters memo.FiltersExpr, cols opt.ColSet, input memo.RelExpr,
) memo.FiltersExpr

ExtractDeterminedConditions returns a new list of filters containing only those expressions from the given list which are bound by columns which are functionally determined by the given columns.

func (*CustomFuncs) ExtractGroupingOrdering Uses

func (c *CustomFuncs) ExtractGroupingOrdering(
    private *memo.GroupingPrivate,
) physical.OrderingChoice

ExtractGroupingOrdering returns the ordering associated with the input GroupingPrivate.

func (*CustomFuncs) ExtractJoinEquality Uses

func (c *CustomFuncs) ExtractJoinEquality(
    joinOp opt.Operator,
    left, right memo.RelExpr,
    filters memo.FiltersExpr,
    item *memo.FiltersItem,
    private *memo.JoinPrivate,
) memo.RelExpr

ExtractJoinEquality takes an equality FiltersItem that was identified via a call to CanExtractJoinEquality, and converts it to an equality on "bare" variables, by pushing down more complicated expressions as projections. See the ExtractJoinEqualities rule.

func (*CustomFuncs) ExtractRedundantConjunct Uses

func (c *CustomFuncs) ExtractRedundantConjunct(
    conjunct, left, right opt.ScalarExpr,
) opt.ScalarExpr

ExtractRedundantConjunct extracts a redundant conjunct from an Or expression, and returns an And of the conjunct with the remaining Or expression (a logically equivalent expression). For example:

(A AND B) OR (A AND C)  =>  A AND (B OR C)

If extracting the conjunct from one of the OR conditions would result in an empty condition, the conjunct itself is returned (a logically equivalent expression). For example:

A OR (A AND B)  =>  A

These transformations are useful for finding a conjunct that can be pushed down in the query tree. For example, if the redundant conjunct A is fully bound by one side of a join, it can be pushed through the join, even if B and C cannot.

func (*CustomFuncs) ExtractUnboundConditions Uses

func (c *CustomFuncs) ExtractUnboundConditions(
    filters memo.FiltersExpr, cols opt.ColSet,
) memo.FiltersExpr

ExtractUnboundConditions is the opposite of ExtractBoundConditions. Instead of extracting expressions that are bound by the given columns, it extracts list expressions that have at least one outer reference that is *not* bound by the given columns (i.e. it has a "free" variable).

func (*CustomFuncs) ExtractUndeterminedConditions Uses

func (c *CustomFuncs) ExtractUndeterminedConditions(
    filters memo.FiltersExpr, cols opt.ColSet, input memo.RelExpr,
) memo.FiltersExpr

ExtractUndeterminedConditions is the opposite of ExtractDeterminedConditions.

func (*CustomFuncs) FilterHasCorrelatedSubquery Uses

func (c *CustomFuncs) FilterHasCorrelatedSubquery(filters memo.FiltersExpr) bool

FilterHasCorrelatedSubquery returns true if any of the filter conditions contain a correlated subquery.

func (*CustomFuncs) FilterOuterCols Uses

func (c *CustomFuncs) FilterOuterCols(filters memo.FiltersExpr) opt.ColSet

FilterOuterCols returns the union of all outer columns from the given filter conditions.

func (*CustomFuncs) FiltersBoundBy Uses

func (c *CustomFuncs) FiltersBoundBy(filters memo.FiltersExpr, cols opt.ColSet) bool

FiltersBoundBy returns true if all outer references in any of the filter conditions are bound by the given columns. For example:

(InnerJoin
  (Scan a)
  (Scan b)
  $filters:[ (FiltersItem (Eq (Variable a.x) (Const 1))) ]
)

The $filters expression is fully bound by the output columns of the (Scan a) expression because all of its outer references are satisfied by the columns produced by the Scan.

func (*CustomFuncs) FindInlinableConstants Uses

func (c *CustomFuncs) FindInlinableConstants(input memo.RelExpr) opt.ColSet

FindInlinableConstants returns the set of input columns that are synthesized constant value expressions: ConstOp, TrueOp, FalseOp, or NullOp. Constant value expressions can often be inlined into referencing expressions. Only Project and Values operators synthesize constant value expressions.

func (*CustomFuncs) FindRedundantConjunct Uses

func (c *CustomFuncs) FindRedundantConjunct(left, right opt.ScalarExpr) opt.ScalarExpr

FindRedundantConjunct takes the left and right operands of an Or operator as input. It examines each conjunct from the left expression and determines whether it appears as a conjunct in the right expression. If so, it returns the matching conjunct. Otherwise, it returns nil. For example:

A OR A                               =>  A
B OR A                               =>  nil
A OR (A AND B)                       =>  A
(A AND B) OR (A AND C)               =>  A
(A AND B AND C) OR (A AND (D OR E))  =>  A

Once a redundant conjunct has been found, it is extracted via a call to the ExtractRedundantConjunct function. Redundant conjuncts are extracted from multiple nested Or operators by repeated application of these functions.

func (*CustomFuncs) FoldArray Uses

func (c *CustomFuncs) FoldArray(elems memo.ScalarListExpr, typ *types.T) opt.ScalarExpr

FoldArray evaluates an Array expression with constant inputs. It returns the array as a Const datum with type TArray.

func (*CustomFuncs) FoldBinary Uses

func (c *CustomFuncs) FoldBinary(op opt.Operator, left, right opt.ScalarExpr) opt.ScalarExpr

FoldBinary evaluates a binary expression with constant inputs. It returns a constant expression as long as it finds an appropriate overload function for the given operator and input types, and the evaluation causes no error.

func (*CustomFuncs) FoldCast Uses

func (c *CustomFuncs) FoldCast(input opt.ScalarExpr, typ *types.T) opt.ScalarExpr

FoldCast evaluates a cast expression with a constant input. It returns a constant expression as long as the evaluation causes no error.

func (*CustomFuncs) FoldColumnAccess Uses

func (c *CustomFuncs) FoldColumnAccess(input opt.ScalarExpr, idx memo.TupleOrdinal) opt.ScalarExpr

FoldColumnAccess tries to evaluate a tuple column access operator with a constant tuple input (though tuple field values do not need to be constant). It returns the referenced tuple field value, or nil if folding is not possible or results in an error.

func (*CustomFuncs) FoldComparison Uses

func (c *CustomFuncs) FoldComparison(op opt.Operator, left, right opt.ScalarExpr) opt.ScalarExpr

FoldComparison evaluates a comparison expression with constant inputs. It returns a constant expression as long as it finds an appropriate overload function for the given operator and input types, and the evaluation causes no error.

func (*CustomFuncs) FoldFunction Uses

func (c *CustomFuncs) FoldFunction(
    args memo.ScalarListExpr, private *memo.FunctionPrivate,
) opt.ScalarExpr

FoldFunction evaluates a function expression with constant inputs. It returns a constant expression as long as the function is contained in the FoldFunctionWhitelist, and the evaluation causes no error.

func (*CustomFuncs) FoldIndirection Uses

func (c *CustomFuncs) FoldIndirection(input, index opt.ScalarExpr) opt.ScalarExpr

FoldIndirection evaluates an array indirection operator with constant inputs. It returns the referenced array element as a constant value, or nil if the evaluation results in an error.

func (*CustomFuncs) FoldNullBinary Uses

func (c *CustomFuncs) FoldNullBinary(op opt.Operator, left, right opt.ScalarExpr) opt.ScalarExpr

FoldNullBinary replaces the binary operator with a typed null value having the same type as the binary operator would have.

func (*CustomFuncs) FoldNullUnary Uses

func (c *CustomFuncs) FoldNullUnary(op opt.Operator, input opt.ScalarExpr) opt.ScalarExpr

FoldNullUnary replaces the unary operator with a typed null value having the same type as the unary operator would have.

func (*CustomFuncs) FoldUnary Uses

func (c *CustomFuncs) FoldUnary(op opt.Operator, input opt.ScalarExpr) opt.ScalarExpr

FoldUnary evaluates a unary expression with a constant input. It returns a constant expression as long as it finds an appropriate overload function for the given operator and input type, and the evaluation causes no error.

func (*CustomFuncs) GetEquivColsWithEquivType Uses

func (c *CustomFuncs) GetEquivColsWithEquivType(
    col opt.ColumnID, filters memo.FiltersExpr,
) opt.ColSet

GetEquivColsWithEquivType uses the given FuncDepSet to find columns that are equivalent to col, and returns only those columns that also have the same type as col. This function is used when inferring new filters based on equivalent columns, because operations that are valid with one type may be invalid with a different type.

In addition, if col has a composite key encoding, we cannot guarantee that it will be exactly equal to other "equivalent" columns, so in that case we return a set containing only col. This is a conservative measure to ensure that we don't infer filters incorrectly. For example, consider this query:

SELECT * FROM
  (VALUES (1.0)) AS t1(x),
  (VALUES (1.00)) AS t2(y)
WHERE x=y AND x::text = '1.0';

It should return the following result:

  x  |  y
-----+------
 1.0 | 1.00

But if we use the equality predicate x=y to map x to y and infer an additional filter y::text = '1.0', the query would return nothing.

TODO(rytaft): In the future, we may want to allow the mapping if the filter involves a comparison operator, such as x < 5.

func (*CustomFuncs) GroupingAndConstCols Uses

func (c *CustomFuncs) GroupingAndConstCols(
    grouping *memo.GroupingPrivate, aggs memo.AggregationsExpr,
) opt.ColSet

GroupingAndConstCols returns the grouping columns and ConstAgg columns (for which the input and output column IDs match). A filter on these columns can be pushed through a GroupBy.

func (*CustomFuncs) GroupingColsAreKey Uses

func (c *CustomFuncs) GroupingColsAreKey(grouping *memo.GroupingPrivate, input memo.RelExpr) bool

GroupingColsAreKey returns true if the input expression's grouping columns form a strict key for its output rows. A strict key means that any two rows will have unique key column values. Nulls are treated as equal to one another (i.e. no duplicate nulls allowed). Having a strict key means that the set of key column values uniquely determine the values of all other columns in the relation.

func (*CustomFuncs) GroupingInputOrdering Uses

func (c *CustomFuncs) GroupingInputOrdering(private *memo.GroupingPrivate) physical.OrderingChoice

GroupingInputOrdering returns the Ordering in the private.

func (*CustomFuncs) GroupingOutputCols Uses

func (c *CustomFuncs) GroupingOutputCols(
    grouping *memo.GroupingPrivate, aggs memo.AggregationsExpr,
) opt.ColSet

GroupingOutputCols returns the output columns of a GroupBy, ScalarGroupBy, or DistinctOn expression.

func (*CustomFuncs) HasColType Uses

func (c *CustomFuncs) HasColType(scalar opt.ScalarExpr, dstTyp *types.T) bool

HasColType returns true if the given scalar expression has a static type that's identical to the requested coltype.

func (*CustomFuncs) HasColsInOrdering Uses

func (c *CustomFuncs) HasColsInOrdering(input memo.RelExpr, ordering physical.OrderingChoice) bool

HasColsInOrdering returns true if all columns that appear in an ordering are output columns of the input expression.

func (*CustomFuncs) HasDuplicateRefs Uses

func (c *CustomFuncs) HasDuplicateRefs(
    projections memo.ProjectionsExpr, passthrough opt.ColSet, targetCols opt.ColSet,
) bool

HasDuplicateRefs returns true if the target projection expressions or passthrough columns reference any column in the given target set more than one time, or if the projection expressions contain a correlated subquery. For example:

SELECT x+1, x+2, y FROM a

HasDuplicateRefs would be true, since the x column is referenced twice.

Correlated subqueries are disallowed since it introduces additional complexity for a case that's not too important for inlining. Also, skipping correlated subqueries minimizes expensive searching in deep trees.

func (*CustomFuncs) HasHoistableSubquery Uses

func (c *CustomFuncs) HasHoistableSubquery(scalar opt.ScalarExpr) bool

HasHoistableSubquery returns true if the given scalar expression contains a subquery within its subtree that has at least one outer column, and if that subquery needs to be hoisted up into its parent query as part of query decorrelation.

func (*CustomFuncs) HasNoCols Uses

func (c *CustomFuncs) HasNoCols(input memo.RelExpr) bool

HasNoCols returns true if the input expression has zero output columns.

func (*CustomFuncs) HasNoGroupingCols Uses

func (c *CustomFuncs) HasNoGroupingCols(private *memo.GroupingPrivate) bool

HasNoGroupingCols returns true if the GroupingCols in the private are empty.

func (*CustomFuncs) HasNullRejectingFilter Uses

func (c *CustomFuncs) HasNullRejectingFilter(
    filters memo.FiltersExpr, nullRejectCols opt.ColSet,
) bool

HasNullRejectingFilter returns true if the filter causes some of the columns in nullRejectCols to be non-null. For example, if nullRejectCols = (x, z), filters such as x < 5, x = y, and z IS NOT NULL all satisfy this property.

func (*CustomFuncs) HasOneRow Uses

func (c *CustomFuncs) HasOneRow(input memo.RelExpr) bool

HasOneRow returns true if the input expression always returns exactly one row.

func (*CustomFuncs) HasOuterCols Uses

func (c *CustomFuncs) HasOuterCols(input opt.Expr) bool

HasOuterCols returns true if the input expression has at least one outer column, or in other words, a reference to a variable that is not bound within its own scope. For example:

SELECT * FROM a WHERE EXISTS(SELECT * FROM b WHERE b.x = a.x)

The a.x variable in the EXISTS subquery references a column outside the scope of the subquery. It is an "outer column" for the subquery (see the comment on RelationalProps.OuterCols for more details).

func (*CustomFuncs) HasZeroOrOneRow Uses

func (c *CustomFuncs) HasZeroOrOneRow(input memo.RelExpr) bool

HasZeroOrOneRow returns true if the input expression returns at most one row.

func (*CustomFuncs) HasZeroRows Uses

func (c *CustomFuncs) HasZeroRows(input memo.RelExpr) bool

HasZeroRows returns true if the input expression never returns any rows.

func (*CustomFuncs) HoistJoinSubquery Uses

func (c *CustomFuncs) HoistJoinSubquery(
    op opt.Operator, left, right memo.RelExpr, on memo.FiltersExpr, private *memo.JoinPrivate,
) memo.RelExpr

HoistJoinSubquery searches the Join operator's filter for correlated subqueries. Any found queries are hoisted into LeftJoinApply or InnerJoinApply operators, depending on subquery cardinality:

SELECT y, z
FROM xy
FULL JOIN yz
ON (SELECT u FROM uv WHERE u=x LIMIT 1) IS NULL
=>
SELECT y, z
FROM xy
FULL JOIN LATERAL
(
  SELECT *
  FROM yz
  LEFT JOIN LATERAL (SELECT u FROM uv WHERE u=x LIMIT 1)
  ON True
)
ON u IS NULL

func (*CustomFuncs) HoistProjectSetSubquery Uses

func (c *CustomFuncs) HoistProjectSetSubquery(input memo.RelExpr, zip memo.ZipExpr) memo.RelExpr

HoistProjectSetSubquery searches the ProjectSet operator's functions for correlated subqueries. Any found queries are hoisted into LeftJoinApply or InnerJoinApply operators, depending on subquery cardinality:

SELECT generate_series
FROM xy
INNER JOIN LATERAL ROWS FROM
(
  generate_series(1, (SELECT v FROM uv WHERE u=x))
)
=>
SELECT generate_series
FROM xy
ROWS FROM
(
  SELECT generate_series
  FROM (VALUES ())
  LEFT JOIN LATERAL (SELECT v FROM uv WHERE u=x)
  ON True
  INNER JOIN LATERAL ROWS FROM (generate_series(1, v))
  ON True
)

func (*CustomFuncs) HoistProjectSubquery Uses

func (c *CustomFuncs) HoistProjectSubquery(
    input memo.RelExpr, projections memo.ProjectionsExpr, passthrough opt.ColSet,
) memo.RelExpr

HoistProjectSubquery searches the Project operator's projections for correlated subqueries. Any found queries are hoisted into LeftJoinApply or InnerJoinApply operators, depending on subquery cardinality:

SELECT (SELECT max(u) FROM uv WHERE u=x) AS max FROM xy
=>
SELECT max
FROM xy
INNER JOIN LATERAL (SELECT max(u) FROM uv WHERE u=x)
ON True

func (*CustomFuncs) HoistSelectSubquery Uses

func (c *CustomFuncs) HoistSelectSubquery(
    input memo.RelExpr, filters memo.FiltersExpr,
) memo.RelExpr

HoistSelectSubquery searches the Select operator's filter for correlated subqueries. Any found queries are hoisted into LeftJoinApply or InnerJoinApply operators, depending on subquery cardinality:

SELECT * FROM xy WHERE (SELECT u FROM uv WHERE u=x LIMIT 1) IS NULL
=>
SELECT xy.*
FROM xy
LEFT JOIN LATERAL (SELECT u FROM uv WHERE u=x LIMIT 1)
ON True
WHERE u IS NULL

func (*CustomFuncs) HoistValuesSubquery Uses

func (c *CustomFuncs) HoistValuesSubquery(
    rows memo.ScalarListExpr, private *memo.ValuesPrivate,
) memo.RelExpr

HoistValuesSubquery searches the Values operator's projections for correlated subqueries. Any found queries are hoisted into LeftJoinApply or InnerJoinApply operators, depending on subquery cardinality:

SELECT (VALUES (SELECT u FROM uv WHERE u=x LIMIT 1)) FROM xy
=>
SELECT
(
  SELECT vals.*
  FROM (VALUES ())
  LEFT JOIN LATERAL (SELECT u FROM uv WHERE u=x LIMIT 1)
  ON True
  INNER JOIN LATERAL (VALUES (u)) vals
  ON True
)
FROM xy

The dummy VALUES clause with a singleton empty row is added to the tree in order to use the hoister, which requires an initial input query. While a right join would be slightly better here, this is such a fringe case that it's not worth the extra code complication.

func (*CustomFuncs) Init Uses

func (c *CustomFuncs) Init(f *Factory)

Init initializes a new CustomFuncs with the given factory.

func (*CustomFuncs) InlineConstVar Uses

func (c *CustomFuncs) InlineConstVar(f memo.FiltersExpr) memo.FiltersExpr

InlineConstVar performs the inlining detected by CanInlineConstVar.

func (*CustomFuncs) InlineFilterConstants Uses

func (c *CustomFuncs) InlineFilterConstants(
    filters memo.FiltersExpr, input memo.RelExpr, constCols opt.ColSet,
) memo.FiltersExpr

InlineFilterConstants recursively searches each filter expression and replaces any references to input columns that are constant. It returns a new Filters list containing the replaced expressions.

func (*CustomFuncs) InlineProjectProject Uses

func (c *CustomFuncs) InlineProjectProject(
    input memo.RelExpr, projections memo.ProjectionsExpr, passthrough opt.ColSet,
) memo.RelExpr

InlineProjectProject searches the projection expressions for any variable references to columns from the given input (which must be a Project operator). Each variable is replaced by the corresponding inlined projection expression.

func (*CustomFuncs) InlineProjectionConstants Uses

func (c *CustomFuncs) InlineProjectionConstants(
    projections memo.ProjectionsExpr, input memo.RelExpr, constCols opt.ColSet,
) memo.ProjectionsExpr

InlineProjectionConstants recursively searches each projection expression and replaces any references to input columns that are constant. It returns a new Projections list containing the replaced expressions.

func (*CustomFuncs) InlineSelectProject Uses

func (c *CustomFuncs) InlineSelectProject(
    filters memo.FiltersExpr, projections memo.ProjectionsExpr,
) memo.FiltersExpr

InlineSelectProject searches the filter conditions for any variable references to columns from the given projections expression. Each variable is replaced by the corresponding inlined projection expression.

func (*CustomFuncs) InlineWith Uses

func (c *CustomFuncs) InlineWith(binding, input memo.RelExpr, priv *memo.WithPrivate) memo.RelExpr

InlineWith replaces all references to the With expression in input (via WithScans) with its definition.

func (*CustomFuncs) IntersectionCols Uses

func (c *CustomFuncs) IntersectionCols(left, right opt.ColSet) opt.ColSet

IntersectionCols returns the intersection of the left and right column sets.

func (*CustomFuncs) IsAdditive Uses

func (c *CustomFuncs) IsAdditive(e opt.ScalarExpr) bool

IsAdditive returns true if the type of the expression supports addition and subtraction in the natural way. This differs from "has a +/- Numeric implementation" because JSON has an implementation for "- INT" which doesn't obey x - 0 = x. Additive types include all numeric types as well as timestamps and dates.

func (*CustomFuncs) IsBoundBy Uses

func (c *CustomFuncs) IsBoundBy(src opt.Expr, cols opt.ColSet) bool

IsBoundBy returns true if all outer references in the source expression are bound by the given columns. For example:

(InnerJoin
  (Scan a)
  (Scan b)
  [ ... $item:(FiltersItem (Eq (Variable a.x) (Const 1))) ... ]
)

The $item expression is fully bound by the output columns of the (Scan a) expression because all of its outer references are satisfied by the columns produced by the Scan.

func (*CustomFuncs) IsColNotNull Uses

func (c *CustomFuncs) IsColNotNull(col opt.ColumnID, input memo.RelExpr) bool

IsColNotNull returns true if the given input column is never null.

func (*CustomFuncs) IsColNotNull2 Uses

func (c *CustomFuncs) IsColNotNull2(col opt.ColumnID, left, right memo.RelExpr) bool

IsColNotNull2 returns true if the given column is part of the left or right expressions' set of not-null columns.

func (*CustomFuncs) IsConstArray Uses

func (c *CustomFuncs) IsConstArray(scalar opt.ScalarExpr) bool

IsConstArray returns true if the expression is a constant array.

func (*CustomFuncs) IsConstValueEqual Uses

func (c *CustomFuncs) IsConstValueEqual(const1, const2 opt.ScalarExpr) bool

IsConstValueEqual returns whether const1 and const2 are equal.

func (*CustomFuncs) IsConstValueOrTuple Uses

func (c *CustomFuncs) IsConstValueOrTuple(input opt.ScalarExpr) bool

IsConstValueOrTuple returns true if the input is a constant or a tuple of constants.

func (*CustomFuncs) IsContradiction Uses

func (c *CustomFuncs) IsContradiction(item *memo.FiltersItem) bool

IsContradiction returns true if the given filter item contains a contradiction constraint.

func (*CustomFuncs) IsCorrelated Uses

func (c *CustomFuncs) IsCorrelated(src, dst memo.RelExpr) bool

IsCorrelated returns true if any variable in the source expression references a column from the destination expression. For example:

(InnerJoin
  (Scan a)
  (Scan b)
  [ ... (FiltersItem $item:(Eq (Variable a.x) (Const 1))) ... ]
)

The $item expression is correlated with the (Scan a) expression because it references one of its columns. But the $item expression is not correlated with the (Scan b) expression.

func (*CustomFuncs) IsDeterminedBy Uses

func (c *CustomFuncs) IsDeterminedBy(src opt.Expr, cols opt.ColSet, input memo.RelExpr) bool

IsDeterminedBy returns true if all outer references in the source expression are bound by the closure of the given columns according to the functional dependencies of the input expression.

func (*CustomFuncs) IsFilterFalse Uses

func (c *CustomFuncs) IsFilterFalse(filters memo.FiltersExpr) bool

IsFilterFalse returns true if the filters always evaluate to false. The only case that's checked is the fully normalized case, when the list contains a single False condition.

func (*CustomFuncs) IsJSONScalar Uses

func (c *CustomFuncs) IsJSONScalar(value opt.ScalarExpr) bool

IsJSONScalar returns if the JSON value is a number, string, true, false, or null.

func (*CustomFuncs) IsLimited Uses

func (c *CustomFuncs) IsLimited(sub *memo.SubqueryPrivate) bool

IsLimited indicates whether a limit was pushed under the subquery already. See e.g. the rule IntroduceExistsLimit.

func (*CustomFuncs) IsListOfConstants Uses

func (c *CustomFuncs) IsListOfConstants(elems memo.ScalarListExpr) bool

IsListOfConstants returns true if elems is a list of constant values or tuples.

func (*CustomFuncs) IsPositiveLimit Uses

func (c *CustomFuncs) IsPositiveLimit(limit tree.Datum) bool

IsPositiveLimit is true if the given limit value is greater than zero.

func (*CustomFuncs) IsSameOrdering Uses

func (c *CustomFuncs) IsSameOrdering(
    first physical.OrderingChoice, other physical.OrderingChoice,
) bool

IsSameOrdering evaluates whether the two orderings are equal.

func (*CustomFuncs) IsString Uses

func (c *CustomFuncs) IsString(scalar opt.ScalarExpr) bool

IsString returns true if the given scalar expression is of type String.

func (*CustomFuncs) IsUnorderedGrouping Uses

func (c *CustomFuncs) IsUnorderedGrouping(grouping *memo.GroupingPrivate) bool

IsUnorderedGrouping returns true if the given grouping ordering is not specified.

func (*CustomFuncs) IsZipCorrelated Uses

func (c *CustomFuncs) IsZipCorrelated(zip memo.ZipExpr, cols opt.ColSet) bool

IsZipCorrelated returns true if any element in the zip references any of the given columns.

func (*CustomFuncs) JoinFiltersMatchAllLeftRows Uses

func (c *CustomFuncs) JoinFiltersMatchAllLeftRows(
    left, right memo.RelExpr, filters memo.FiltersExpr,
) bool

JoinFiltersMatchAllLeftRows returns true when each row in the given join's left input matches at least one row from the right input, according to the join filters. This is true when the following conditions are satisfied:

1. Each conjunct in the join condition is an equality between a not-null
   column from the left input and a not-null column from the right input.
2. All left input equality columns come from a single table (called its
   "equality table"), as do all right input equality columns (can be
   different table).
3. The right input contains every row from its equality table. There may be
   a subset of columns from the table, and/or duplicate rows, but every row
   must be present.
4. If the left equality table is the same as the right equality table, then
   it's the self-join case. The columns in each equality pair must have the
   same ordinal position in the table.
5. If the left equality table is different than the right equality table,
   then it's the foreign-key case. The left equality columns must map to
   a foreign key on the left equality table, and the right equality columns
   to the corresponding referenced columns in the right equality table.

func (*CustomFuncs) KeyCols Uses

func (c *CustomFuncs) KeyCols(in memo.RelExpr) opt.ColSet

KeyCols returns a column set consisting of the columns that make up the candidate key for the input expression (a key must be present).

func (*CustomFuncs) LimitGeMaxRows Uses

func (c *CustomFuncs) LimitGeMaxRows(limit tree.Datum, input memo.RelExpr) bool

LimitGeMaxRows returns true if the given constant limit value is greater than or equal to the max number of rows returned by the input expression.

func (*CustomFuncs) MakeAggCols Uses

func (c *CustomFuncs) MakeAggCols(aggOp opt.Operator, cols opt.ColSet) memo.AggregationsExpr

MakeAggCols constructs a new Aggregations operator containing an aggregate function of the given operator type for each of column in the given set. For example, for ConstAggOp and columns (1,2), this expression is returned:

(Aggregations
  [(ConstAgg (Variable 1)) (ConstAgg (Variable 2))]
  [1,2]
)

func (*CustomFuncs) MakeAggCols2 Uses

func (c *CustomFuncs) MakeAggCols2(
    aggOp opt.Operator, cols opt.ColSet, aggOp2 opt.Operator, cols2 opt.ColSet,
) memo.AggregationsExpr

MakeAggCols2 is similar to MakeAggCols, except that it allows two different sets of aggregate functions to be added to the resulting Aggregations operator, with one set appended to the other, like this:

(Aggregations
  [(ConstAgg (Variable 1)) (ConstAgg (Variable 2)) (FirstAgg (Variable 3))]
  [1,2,3]
)

func (*CustomFuncs) MakeArrayAggCol Uses

func (c *CustomFuncs) MakeArrayAggCol(typ *types.T) *memo.ColPrivate

MakeArrayAggCol returns a ColPrivate with the given type and an "array_agg" label.

func (*CustomFuncs) MakeEmptyColSet Uses

func (c *CustomFuncs) MakeEmptyColSet() opt.ColSet

MakeEmptyColSet returns a column set with no columns in it.

func (*CustomFuncs) MakeGrouping Uses

func (c *CustomFuncs) MakeGrouping(groupingCols opt.ColSet) *memo.GroupingPrivate

MakeGrouping constructs a new unordered GroupingPrivate using the given grouping columns.

func (*CustomFuncs) MakeLimited Uses

func (c *CustomFuncs) MakeLimited(sub *memo.SubqueryPrivate) *memo.SubqueryPrivate

MakeLimited specifies that the subquery has a limit set already. This prevents e.g. the rule IntroduceExistsLimit from applying twice.

func (*CustomFuncs) MakeOrderedGrouping Uses

func (c *CustomFuncs) MakeOrderedGrouping(
    groupingCols opt.ColSet, ordering physical.OrderingChoice,
) *memo.GroupingPrivate

MakeOrderedGrouping constructs a new GroupingPrivate using the given grouping columns and OrderingChoice private.

func (*CustomFuncs) MakeSegmentedOrdering Uses

func (c *CustomFuncs) MakeSegmentedOrdering(
    input memo.RelExpr,
    prefix opt.ColSet,
    ordering physical.OrderingChoice,
    limitOrdering physical.OrderingChoice,
) *physical.OrderingChoice

MakeSegmentedOrdering returns an ordering choice which satisfies both limitOrdering and the ordering required by a window function. Returns nil if no such ordering exists. See OrderingChoice.PrefixIntersection for more details.

func (*CustomFuncs) MakeSingleKeyJSONObject Uses

func (c *CustomFuncs) MakeSingleKeyJSONObject(key, value opt.ScalarExpr) opt.ScalarExpr

MakeSingleKeyJSONObject returns a JSON object with one entry, mapping key to value.

func (*CustomFuncs) MakeUnorderedSubquery Uses

func (c *CustomFuncs) MakeUnorderedSubquery() *memo.SubqueryPrivate

MakeUnorderedSubquery returns a SubqueryPrivate that specifies no ordering.

func (*CustomFuncs) MapJoinOpEqualities Uses

func (c *CustomFuncs) MapJoinOpEqualities(
    filters memo.FiltersExpr, leftCols, rightCols opt.ColSet,
) memo.FiltersExpr

MapJoinOpEqualities maps all variable equality conditions in filters to use columns in either leftCols or rightCols where possible. See canMapJoinOpEquivalenceGroup and mapJoinOpEquivalenceGroup for more info.

func (*CustomFuncs) MapJoinOpFilter Uses

func (c *CustomFuncs) MapJoinOpFilter(
    filters memo.FiltersExpr, src *memo.FiltersItem, dst memo.RelExpr,
) opt.ScalarExpr

MapJoinOpFilter maps a boolean expression src, which is a conjunct in the given filters expression, to use the output columns of the relational expression dst.

MapJoinOpFilter assumes that CanMapJoinOpFilter has already returned true, and therefore a mapping is possible (see comment above CanMapJoinOpFilter for details).

For each column in src that is not also in dst, MapJoinOpFilter replaces it with an equivalent column in dst. If there are multiple equivalent columns in dst, it chooses one arbitrarily. MapJoinOpFilter does not replace any columns in subqueries, since we know there are no correlated subqueries (otherwise CanMapJoinOpFilter would have returned false).

For example, consider this query:

SELECT * FROM a INNER JOIN b ON a.x=b.x AND a.x + b.y = 5

If MapJoinOpFilter is called with src as a.x + b.y = 5 and dst as (Scan b), it returns b.x + b.y = 5. MapJoinOpFilter should not be called with the equality predicate a.x = b.x, because it would just return the tautology b.x = b.x.

func (*CustomFuncs) MapSetOpFilterLeft Uses

func (c *CustomFuncs) MapSetOpFilterLeft(
    filter *memo.FiltersItem, set *memo.SetPrivate,
) opt.ScalarExpr

MapSetOpFilterLeft maps the filter onto the left expression by replacing the out columns of the filter with the appropriate corresponding columns in the left side of the operator. Useful for pushing filters to relations the set operation is composed of.

func (*CustomFuncs) MapSetOpFilterRight Uses

func (c *CustomFuncs) MapSetOpFilterRight(
    filter *memo.FiltersItem, set *memo.SetPrivate,
) opt.ScalarExpr

MapSetOpFilterRight maps the filter onto the right expression by replacing the out columns of the filter with the appropriate corresponding columns in the right side of the operator. Useful for pushing filters to relations the set operation is composed of.

func (*CustomFuncs) MergeProjectWithValues Uses

func (c *CustomFuncs) MergeProjectWithValues(
    projections memo.ProjectionsExpr, passthrough opt.ColSet, input memo.RelExpr,
) memo.RelExpr

MergeProjectWithValues merges a Project operator with its input Values operator. This is only possible in certain circumstances, which are described in the MergeProjectWithValues rule comment.

Values columns that are part of the Project passthrough columns are retained in the final Values operator, and Project synthesized columns are added to it. Any unreferenced Values columns are discarded. For example:

SELECT column1, 3 FROM (VALUES (1, 2))
=>
(VALUES (1, 3))

func (*CustomFuncs) MergeProjections Uses

func (c *CustomFuncs) MergeProjections(
    outer, inner memo.ProjectionsExpr, passthrough opt.ColSet,
) memo.ProjectionsExpr

MergeProjections concatenates the synthesized columns from the outer Projections operator, and the synthesized columns from the inner Projections operator that are passed through by the outer. Note that the outer synthesized columns must never contain references to the inner synthesized columns; this can be verified by first calling CanMergeProjections.

func (*CustomFuncs) MutationTable Uses

func (c *CustomFuncs) MutationTable(private *memo.MutationPrivate) opt.TableID

MutationTable returns the table upon which the mutation is applied.

func (*CustomFuncs) NeedSortedUniqueList Uses

func (c *CustomFuncs) NeedSortedUniqueList(list memo.ScalarListExpr) bool

NeedSortedUniqueList returns true if the given list is composed entirely of constant values that are either not in sorted order or have duplicates. If true, then ConstructSortedUniqueList needs to be called on the list to normalize it.

func (*CustomFuncs) NeededColMapLeft Uses

func (c *CustomFuncs) NeededColMapLeft(needed opt.ColSet, set *memo.SetPrivate) opt.ColSet

NeededColMapLeft returns the subset of a SetPrivate's LeftCols that corresponds to the needed subset of OutCols. This is useful for pruning columns in set operations.

func (*CustomFuncs) NeededColMapRight Uses

func (c *CustomFuncs) NeededColMapRight(needed opt.ColSet, set *memo.SetPrivate) opt.ColSet

NeededColMapRight returns the subset of a SetPrivate's RightCols that corresponds to the needed subset of OutCols. This is useful for pruning columns in set operations.

func (*CustomFuncs) NeededExplainCols Uses

func (c *CustomFuncs) NeededExplainCols(private *memo.ExplainPrivate) opt.ColSet

NeededExplainCols returns the columns needed by Explain's required physical properties.

func (*CustomFuncs) NeededGroupingCols Uses

func (c *CustomFuncs) NeededGroupingCols(private *memo.GroupingPrivate) opt.ColSet

NeededGroupingCols returns the columns needed by a grouping operator's grouping columns or requested ordering.

func (*CustomFuncs) NeededMutationCols Uses

func (c *CustomFuncs) NeededMutationCols(private *memo.MutationPrivate) opt.ColSet

NeededMutationCols returns the columns needed by a mutation operator. Note that this function makes no attempt to determine the minimal set of columns needed by the mutation private; it simply returns the input columns that are referenced by it. Other rules filter the FetchCols, CheckCols, etc. and can in turn trigger the PruneMutationInputCols rule.

func (*CustomFuncs) NeededMutationFetchCols Uses

func (c *CustomFuncs) NeededMutationFetchCols(
    op opt.Operator, private *memo.MutationPrivate,
) opt.ColSet

NeededMutationFetchCols returns the set of FetchCols needed by the given mutation operator. FetchCols are existing values that are fetched from the store and are then used to construct keys and values for update or delete KV operations.

func (*CustomFuncs) NeededOrdinalityCols Uses

func (c *CustomFuncs) NeededOrdinalityCols(private *memo.OrdinalityPrivate) opt.ColSet

NeededOrdinalityCols returns the columns needed by a Ordinality operator's requested ordering.

func (*CustomFuncs) NeededWindowCols Uses

func (c *CustomFuncs) NeededWindowCols(windows memo.WindowsExpr, p *memo.WindowPrivate) opt.ColSet

NeededWindowCols is the set of columns that the window function needs to execute.

func (*CustomFuncs) NegateComparison Uses

func (c *CustomFuncs) NegateComparison(
    cmp opt.Operator, left, right opt.ScalarExpr,
) opt.ScalarExpr

NegateComparison negates a comparison op like:

a.x = 5

to:

a.x <> 5

func (*CustomFuncs) NonKeyCols Uses

func (c *CustomFuncs) NonKeyCols(in memo.RelExpr) opt.ColSet

NonKeyCols returns a column set consisting of the output columns of the given input, minus the columns that make up its candidate key (which it must have).

func (*CustomFuncs) NormalizeTupleEquality Uses

func (c *CustomFuncs) NormalizeTupleEquality(left, right memo.ScalarListExpr) opt.ScalarExpr

NormalizeTupleEquality remaps the elements of two tuples compared for equality, like this:

(a, b, c) = (x, y, z)

into this:

(a = x) AND (b = y) AND (c = z)

func (*CustomFuncs) NullRejectAggVar Uses

func (c *CustomFuncs) NullRejectAggVar(
    aggs memo.AggregationsExpr, nullRejectCols opt.ColSet,
) *memo.VariableExpr

NullRejectAggVar scans through the list of aggregate functions and returns the Variable input of the first aggregate that is not ConstAgg. Such an aggregate must exist, since this is only called if at least one eligible null-rejection column was identified by the deriveGroupByRejectNullCols method (see its comment for more details).

func (*CustomFuncs) OpsAreSame Uses

func (c *CustomFuncs) OpsAreSame(left, right opt.Operator) bool

OpsAreSame returns true if the two operators are the same.

func (*CustomFuncs) OrderingCols Uses

func (c *CustomFuncs) OrderingCols(ordering physical.OrderingChoice) opt.ColSet

OrderingCols returns all non-optional columns that are part of the given OrderingChoice.

func (*CustomFuncs) OrderingIntersection Uses

func (c *CustomFuncs) OrderingIntersection(
    ordering1, ordering2 physical.OrderingChoice,
) physical.OrderingChoice

OrderingIntersection returns the intersection of two orderings. Should only be called if it is known that an intersection exists. See OrderingChoice.Intersection for more information.

func (*CustomFuncs) OrderingIntersects Uses

func (c *CustomFuncs) OrderingIntersects(ordering1, ordering2 physical.OrderingChoice) bool

OrderingIntersects returns true if <ordering1> and <ordering2> have an intersection. See OrderingChoice.Intersection for more information.

func (*CustomFuncs) OrderingSucceeded Uses

func (c *CustomFuncs) OrderingSucceeded(result *physical.OrderingChoice) bool

OrderingSucceeded returns true if an OrderingChoice is not nil.

func (*CustomFuncs) OrdinalityOrdering Uses

func (c *CustomFuncs) OrdinalityOrdering(private *memo.OrdinalityPrivate) physical.OrderingChoice

OrdinalityOrdering returns an ordinality operator's ordering choice.

func (*CustomFuncs) OuterCols Uses

func (c *CustomFuncs) OuterCols(e opt.Expr) opt.ColSet

OuterCols returns the set of outer columns associated with the given expression, whether it be a relational or scalar operator.

func (*CustomFuncs) OutputCols Uses

func (c *CustomFuncs) OutputCols(input memo.RelExpr) opt.ColSet

OutputCols returns the set of columns returned by the input expression.

func (*CustomFuncs) OutputCols2 Uses

func (c *CustomFuncs) OutputCols2(left, right memo.RelExpr) opt.ColSet

OutputCols2 returns the union of columns returned by the left and right expressions.

func (*CustomFuncs) PrimaryKeyCols Uses

func (c *CustomFuncs) PrimaryKeyCols(table opt.TableID) opt.ColSet

PrimaryKeyCols returns the key columns of the primary key of the table.

func (*CustomFuncs) ProjectColMapLeft Uses

func (c *CustomFuncs) ProjectColMapLeft(set *memo.SetPrivate) memo.ProjectionsExpr

ProjectColMapLeft returns a Projections operator that maps the left side columns in a SetPrivate to the output columns in it. Useful for replacing set operations with simpler constructs.

func (*CustomFuncs) ProjectColMapRight Uses

func (c *CustomFuncs) ProjectColMapRight(set *memo.SetPrivate) memo.ProjectionsExpr

ProjectColMapRight returns a Project operator that maps the right side columns in a SetPrivate to the output columns in it. Useful for replacing set operations with simpler constructs.

func (*CustomFuncs) ProjectExtraCol Uses

func (c *CustomFuncs) ProjectExtraCol(
    in memo.RelExpr, extra opt.ScalarExpr, extraID opt.ColumnID,
) memo.RelExpr

ProjectExtraCol constructs a new Project operator that passes through all columns in the given "in" expression, and then adds the given "extra" expression as an additional column.

func (*CustomFuncs) ProjectionCols Uses

func (c *CustomFuncs) ProjectionCols(projections memo.ProjectionsExpr) opt.ColSet

ProjectionCols returns the ids of the columns synthesized by the given Projections operator.

func (*CustomFuncs) ProjectionOuterCols Uses

func (c *CustomFuncs) ProjectionOuterCols(projections memo.ProjectionsExpr) opt.ColSet

ProjectionOuterCols returns the union of all outer columns from the given projection expressions.

func (*CustomFuncs) PruneAggCols Uses

func (c *CustomFuncs) PruneAggCols(
    target memo.AggregationsExpr, neededCols opt.ColSet,
) memo.AggregationsExpr

PruneAggCols creates a new AggregationsExpr that discards columns that are not referenced by the neededCols set.

func (*CustomFuncs) PruneCols Uses

func (c *CustomFuncs) PruneCols(target memo.RelExpr, neededCols opt.ColSet) memo.RelExpr

PruneCols creates an expression that discards any outputs columns of the target expression that are not used. If the target expression type supports column filtering (like Scan, Values, Projections, etc.), then create a new instance of that operator that does the filtering. Otherwise, construct a Project operator that wraps the operator and does the filtering. The new Project operator will be pushed down the tree until it merges with another operator that supports column filtering.

func (*CustomFuncs) PruneMutationFetchCols Uses

func (c *CustomFuncs) PruneMutationFetchCols(
    private *memo.MutationPrivate, neededCols opt.ColSet,
) *memo.MutationPrivate

PruneMutationFetchCols rewrites the given mutation private to no longer reference FetchCols that are not part of the neededCols set. The caller must have already done the analysis to prove that these columns are not needed, by calling CanPruneMutationFetchCols.

func (*CustomFuncs) PruneMutationReturnCols Uses

func (c *CustomFuncs) PruneMutationReturnCols(
    private *memo.MutationPrivate, needed opt.ColSet,
) *memo.MutationPrivate

PruneMutationReturnCols rewrites the given mutation private to no longer keep ReturnCols that are not referenced by the RETURNING clause or are not part of the primary key. The caller must have already done the analysis to prove that such columns exist, by calling CanPruneMutationReturnCols.

func (*CustomFuncs) PruneOrdering Uses

func (c *CustomFuncs) PruneOrdering(
    ordering physical.OrderingChoice, needed opt.ColSet,
) physical.OrderingChoice

PruneOrdering removes any columns referenced by an OrderingChoice that are not part of the needed column set. Should only be called if HasColsInOrdering is true.

func (*CustomFuncs) PruneOrderingGroupBy Uses

func (c *CustomFuncs) PruneOrderingGroupBy(
    private *memo.GroupingPrivate, neededCols opt.ColSet,
) *memo.GroupingPrivate

PruneOrderingGroupBy removes any columns referenced by the Ordering inside a GroupingPrivate which are not part of the neededCols set.

func (*CustomFuncs) PruneOrderingOrdinality Uses

func (c *CustomFuncs) PruneOrderingOrdinality(
    private *memo.OrdinalityPrivate, neededCols opt.ColSet,
) *memo.OrdinalityPrivate

PruneOrderingOrdinality removes any columns referenced by the Ordering inside a OrdinalityPrivate which are not part of the neededCols set.

func (*CustomFuncs) PruneSetPrivate Uses

func (c *CustomFuncs) PruneSetPrivate(needed opt.ColSet, set *memo.SetPrivate) *memo.SetPrivate

PruneSetPrivate returns a SetPrivate based on the given SetPrivate, but with unneeded input and output columns discarded.

func (*CustomFuncs) PruneWindows Uses

func (c *CustomFuncs) PruneWindows(needed opt.ColSet, windows memo.WindowsExpr) memo.WindowsExpr

PruneWindows restricts windows to only the columns which appear in needed. If we eliminate all the window functions, EliminateWindow will trigger and remove the expression entirely.

func (*CustomFuncs) ReduceGroupingCols Uses

func (c *CustomFuncs) ReduceGroupingCols(
    input memo.RelExpr, private *memo.GroupingPrivate,
) *memo.GroupingPrivate

ReduceGroupingCols constructs a new GroupByDef private, based on an existing definition. The new GroupByDef will not retain any grouping column that is functionally determined by other grouping columns. CanReduceGroupingCols should be called before calling this method, to ensure it has work to do.

func (*CustomFuncs) ReduceWindowPartitionCols Uses

func (c *CustomFuncs) ReduceWindowPartitionCols(
    input memo.RelExpr, private *memo.WindowPrivate,
) *memo.WindowPrivate

ReduceWindowPartitionCols reduces the set of columns being partitioned on to a smaller set.

func (*CustomFuncs) RejectNullCols Uses

func (c *CustomFuncs) RejectNullCols(in memo.RelExpr) opt.ColSet

RejectNullCols returns the set of columns that are candidates for NULL rejection filter pushdown. See the Relational.Rule.RejectNullCols comment for more details.

func (*CustomFuncs) RemoveAggDistinctForKeys Uses

func (c *CustomFuncs) RemoveAggDistinctForKeys(
    aggs memo.AggregationsExpr, private *memo.GroupingPrivate, input memo.RelExpr,
) memo.AggregationsExpr

RemoveAggDistinctForKeys rewrites aggregations to remove AggDistinct when the input column together with the grouping columns form a key. Returns the new Aggregation expression.

func (*CustomFuncs) RemoveFiltersItem Uses

func (c *CustomFuncs) RemoveFiltersItem(
    filters memo.FiltersExpr, search *memo.FiltersItem,
) memo.FiltersExpr

RemoveFiltersItem returns a new list that is a copy of the given list, except that it does not contain the given search item. If the list contains the item multiple times, then only the first instance is removed. If the list does not contain the item, then the method panics.

func (*CustomFuncs) ReplaceFiltersItem Uses

func (c *CustomFuncs) ReplaceFiltersItem(
    filters memo.FiltersExpr, search *memo.FiltersItem, replace opt.ScalarExpr,
) memo.FiltersExpr

ReplaceFiltersItem returns a new list that is a copy of the given list, except that the given search item has been replaced by the given replace item. If the list contains the search item multiple times, then only the first instance is replaced. If the list does not contain the item, then the method panics.

func (*CustomFuncs) SimplifyCoalesce Uses

func (c *CustomFuncs) SimplifyCoalesce(args memo.ScalarListExpr) opt.ScalarExpr

SimplifyCoalesce discards any leading null operands, and then if the next operand is a constant, replaces with that constant.

func (*CustomFuncs) SimplifyExplainOrdering Uses

func (c *CustomFuncs) SimplifyExplainOrdering(
    in memo.RelExpr, private *memo.ExplainPrivate,
) *memo.ExplainPrivate

SimplifyExplainOrdering makes the ordering required by the Explain operator less restrictive by removing optional columns, adding equivalent columns, and removing redundant columns.

func (*CustomFuncs) SimplifyFilters Uses

func (c *CustomFuncs) SimplifyFilters(filters memo.FiltersExpr) memo.FiltersExpr

SimplifyFilters removes True operands from a FiltersExpr, and normalizes any False or Null condition to a single False condition. Null values map to False because FiltersExpr are only used by Select and Join, both of which treat a Null filter conjunct exactly as if it were false.

SimplifyFilters also "flattens" any And operator child by merging its conditions into a new FiltersExpr list. If, after simplification, no operands remain, then SimplifyFilters returns an empty FiltersExpr.

This method assumes that the NormalizeNestedAnds rule has already run and ensured a left deep And tree. If not (maybe because it's a testing scenario), then this rule may rematch, but it should still make forward progress).

func (*CustomFuncs) SimplifyGroupingOrdering Uses

func (c *CustomFuncs) SimplifyGroupingOrdering(
    in memo.RelExpr, private *memo.GroupingPrivate,
) *memo.GroupingPrivate

SimplifyGroupingOrdering makes the ordering required by the grouping operator less restrictive by removing optional columns, adding equivalent columns, and removing redundant columns.

func (*CustomFuncs) SimplifyLimitOffsetOrdering Uses

func (c *CustomFuncs) SimplifyLimitOffsetOrdering(
    input memo.RelExpr, ordering physical.OrderingChoice,
) physical.OrderingChoice

SimplifyLimitOffsetOrdering makes the ordering required by the Limit or Offset operator less restrictive by removing optional columns, adding equivalent columns, and removing redundant columns.

func (*CustomFuncs) SimplifyNotNullEquality Uses

func (c *CustomFuncs) SimplifyNotNullEquality(
    eq opt.ScalarExpr, testOp, constOp opt.Operator,
) opt.ScalarExpr

SimplifyNotNullEquality simplifies an expression of the following form:

(Is | IsNot (Eq) (True | False | Null))

in the case where the Eq expression is guaranteed to never result in null. The testOp argument must be IsOp or IsNotOp, and the constOp argument must be TrueOp, FalseOp, or NullOp.

func (*CustomFuncs) SimplifyOrdinalityOrdering Uses

func (c *CustomFuncs) SimplifyOrdinalityOrdering(
    in memo.RelExpr, private *memo.OrdinalityPrivate,
) *memo.OrdinalityPrivate

SimplifyOrdinalityOrdering makes the ordering required by the Ordinality operator less restrictive by removing optional columns, adding equivalent columns, and removing redundant columns.

func (*CustomFuncs) SimplifyWhens Uses

func (c *CustomFuncs) SimplifyWhens(
    condition opt.ScalarExpr, whens memo.ScalarListExpr, orElse opt.ScalarExpr,
) opt.ScalarExpr

SimplifyWhens removes known unreachable WHEN cases and constructs a new CASE statement. Any known true condition is converted to the ELSE. If only the ELSE remains, its expression is returned. condition must be a ConstValue.

func (*CustomFuncs) SimplifyWindowOrdering Uses

func (c *CustomFuncs) SimplifyWindowOrdering(
    in memo.RelExpr, private *memo.WindowPrivate,
) *memo.WindowPrivate

SimplifyWindowOrdering makes the intra-partition ordering used by the window function less restrictive.

func (*CustomFuncs) SortFilters Uses

func (c *CustomFuncs) SortFilters(f memo.FiltersExpr) memo.FiltersExpr

SortFilters sorts a filter list by the IDs of the expressions. This has the effect of canonicalizing FiltersExprs which may have the same filters, but in a different order.

func (*CustomFuncs) SubqueryOrdering Uses

func (c *CustomFuncs) SubqueryOrdering(sub *memo.SubqueryPrivate) physical.OrderingChoice

SubqueryOrdering returns the ordering property on a SubqueryPrivate.

func (*CustomFuncs) SubqueryRequestedCol Uses

func (c *CustomFuncs) SubqueryRequestedCol(sub *memo.SubqueryPrivate) opt.ColumnID

SubqueryRequestedCol returns the requested column from a SubqueryPrivate. This function should only be used with ArrayFlatten expressions.

func (*CustomFuncs) Succeeded Uses

func (c *CustomFuncs) Succeeded(result opt.Expr) bool

Succeeded returns true if a result expression is not nil.

func (*CustomFuncs) TranslateNonIgnoreAggs Uses

func (c *CustomFuncs) TranslateNonIgnoreAggs(
    newIn memo.RelExpr,
    newAggs memo.AggregationsExpr,
    oldIn memo.RelExpr,
    oldAggs memo.AggregationsExpr,
    canaryCol opt.ColumnID,
) memo.RelExpr

TranslateNonIgnoreAggs checks if any of the aggregates being decorrelated are unable to ignore nulls. If that is the case, it inserts projections which check a "canary" aggregation that determines if an expression actually had any things grouped into it or not.

func (*CustomFuncs) UnifyComparison Uses

func (c *CustomFuncs) UnifyComparison(left, right opt.ScalarExpr) opt.ScalarExpr

UnifyComparison attempts to convert a constant expression to the type of the variable expression, if that conversion can round-trip and is monotonic.

func (*CustomFuncs) UnionCols Uses

func (c *CustomFuncs) UnionCols(left, right opt.ColSet) opt.ColSet

UnionCols returns the union of the left and right column sets.

func (*CustomFuncs) UnionCols3 Uses

func (c *CustomFuncs) UnionCols3(cols1, cols2, cols3 opt.ColSet) opt.ColSet

UnionCols3 returns the union of the three column sets.

func (*CustomFuncs) UnionCols4 Uses

func (c *CustomFuncs) UnionCols4(cols1, cols2, cols3, cols4 opt.ColSet) opt.ColSet

UnionCols4 returns the union of the four column sets.

func (*CustomFuncs) WindowOrdering Uses

func (c *CustomFuncs) WindowOrdering(private *memo.WindowPrivate) physical.OrderingChoice

WindowOrdering returns the ordering used by the window function.

func (*CustomFuncs) WindowPartition Uses

func (c *CustomFuncs) WindowPartition(priv *memo.WindowPrivate) opt.ColSet

WindowPartition returns the set of columns that the window function uses to partition.

func (*CustomFuncs) WithUses Uses

func (c *CustomFuncs) WithUses(r opt.Expr) map[opt.WithID]int

WithUses returns a map mapping WithIDs to the number of times a given With expression is referenced in the given expression.

func (*CustomFuncs) ZipOuterCols Uses

func (c *CustomFuncs) ZipOuterCols(zip memo.ZipExpr) opt.ColSet

ZipOuterCols returns the union of all outer columns from the given zip expressions.

type Factory Uses

type Factory struct {
    // contains filtered or unexported fields
}

Factory constructs a normalized expression tree within the memo. As each kind of expression is constructed by the factory, it transitively runs normalization transformations defined for that expression type. This may result in the construction of a different type of expression than what was requested. If, after normalization, the expression is already part of the memo, then construction is a no-op. Otherwise, a new memo group is created, with the normalized expression as its first and only expression.

Factory is largely auto-generated by optgen. The generated code can be found in factory.og.go. The factory.go file contains helper functions that are invoked by normalization patterns. While most patterns are specified in the Optgen DSL, the factory always calls the `onConstruct` method as its last step, in order to allow any custom manual code to execute.

func (*Factory) AssignPlaceholders Uses

func (f *Factory) AssignPlaceholders(from *memo.Memo) (err error)

AssignPlaceholders is used just before execution of a prepared Memo. It makes a copy of the given memo, but with any placeholder values replaced by their assigned values. This can trigger additional normalization rules that can substantially rewrite the tree. Once all placeholders are assigned, the exploration phase can begin.

func (*Factory) ConstructConstVal Uses

func (f *Factory) ConstructConstVal(d tree.Datum, t *types.T) opt.ScalarExpr

ConstructConstVal constructs one of the constant value operators from the given datum value. While most constants are represented with Const, there are special-case operators for True, False, and Null, to make matching easier. Null operators require the static type to be specified, so that rewrites do not change it.

func (*Factory) ConstructJoin Uses

func (f *Factory) ConstructJoin(
    joinOp opt.Operator, left, right memo.RelExpr, on memo.FiltersExpr, private *memo.JoinPrivate,
) memo.RelExpr

ConstructJoin constructs the join operator that corresponds to the given join operator type.

func (*Factory) ConstructZeroValues Uses

func (f *Factory) ConstructZeroValues() memo.RelExpr

ConstructZeroValues constructs a Values operator with zero rows and zero columns. It is used to create a dummy input for operators like CreateTable.

func (*Factory) CopyAndReplace Uses

func (f *Factory) CopyAndReplace(
    from memo.RelExpr, fromProps *physical.Required, replace ReplaceFunc,
)

CopyAndReplace builds this factory's memo by constructing a copy of a subtree that is part of another memo. That memo's metadata is copied to this factory's memo so that tables and columns referenced by the copied memo can keep the same ids. The copied subtree becomes the root of the destination memo, having the given physical properties.

The "replace" callback function allows the caller to override the default traversal and cloning behavior with custom logic. It is called for each node in the "from" subtree, and has the choice of constructing an arbitrary replacement node, or delegating to the default behavior by calling CopyAndReplaceDefault, which constructs a copy of the source operator using children returned by recursive calls to the replace callback. Note that if a non-leaf replacement node is constructed, its inputs must be copied using CopyAndReplaceDefault.

Sample usage:

var replaceFn ReplaceFunc
replaceFn = func(e opt.Expr) opt.Expr {
  if e.Op() == opt.PlaceholderOp {
    return f.ConstructConst(evalPlaceholder(e))
  }

  // Copy e, calling replaceFn on its inputs recursively.
  return f.CopyAndReplaceDefault(e, replaceFn)
}

f.CopyAndReplace(from, fromProps, replaceFn)

NOTE: Callers must take care to always create brand new copies of non- singleton source nodes rather than referencing existing nodes. The source memo should always be treated as immutable, and the destination memo must be completely independent of it once CopyAndReplace has completed.

func (*Factory) CustomFuncs Uses

func (f *Factory) CustomFuncs() *CustomFuncs

CustomFuncs returns the set of custom functions used by normalization rules.

func (*Factory) DetachMemo Uses

func (f *Factory) DetachMemo() *memo.Memo

DetachMemo extracts the memo from the optimizer, and then re-initializes the factory so that its reuse will not impact the detached memo. This method is used to extract a read-only memo during the PREPARE phase.

Before extracting the memo, DetachMemo first clears all column statistics in the memo. This is used to free up the potentially large amount of memory used by histograms. This does not affect the quality of the plan used at execution time, since the stats are just recalculated anyway when placeholders are assigned. If there are no placeholders, there is no need for column statistics, since the memo is already fully optimized.

func (*Factory) DisableOptimizations Uses

func (f *Factory) DisableOptimizations()

DisableOptimizations disables all transformation rules. The unaltered input expression tree becomes the output expression tree (because no transforms are applied).

func (*Factory) Init Uses

func (f *Factory) Init(evalCtx *tree.EvalContext)

Init initializes a Factory structure with a new, blank memo structure inside. This must be called before the factory can be used (or reused).

func (*Factory) Memo Uses

func (f *Factory) Memo() *memo.Memo

Memo returns the memo structure that the factory is operating upon.

func (*Factory) Metadata Uses

func (f *Factory) Metadata() *opt.Metadata

Metadata returns the query-specific metadata, which includes information about the columns and tables used in this particular query.

func (*Factory) NotifyOnAppliedRule Uses

func (f *Factory) NotifyOnAppliedRule(appliedRule AppliedRuleFunc)

NotifyOnAppliedRule sets a callback function which is invoked each time a normalize rule has been applied by the factory. If appliedRule is nil, then no further notifications are sent.

func (*Factory) NotifyOnMatchedRule Uses

func (f *Factory) NotifyOnMatchedRule(matchedRule MatchedRuleFunc)

NotifyOnMatchedRule sets a callback function which is invoked each time a normalize rule has been matched by the factory. If matchedRule is nil, then no further notifications are sent, and all rules are applied by default. In addition, callers can invoke the DisableOptimizations convenience method to disable all rules.

type MatchedRuleFunc Uses

type MatchedRuleFunc func(ruleName opt.RuleName) bool

MatchedRuleFunc defines the callback function for the NotifyOnMatchedRule event supported by the optimizer and factory. It is invoked each time an optimization rule (Normalize or Explore) has been matched. The name of the matched rule is passed as a parameter. If the function returns false, then the rule is not applied (i.e. skipped).

type ReplaceFunc Uses

type ReplaceFunc func(e opt.Expr) opt.Expr

ReplaceFunc is the callback function passed to the Factory.Replace method. It is called with each child of the expression passed to Replace. See the Replace method for more details.

Package norm imports 18 packages (graph) and is imported by 11 packages. Updated 2019-11-19. Refresh now. Tools for package owners.