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

     1  // Copyright 2016 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 sqlutil
    12  
    13  import (
    14  	"context"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/kv"
    17  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    18  	"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
    19  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    20  )
    21  
    22  // InternalExecutor is meant to be used by layers below SQL in the system that
    23  // nevertheless want to execute SQL queries (presumably against system tables).
    24  // It is extracted in this "sql/util" package to avoid circular references and
    25  // is implemented by *sql.InternalExecutor.
    26  type InternalExecutor interface {
    27  	// Exec executes the supplied SQL statement and returns the number of rows
    28  	// affected (not like the results; see Query()). If no user has been previously
    29  	// set through SetSessionData, the statement is executed as the root user.
    30  	//
    31  	// If txn is not nil, the statement will be executed in the respective txn.
    32  	//
    33  	// Exec is deprecated because it may transparently execute a query as root. Use
    34  	// ExecEx instead.
    35  	Exec(
    36  		ctx context.Context, opName string, txn *kv.Txn, statement string, params ...interface{},
    37  	) (int, error)
    38  
    39  	// ExecEx is like Exec, but allows the caller to override some session data
    40  	// fields.
    41  	//
    42  	// The fields set in session that are set override the respective fields if they
    43  	// have previously been set through SetSessionData().
    44  	ExecEx(
    45  		ctx context.Context,
    46  		opName string,
    47  		txn *kv.Txn,
    48  		o sqlbase.InternalExecutorSessionDataOverride,
    49  		stmt string,
    50  		qargs ...interface{},
    51  	) (int, error)
    52  
    53  	// Query executes the supplied SQL statement and returns the resulting rows.
    54  	// If no user has been previously set through SetSessionData, the statement is
    55  	// executed as the root user.
    56  	//
    57  	// If txn is not nil, the statement will be executed in the respective txn.
    58  	//
    59  	// Query is deprecated because it may transparently execute a query as root. Use
    60  	// QueryEx instead.
    61  	Query(
    62  		ctx context.Context, opName string, txn *kv.Txn, statement string, qargs ...interface{},
    63  	) ([]tree.Datums, error)
    64  
    65  	// QueryEx is like Query, but allows the caller to override some session data
    66  	// fields.
    67  	//
    68  	// The fields set in session that are set override the respective fields if
    69  	// they have previously been set through SetSessionData().
    70  	QueryEx(
    71  		ctx context.Context,
    72  		opName string,
    73  		txn *kv.Txn,
    74  		session sqlbase.InternalExecutorSessionDataOverride,
    75  		stmt string,
    76  		qargs ...interface{},
    77  	) ([]tree.Datums, error)
    78  
    79  	// QueryWithCols is like QueryEx, but it also returns the computed ResultColumns
    80  	// of the input query.
    81  	QueryWithCols(
    82  		ctx context.Context, opName string, txn *kv.Txn,
    83  		o sqlbase.InternalExecutorSessionDataOverride, statement string, qargs ...interface{},
    84  	) ([]tree.Datums, sqlbase.ResultColumns, error)
    85  
    86  	// QueryRow is like Query, except it returns a single row, or nil if not row is
    87  	// found, or an error if more that one row is returned.
    88  	//
    89  	// QueryRow is deprecated (like Query). Use QueryRowEx() instead.
    90  	QueryRow(
    91  		ctx context.Context, opName string, txn *kv.Txn, statement string, qargs ...interface{},
    92  	) (tree.Datums, error)
    93  
    94  	// QueryRowEx is like QueryRow, but allows the caller to override some session data
    95  	// fields.
    96  	//
    97  	// The fields set in session that are set override the respective fields if they
    98  	// have previously been set through SetSessionData().
    99  	QueryRowEx(
   100  		ctx context.Context,
   101  		opName string,
   102  		txn *kv.Txn,
   103  		session sqlbase.InternalExecutorSessionDataOverride,
   104  		stmt string,
   105  		qargs ...interface{},
   106  	) (tree.Datums, error)
   107  }
   108  
   109  // SessionBoundInternalExecutorFactory is a function that produces a "session
   110  // bound" internal executor.
   111  type SessionBoundInternalExecutorFactory func(
   112  	context.Context, *sessiondata.SessionData,
   113  ) InternalExecutor