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

package sessiondata

import "github.com/cockroachdb/cockroach/pkg/sql/sessiondata"

Index

Package Files

internal.go search_path.go sequence_state.go session_data.go

Constants

const CRDBInternalSchemaName = "crdb_internal"

CRDBInternalSchemaName is the name of the crdb_internal system schema.

const InformationSchemaName = "information_schema"

InformationSchemaName is the name of the information_schema system schema.

const PgCatalogName = "pg_catalog"

PgCatalogName is the name of the pg_catalog system schema.

const PgExtensionSchemaName = "pg_extension"

PgExtensionSchemaName is the alias for schemas which are usually "public" in postgres when installing an extension, but must be stored as a separate schema in CRDB.

const PgSchemaPrefix = "pg_"

PgSchemaPrefix is a prefix for Postgres system schemas. Users cannot create schemas with this prefix.

const PgTempSchemaName = "pg_temp"

PgTempSchemaName is the alias for temporary schemas across sessions.

const PublicSchemaName = "public"

PublicSchemaName is the name of the pg_catalog system schema.

const UserSchemaName = "$user"

UserSchemaName is the alias for schema names for users.

Variables

var DefaultSearchPath = MakeSearchPath(
    []string{UserSchemaName, PublicSchemaName},
)

DefaultSearchPath is the search path used by virgin sessions.

var EmptySearchPath = SearchPath{}

EmptySearchPath is a SearchPath with no schema names in it.

var NoSessionDataOverride = InternalExecutorOverride{}

NoSessionDataOverride is the empty InternalExecutorOverride which does not override any session data.

var NodeUserSessionDataOverride = InternalExecutorOverride{
    User: security.MakeSQLUsernameFromPreNormalizedString(security.NodeUser)}

NodeUserSessionDataOverride is an InternalExecutorOverride which overrides the users to the NodeUser.

func MarshalNonLocal Uses

func MarshalNonLocal(sd *SessionData, proto *sessiondatapb.SessionData)

MarshalNonLocal serializes all non-local parameters from SessionData struct that don't have native protobuf support into proto.

type DistSQLExecMode Uses

type DistSQLExecMode int64

DistSQLExecMode controls if and when the Executor distributes queries. Since 2.1, we run everything through the DistSQL infrastructure, and these settings control whether to use a distributed plan, or use a plan that only involves local DistSQL processors.

const (
    // DistSQLOff means that we never distribute queries.
    DistSQLOff DistSQLExecMode = iota
    // DistSQLAuto means that we automatically decide on a case-by-case basis if
    // we distribute queries.
    DistSQLAuto
    // DistSQLOn means that we distribute queries that are supported.
    DistSQLOn
    // DistSQLAlways means that we only distribute; unsupported queries fail.
    DistSQLAlways
)

func DistSQLExecModeFromString Uses

func DistSQLExecModeFromString(val string) (_ DistSQLExecMode, ok bool)

DistSQLExecModeFromString converts a string into a DistSQLExecMode

func (DistSQLExecMode) String Uses

func (m DistSQLExecMode) String() string

type ExperimentalDistSQLPlanningMode Uses

type ExperimentalDistSQLPlanningMode int64

ExperimentalDistSQLPlanningMode controls if and when the opt-driven DistSQL planning is used to create physical plans.

const (
    // ExperimentalDistSQLPlanningOff means that we always use the old path of
    // going from opt.Expr to planNodes and then to processor specs.
    ExperimentalDistSQLPlanningOff ExperimentalDistSQLPlanningMode = iota
    // ExperimentalDistSQLPlanningOn means that we will attempt to use the new
    // path for performing DistSQL planning in the optimizer, and if that
    // doesn't succeed for some reason, we will fallback to the old path.
    ExperimentalDistSQLPlanningOn
    // ExperimentalDistSQLPlanningAlways means that we will only use the new path,
    // and if it fails for any reason, the query will fail as well.
    ExperimentalDistSQLPlanningAlways
)

func ExperimentalDistSQLPlanningModeFromString Uses

func ExperimentalDistSQLPlanningModeFromString(val string) (ExperimentalDistSQLPlanningMode, bool)

ExperimentalDistSQLPlanningModeFromString converts a string into a ExperimentalDistSQLPlanningMode. False is returned if the conversion was unsuccessful.

func (ExperimentalDistSQLPlanningMode) String Uses

func (m ExperimentalDistSQLPlanningMode) String() string

type InternalExecutorOverride Uses

type InternalExecutorOverride struct {
    // User represents the user that the query will run under.
    User security.SQLUsername
    // Database represents the default database for the query.
    Database string
    // ApplicationName represents the application that the query runs under.
    ApplicationName string
    // SearchPath represents the namespaces to search in.
    SearchPath *SearchPath
    // DatabaseIDToTempSchemaID represents the mapping for temp schemas used which
    // allows temporary schema resolution by ID.
    DatabaseIDToTempSchemaID map[uint32]uint32
}

InternalExecutorOverride is used by the InternalExecutor interface to allow control over some of the session data.

type LocalOnlySessionData Uses

type LocalOnlySessionData struct {
    // SaveTablesPrefix indicates that a table should be created with the
    // given prefix for the output of each subexpression in a query. If
    // SaveTablesPrefix is empty, no tables are created.
    SaveTablesPrefix string
    // RemoteAddr is used to generate logging events.
    RemoteAddr net.Addr
    // VectorizeRowCountThreshold indicates the row count above which the
    // vectorized execution engine will be used if possible.
    VectorizeRowCountThreshold uint64
    // ExperimentalDistSQLPlanningMode indicates whether the experimental
    // DistSQL planning driven by the optimizer is enabled.
    ExperimentalDistSQLPlanningMode ExperimentalDistSQLPlanningMode
    // DistSQLMode indicates whether to run queries using the distributed
    // execution engine.
    DistSQLMode DistSQLExecMode
    // OptimizerFKCascadesLimit is the maximum number of cascading operations that
    // are run for a single query.
    OptimizerFKCascadesLimit int
    // ResultsBufferSize specifies the size at which the pgwire results buffer
    // will self-flush.
    ResultsBufferSize int64
    // NoticeDisplaySeverity indicates the level of Severity to send notices for the given
    // session.
    NoticeDisplaySeverity pgnotice.DisplaySeverity
    // SerialNormalizationMode indicates how to handle the SERIAL pseudo-type.
    SerialNormalizationMode SerialNormalizationMode
    // DatabaseIDToTempSchemaID stores the temp schema ID for every database that
    // has created a temporary schema. The mapping is from descpb.ID -> desscpb.ID,
    // but cannot be stored as such due to package dependencies.
    DatabaseIDToTempSchemaID map[uint32]uint32
    // StmtTimeout is the duration a query is permitted to run before it is
    // canceled by the session. If set to 0, there is no timeout.
    StmtTimeout time.Duration
    // IdleInSessionTimeout is the duration a session is permitted to idle before
    // the session is canceled. If set to 0, there is no timeout.
    IdleInSessionTimeout time.Duration
    // IdleInTransactionSessionTimeout is the duration a session is permitted to
    // idle in a transaction before the session is canceled.
    // If set to 0, there is no timeout.
    IdleInTransactionSessionTimeout time.Duration
    // ReorderJoinsLimit indicates the number of joins at which the optimizer should
    // stop attempting to reorder.
    ReorderJoinsLimit int
    // DefaultTxnPriority indicates the default priority of newly created
    // transactions.
    // NOTE: we'd prefer to use tree.UserPriority here, but doing so would
    // introduce a package dependency cycle.
    DefaultTxnPriority int
    // DefaultReadOnly indicates the default read-only status of newly created
    // transactions.
    DefaultReadOnly bool
    // PartiallyDistributedPlansDisabled indicates whether the partially
    // distributed plans produced by distSQLSpecExecFactory are disabled. It
    // should be set to 'true' only in tests that verify that the old and the
    // new factories return exactly the same physical plans.
    // TODO(yuzefovich): remove it when deleting old sql.execFactory.
    PartiallyDistributedPlansDisabled bool
    // OptimizerUseHistograms indicates whether we should use histograms for
    // cardinality estimation in the optimizer.
    OptimizerUseHistograms bool
    // OptimizerUseMultiColStats indicates whether we should use multi-column
    // statistics for cardinality estimation in the optimizer.
    OptimizerUseMultiColStats bool
    // SafeUpdates causes errors when the client
    // sends syntax that may have unwanted side effects.
    SafeUpdates bool
    // PreferLookupJoinsForFKs causes foreign key operations to prefer lookup
    // joins.
    PreferLookupJoinsForFKs bool
    // ZigzagJoinEnabled indicates whether the optimizer should try and plan a
    // zigzag join.
    ZigzagJoinEnabled bool
    // RequireExplicitPrimaryKeys indicates whether CREATE TABLE statements should
    // error out if no primary key is provided.
    RequireExplicitPrimaryKeys bool
    // ForceSavepointRestart overrides the default SAVEPOINT behavior
    // for compatibility with certain ORMs. When this flag is set,
    // the savepoint name will no longer be compared against the magic
    // identifier `cockroach_restart` in order use a restartable
    // transaction.
    ForceSavepointRestart bool
    // AllowPrepareAsOptPlan must be set to allow use of
    //   PREPARE name AS OPT PLAN '...'
    AllowPrepareAsOptPlan bool
    // TempTablesEnabled indicates whether temporary tables can be created or not.
    TempTablesEnabled bool
    // HashShardedIndexesEnabled indicates whether hash sharded indexes can be created.
    HashShardedIndexesEnabled bool
    // DisallowFullTableScans indicates whether queries that plan full table scans
    // should be rejected.
    DisallowFullTableScans bool
    // ImplicitSelectForUpdate is true if FOR UPDATE locking may be used during
    // the row-fetch phase of mutation statements.
    ImplicitSelectForUpdate bool
    // InsertFastPath is true if the fast path for insert (with VALUES input) may
    // be used.
    InsertFastPath bool
    // AlterColumnTypeGeneralEnabled is true if ALTER TABLE ... ALTER COLUMN ...
    // TYPE x may be used for general conversions requiring online schema change/
    AlterColumnTypeGeneralEnabled bool
    // SynchronousCommit is a dummy setting for the synchronous_commit var.
    SynchronousCommit bool
    // EnableSeqScan is a dummy setting for the enable_seqscan var.
    EnableSeqScan bool
    // EnableMultiColumnInvertedIndexes indicates whether creating multi-column
    // inverted indexes is allowed.
    // TODO(mgartner): remove this once multi-column inverted indexes are fully
    // supported.
    EnableMultiColumnInvertedIndexes bool
}

LocalOnlySessionData contains session parameters that only influence the execution on the gateway node and don't need to be propagated to the remote nodes.

type SearchPath Uses

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

SearchPath represents a list of namespaces to search builtins in. The names must be normalized (as per Name.Normalize) already.

func DefaultSearchPathForUser Uses

func DefaultSearchPathForUser(username security.SQLUsername) SearchPath

DefaultSearchPathForUser returns the default search path with the user specific schema name set so that it can be expanded during resolution.

func MakeSearchPath Uses

func MakeSearchPath(paths []string) SearchPath

MakeSearchPath returns a new immutable SearchPath struct. The paths slice must not be modified after hand-off to MakeSearchPath.

func (SearchPath) Contains Uses

func (s SearchPath) Contains(target string) bool

Contains returns true iff the SearchPath contains the given string.

func (SearchPath) Equals Uses

func (s SearchPath) Equals(other *SearchPath) bool

Equals returns true if two SearchPaths are the same.

func (SearchPath) GetPathArray Uses

func (s SearchPath) GetPathArray() []string

GetPathArray returns the underlying path array of this SearchPath. The resultant slice is not to be modified.

func (SearchPath) GetTemporarySchemaName Uses

func (s SearchPath) GetTemporarySchemaName() string

GetTemporarySchemaName returns the temporary schema specific to the current session.

func (SearchPath) Iter Uses

func (s SearchPath) Iter() SearchPathIter

Iter returns an iterator through the search path. We must include the implicit pg_catalog and temporary schema at the beginning of the search path, unless they have been explicitly set later by the user. We also include pg_extension in the path, as this normally be used in place of the public schema. This should be read before "public" is read. "The system catalog schema, pg_catalog, is always searched, whether it is mentioned in the path or not. If it is mentioned in the path then it will be searched in the specified order. If pg_catalog is not in the path then it will be searched before searching any of the path items." "Likewise, the current session's temporary-table schema, pg_temp_nnn, is always searched if it exists. It can be explicitly listed in the path by using the alias pg_temp. If it is not listed in the path then it is searched first (even before pg_catalog)." - https://www.postgresql.org/docs/9.1/static/runtime-config-client.html

func (SearchPath) IterWithoutImplicitPGSchemas Uses

func (s SearchPath) IterWithoutImplicitPGSchemas() SearchPathIter

IterWithoutImplicitPGSchemas is the same as Iter, but does not include the implicit pg_temp and pg_catalog.

func (SearchPath) MaybeResolveTemporarySchema Uses

func (s SearchPath) MaybeResolveTemporarySchema(schemaName string) (string, error)

MaybeResolveTemporarySchema returns the session specific temporary schema for the pg_temp alias (only if a temporary schema exists). It acts as a pass through for all other schema names.

func (SearchPath) String Uses

func (s SearchPath) String() string

func (SearchPath) UpdatePaths Uses

func (s SearchPath) UpdatePaths(paths []string) SearchPath

UpdatePaths returns a new immutable SearchPath struct with the paths supplied and the same tempSchemaName and userSchemaName as before.

func (SearchPath) WithTemporarySchemaName Uses

func (s SearchPath) WithTemporarySchemaName(tempSchemaName string) SearchPath

WithTemporarySchemaName returns a new immutable SearchPath struct with the tempSchemaName supplied and the same paths as before. This should be called every time a session creates a temporary schema for the first time.

func (SearchPath) WithUserSchemaName Uses

func (s SearchPath) WithUserSchemaName(userSchemaName string) SearchPath

WithUserSchemaName returns a new immutable SearchPath struct with the userSchemaName populated and the same values for all other fields as before.

type SearchPathIter Uses

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

SearchPathIter enables iteration over the search paths without triggering an allocation. Use one of the SearchPath.Iter methods to get an instance of the iterator, and then repeatedly call the Next method in order to iterate over each search path. The tempSchemaName in the iterator is only set if the session has created a temporary schema.

func (*SearchPathIter) Next Uses

func (iter *SearchPathIter) Next() (path string, ok bool)

Next returns the next search path, or false if there are no remaining paths.

type SequenceState Uses

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

SequenceState stores session-scoped state used by sequence builtins.

All public methods of SequenceState are thread-safe, as the structure is meant to be shared by statements executing in parallel on a session.

func NewSequenceState Uses

func NewSequenceState() *SequenceState

NewSequenceState creates a SequenceState.

func (*SequenceState) Export Uses

func (ss *SequenceState) Export() (map[uint32]int64, uint32)

Export returns a copy of the SequenceState's state - the latestValues and lastSequenceIncremented. If there are no values in latestValues, the returned map will be nil. lastSequenceIncremented is only defined if latestValues is non-empty.

func (*SequenceState) GetLastValue Uses

func (ss *SequenceState) GetLastValue() (int64, error)

GetLastValue returns the value most recently obtained by nextval() for the last sequence for which RecordLatestVal() was called.

func (*SequenceState) GetLastValueByID Uses

func (ss *SequenceState) GetLastValueByID(seqID uint32) (int64, bool)

GetLastValueByID returns the value most recently obtained by nextval() for the given sequence in this session. The bool retval is false if RecordLatestVal() was never called on the requested sequence.

func (*SequenceState) RecordValue Uses

func (ss *SequenceState) RecordValue(seqID uint32, val int64)

RecordValue records the latest manipulation of a sequence done by a session.

func (*SequenceState) SetLastSequenceIncremented Uses

func (ss *SequenceState) SetLastSequenceIncremented(seqID uint32)

SetLastSequenceIncremented sets the id of the last incremented sequence. Usually this id is set through RecordValue().

type SerialNormalizationMode Uses

type SerialNormalizationMode int64

SerialNormalizationMode controls if and when the Executor uses DistSQL.

const (
    // SerialUsesRowID means use INT NOT NULL DEFAULT unique_rowid().
    SerialUsesRowID SerialNormalizationMode = iota
    // SerialUsesVirtualSequences means create a virtual sequence and
    // use INT NOT NULL DEFAULT nextval(...).
    SerialUsesVirtualSequences
    // SerialUsesSQLSequences means create a regular SQL sequence and
    // use INT NOT NULL DEFAULT nextval(...).
    SerialUsesSQLSequences
)

func SerialNormalizationModeFromString Uses

func SerialNormalizationModeFromString(val string) (_ SerialNormalizationMode, ok bool)

SerialNormalizationModeFromString converts a string into a SerialNormalizationMode

func (SerialNormalizationMode) String Uses

func (m SerialNormalizationMode) String() string

type SessionData Uses

type SessionData struct {
    // SessionData contains session parameters that are easily serializable and
    // are required to be propagated to the remote nodes for the correct
    // execution of DistSQL flows.
    sessiondatapb.SessionData
    // LocalOnlySessionData contains session parameters that don't need to be
    // propagated to the remote nodes.
    LocalOnlySessionData

    // All session parameters below must be propagated to the remote nodes but
    // are not easily serializable. They require custom serialization
    // (MarshalNonLocal) and deserialization (UnmarshalNonLocal).
    //
    // Location indicates the current time zone.
    Location *time.Location
    // SearchPath is a list of namespaces to search builtins in.
    SearchPath SearchPath
    // SequenceState gives access to the SQL sequences that have been
    // manipulated by the session.
    SequenceState *SequenceState
}

SessionData contains session parameters. They are all user-configurable. A SQL Session changes fields in SessionData through sql.sessionDataMutator.

func UnmarshalNonLocal Uses

func UnmarshalNonLocal(proto sessiondatapb.SessionData) (*SessionData, error)

UnmarshalNonLocal returns a new SessionData based on the serialized representation. Note that only non-local session parameters are populated.

func (*SessionData) GetLocation Uses

func (s *SessionData) GetLocation() *time.Location

GetLocation returns the session timezone.

func (*SessionData) GetTemporarySchemaIDForDb Uses

func (s *SessionData) GetTemporarySchemaIDForDb(dbID uint32) (uint32, bool)

GetTemporarySchemaIDForDb returns the schemaID for the temporary schema if one exists for the DB. The second return value communicates the existence of the temp schema for that DB.

func (*SessionData) IsTemporarySchemaID Uses

func (s *SessionData) IsTemporarySchemaID(ID uint32) bool

IsTemporarySchemaID returns true if the given ID refers to any of the temp schemas created by the session.

Package sessiondata imports 11 packages (graph) and is imported by 83 packages. Updated 2020-12-01. Refresh now. Tools for package owners.