github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/zigzag_join.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package sql
    12  
    13  import (
    14  	"context"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    17  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    18  )
    19  
    20  // zigzagJoinNode represents a zigzag join. A zigzag join uses multiple indexes
    21  // at the same time that are all prefixed with fixed columns (columns
    22  // constrained to constant values) followed by values that must remain
    23  // equal across all sides (such as primary keys). The zigzag joiner takes
    24  // advantage of the sorted order of those equality columns to efficiently
    25  // find rows that satisfy the constant constraints as well as the equality
    26  // constraints.
    27  //
    28  // For a more detailed description of zigzag joins, as well as when they can
    29  // be planned, see the comment in rowexec/zigzagjoiner.go.
    30  type zigzagJoinNode struct {
    31  	// sides contains information about each individual "side" of a
    32  	// zigzag join. Must contain 2 or more zigzagJoinSides.
    33  	sides []zigzagJoinSide
    34  
    35  	// columns are the produced columns, namely the columns in all
    36  	// indexes in 'sides' - in the same order as sides.
    37  	columns sqlbase.ResultColumns
    38  
    39  	// onCond is any ON condition to be used in conjunction with the implicit
    40  	// equality condition on keyCols.
    41  	onCond tree.TypedExpr
    42  
    43  	reqOrdering ReqOrdering
    44  }
    45  
    46  // zigzagJoinSide contains information about one "side" of the zigzag
    47  // join. Note that the length of all eqCols in one zigzagJoinNode should
    48  // be the same.
    49  type zigzagJoinSide struct {
    50  	// scan references a scan node containing index/table descriptor references
    51  	// for this side of the join.
    52  	scan *scanNode
    53  
    54  	// eqCols is an int slice containing the equated columns for this side
    55  	// of the zigzag join.
    56  	eqCols []int
    57  
    58  	// fixedVals contains fixed values for a prefix of this side's index columns.
    59  	// Represented as a values node with one row/tuple, and just the columns
    60  	// that are fixed.
    61  	fixedVals *valuesNode
    62  }
    63  
    64  func (zj *zigzagJoinNode) startExec(params runParams) error {
    65  	panic("zigzag joins cannot be executed outside of distsql")
    66  }
    67  
    68  // Next is part of the planNode interface.
    69  func (zj *zigzagJoinNode) Next(params runParams) (bool, error) {
    70  	panic("zigzag joins cannot be executed outside of distsql")
    71  }
    72  
    73  // Values is part of the planNode interface.
    74  func (zj *zigzagJoinNode) Values() tree.Datums {
    75  	panic("zigzag joins cannot be executed outside of distsql")
    76  }
    77  
    78  // Close is part of the planNode interface.
    79  func (zj *zigzagJoinNode) Close(ctx context.Context) {
    80  }