sql

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 239 Imported by: 0

Documentation ¶

Overview ¶

Package sql provides the user-facing API for access to a Cockroach datastore. As the name suggests, the API is based around SQL, the same SQL you find in traditional RDBMS systems like Oracle, MySQL or Postgres. The core Cockroach system implements a distributed, transactional, monolithic sorted key-value map. The sql package builds on top of this core system (provided by the storage and kv packages) adding parsing, query planning and query execution as well as defining the privilege model.

Databases and Tables ¶

The two primary objects are databases and tables. A database is a namespace which holds a series of tables. Conceptually, a database can be viewed as a directory in a filesystem plus some additional metadata. A table is like a file on steroids: it contains a structured layout of rows and columns along with secondary indexes.

Like a directory, a database has a name and some metadata. The metadata is defined by the DatabaseDescriptor:

message DatabaseDescriptor {
  optional string name;
  optional uint32 id;
  optional PrivilegeDescriptor privileges;
}

As you can see, currently the metadata we store for databases just consists of privileges.

Similarly, tables have a TableDescriptor:

message TableDescriptor {
  optional string name;
  optional uint32 id;
  repeated ColumnDescriptor columns;
  optional IndexDescriptor primary_index;
  repeated IndexDescriptor indexes;
  optional PrivilegeDescriptor privileges;
}

Both the database ID and the table ID are allocated from the same "ID space" and IDs are never reused.

The namespace in which databases and tables exist contains only two levels: the root level contains databases and the database level contains tables. The "system.namespace" and "system.descriptor" tables implement the mapping from database/table name to ID and from ID to descriptor:

CREATE TABLE system.namespace (
  "parentID" INT,
  "name"     CHAR,
  "id"       INT,
  PRIMARY KEY ("parentID", name)
);

Create TABLE system.descriptor (
  "id"         INT PRIMARY KEY,
  "descriptor" BLOB
);

The ID 0 is a reserved ID used for the "root" of the namespace in which the databases reside. In order to look up the ID of a database given its name, the system runs the underlying key-value operations that correspond to the following query:

SELECT id FROM system.namespace WHERE "parentID" = 0 AND name = <database-name>

And given a database/table ID, the system looks up the descriptor using the following query:

SELECT descriptor FROM system.descriptor WHERE id = <ID>

Let's also create two new tables to use as running examples, one relatively simple, and one a little more complex. The first table is just a list of stores, with a "store_id" primary key that is an automatically incremented unique integer as the primary key (the "SERIAL" datatype) and a name.

CREATE DATABASE test;
SET DATABASE TO test;

Create TABLE stores (
  "store_id" SERIAL PRIMARY KEY,
  "name" CHAR UNIQUE
);

The second table

CREATE TABLE inventory (
  "item_id" INT UNIQUE,
  "name" CHAR UNIQUE,
  "at_store" INT,
  "stock" INT,
  PRIMARY KEY (item_id, at_store),
  CONSTRAINT at_store_fk FOREIGN KEY (at_store) REFERENCES stores (store_id)
);

Primary Key Addressing ¶

All of the SQL data stored in tables is mapped down to individual keys and values. We call the exact mapping converting any table or row to a key value pair "key addressing". Cockroach's key addressing relies upon a primary key, and thus all tables have a primary key, whether explicitly listed in the schema or automatically generated. Note that the notion of a "primary key" refers to the primary key in the SQL sense, and is unrelated to the "key" in Cockroach's underlying key-value pairs.

Primary keys consist of one or more non-NULL columns from the table. For a given row of the table, the columns for the primary key are encoded into a single string. For example, our inventory table would be encoded as:

/item_id/at_store

[Note that "/" is being used to disambiguate the components of the key. The actual encodings do not use the "/" character. The actual encoding is specified in the `util` package in `util/encoding`. These encoding routines allow for the encoding of NULL values, integers, floating point numbers and strings such that the lexicographic ordering of the encoded strings corresponds to the same ordering of the unencoded data.]

Before being stored in the monolithic key-value space, the encoded primary key columns are prefixed with the table ID and an ID indicating that the key corresponds to the primary index. The prefix for the inventory table looks like this:

/TableID/PrimaryIndexID/item_id/at_store

Each column value is stored in a key with that prefix. Every column has a unique ID (local to the table). The value for every cell is stored at the key:

/TableID/PrimaryIndexID/item_id/at_store/ColumnID -> ColumnValue

Thus, the scan over the range

[/TableID/PrimaryIndexID/item_id/at_store,
/TableID/PrimaryIndexID/item_id/at_storf)

Where the abuse of notation "namf" in the end key refers to the key resulting from incrementing the value of the start key. As an efficiency, we do not store columns NULL values. Thus, all returned rows from the above scan give us enough information to construct the entire row. However, a row that has exclusively NULL values in non-primary key columns would have nothing stored at all. Thus, to note the existence of a row with only a primary key and remaining NULLs, every row also has a sentinel key indicating its existence. The sentinel key is simply the primary index key, with an empty value:

/TableID/PrimaryIndexID/item_id/at_store -> <empty>

Thus the above scan on such a row would return a single key, which we can use to reconstruct the row filling in NULLs for the non-primary-key values.

Column Families ¶

The above structure is inefficient if we have many columns, since each row in an N-column table results in up to N+1 entries (1 sentinel key + N keys if every column was non-NULL). Thus, Cockroach has the ability to group multiple columns together and write them as a single key-value pair. We call this a "column family", and there are more details in this blog post: https://www.cockroachlabs.com/blog/sql-cockroachdb-column-families/

Secondary Indexes ¶

Despite not being a formal part of the SQL standard, secondary indexes are one of its most powerful features. Secondary indexes are a level of indirection that allow quick lookups of a row using something other than the primary key. As an example, here is a secondary index on the "inventory" table, using only the "name" column:

CREATE INDEX name ON inventory (name);

This secondary index allows fast lookups based on just the "name". We use the following key addressing scheme for this non-unique index:

/TableId/SecondaryIndexID/name/item_id/at_store -> <empty>

Notice that while the index is on "name", the key contains both "name" and the values for item_id and at_store. This is done to ensure that each row for a table has a unique key for the non-unique index. In general, in order to guarantee that a non-unique index is unique, we encode the index's columns followed by any primary key columns that have not already been mentioned. Since the primary key must uniquely define a row, this transforms any non-unique index into a unique index.

Let's suppose that we had instead defined the index as:

CREATE UNIQUE INDEX name ON inventory (name, item_id);

Since this index is defined on creation as a unique index, we do not need to append the rest of the primary key columns to ensure uniqueness; instead, any insertion of a row into the table that would result in a duplication in the index will fail (and if there already are duplicates upon creation, the index creation itself will fail). However, we still need to be able to decode the full primary key by reading this index, as we will see later, in order to read any columns that are not in this index:

SELECT at_store FROM inventory WHERE name = "foo";

The solution is to put any remaining primary key columns into the value. Thus, the key addressing for this unique index looks like this:

/TableID/SecondaryIndexID/name/item_id -> at_store

The value for a unique index is composed of any primary key columns that are not already part of the index ("at_store" in this example). The goal of this key addressing scheme is to ensure that the primary key is fully specified by the key-value pair, and that the key portion is unique. However, any lookup of a non-primary and non-index column requires two reads, first to decode the primary key, and then to read the full row for the primary key, which contains all the columns. For instance, to read the value of the "stock" column in this table:

SELECT stock FROM inventory WHERE name = "foo";

Looking this up by the index on "name" does not give us the value of the "stock" column. Instead, to process this query, Cockroach does two key-value reads, which are morally equivalent to the following two SQL queries:

SELECT (item_id, at_store) FROM inventory WHERE name = "foo";

Then we use the values for the primary key that we received from the first query to perform the lookup:

SELECT stock FROM inventory WHERE item_id = "..." AND at_store = "...";

Query Planning and Execution ¶

SQL queries are executed by converting every SQL query into a set of transactional key-value operations. The Cockroach distributed transactional key-value store provides a few operations, of which we shall discuss execution using two important ones: conditional puts, and ordered scans.

Query planning is the system which takes a parsed SQL statement (described by an abstract syntax tree) and creates an execution plan which is itself a tree of operations. The execution tree consists of leaf nodes that are SCANs and PUTs, and internal nodes that consist of operations such as join, groupby, sort, or projection.. For the bulk of SQL statements, query planning is straightforward: the complexity lies in SELECT.

At one end of the performance spectrum, an implementation of SELECT can be straightforward: do a full scan of the (joined) tables in the FROM clause, filter rows based on the WHERE clause, group the resulting rows based on the GROUP BY clause, filter those rows using the HAVING clause, and sort the remaining rows using the ORDER BY clause. There are a number of steps, but they all have well defined semantics and are mostly just an exercise in software engineering: retrieve the rows as quickly as possible and then send them through the pipeline of filtering, grouping, filtering and sorting.

However, this naive execution plan would have poor performance if the first scans return large amounts of data: if we are scanning orders of magnitude extra data, only to discard the vast majority of rows as we filter out the few rows that we need, this is needlessly inefficient. Instead, the query planner attempts to take advantage of secondary indexes to limit the data retrieved by the leafs. Additionally, the query planner makes joins between tables faster by taking advantage of the different sort orders of various secondary indexes, and avoiding re-sorting (or taking advantage of partial sorts to limit the amount of sorting done). As query planning is under active development, the details of how we implement this are in flux and will continue to be in flux for the foreseeable future. This section is intended to provide a high-level overview of a few of the techniques involved.

For a SELECT query, after parsing it, the query planner performs semantic analysis to statically verify if the query obeys basic type-safety checks, and to resolve names within the query to actual objects within the system. Let's consider a query which looks up the stock of an item in the inventory table named "foo" with item_id X:

SELECT stock FROM inventory WHERE item_id = X AND name = 'test'

The query planner first needs to resolve the "inventory" qualified name in the FROM clause to the appropriate TableDescriptor. It also needs to resolve the "item_id", "stock" and "name" column references to the appropriate column descriptions with the "inventory" TableDescriptor. Lastly, as part of semantic analysis, the query planner verifies that the expressions in the select targets and the WHERE clause are valid (e.g. the WHERE clause evaluates to a boolean).

From that starting point, the query planner then analyzes the GROUP BY and ORDER BY clauses, adding "hidden" targets for expressions used in those clauses that are not explicit targets of the query. Our example query does not have any GROUP BY or ORDER BY clauses, so we move straight to the next step: index selection. Index selection is the stage where the query planner selects the best index to scan and selects the start and end keys that minimize the amount of scanned data. Depending on the complexity of the query, the query planner might even select multiple ranges to scan from an index or multiple ranges from different indexes.

How does the query planner decide which index to use and which range of the index to scan? We currently use a restricted form of value propagation in order to determine the range of possible values for columns referenced in the WHERE clause. Using this range information, each index is examined to determine if it is a potential candidate and ranked according to its specificity. In addition to ranking indexes by the column value range information, they are ranked by how well they match the sorting required by the ORDER BY clause. A more detailed description is here: https://www.cockroachlabs.com/blog/index-selection-cockroachdb-2/, but back to the example above, the range information would determine that:

item_id >= 0 AND item_id <= 0 AND name >= 'test' and name <= 'test

Since there are two indexes on the "inventory" table, one index on "name" and another unique index on "item_id" and "name", the latter is selected as the candidate for performing a scan. To perform this scan, we need a start (inclusive) and end key (exclusive). The start key is computed using the SecondaryIndexID of the chosen index, and the constraints on the range information above:

/inventory/SecondaryIndexID/item_id/name

The end key is:

/inventory/SecondaryIndexID/item_id/namf

The "namf" suffix is not a typo: it is an abuse of notation to demonstrate how we calculate the end key: the end key is computed by incrementing the final byte of the start key such that "t" becomes "u".

Our example scan will return two key-value pairs:

/system.descriptor/primary/0/test    -> NULL
/system.descriptor/primary/0/test/id -> <ID>

The first key is the sentinel key, and the value from the second key returned by the scan is the result we need to return as the result of this SQL query.

Index ¶

Constants ¶

View Source
const (
	NoTxnStateStr         = sqlfsm.NoTxnStateStr
	OpenStateStr          = sqlfsm.OpenStateStr
	AbortedStateStr       = sqlfsm.AbortedStateStr
	CommitWaitStateStr    = sqlfsm.CommitWaitStateStr
	InternalErrorStateStr = sqlfsm.InternalErrorStateStr
)

Constants for the String() representation of the session states. Shared with the CLI code which needs to recognize them.

View Source
const (
	// NodelocalFileUploadTable is used internally to identify a COPY initiated by
	// nodelocal upload.
	NodelocalFileUploadTable = "nodelocal_file_upload"
	// UserFileUploadTable is used internally to identify a COPY initiated by
	// userfile upload.
	UserFileUploadTable = "user_file_upload"
)
View Source
const (
	// EnumTypeUserDefined is a user defined enum.
	EnumTypeUserDefined = iota
	// EnumTypeMultiRegion is a multi-region related enum.
	EnumTypeMultiRegion
)
View Source
const (
	// DistributionTypeNone does not distribute a plan across multiple instances.
	DistributionTypeNone = iota
	// DistributionTypeAlways distributes a plan across multiple instances whether
	// it is a system tenant or non-system tenant.
	DistributionTypeAlways
	// DistributionTypeSystemTenantOnly only distributes a plan if it is for a
	// system tenant. Plans on non-system tenants are not distributed.
	DistributionTypeSystemTenantOnly
)
View Source
const (
	MySQL    = "mysql"
	Postgres = "postgres"
)

RDBMS options

View Source
const (
	// RunningStatusWaitingGC is for jobs that are currently in progress and
	// are waiting for the GC interval to expire
	RunningStatusWaitingGC jobs.RunningStatus = "waiting for GC TTL"
	// RunningStatusDeleteOnly is for jobs that are currently waiting on
	// the cluster to converge to seeing the schema element in the DELETE_ONLY
	// state.
	RunningStatusDeleteOnly jobs.RunningStatus = "waiting in DELETE-ONLY"
	// RunningStatusDeleteAndWriteOnly is for jobs that are currently waiting on
	// the cluster to converge to seeing the schema element in the
	// DELETE_AND_WRITE_ONLY state.
	RunningStatusDeleteAndWriteOnly jobs.RunningStatus = "waiting in DELETE-AND-WRITE_ONLY"
	// RunningStatusMerging is for jobs that are currently waiting on
	// the cluster to converge to seeing the schema element in the
	// MERGING state.
	RunningStatusMerging jobs.RunningStatus = "waiting in MERGING"
	// RunningStatusBackfill is for jobs that are currently running a backfill
	// for a schema element.
	RunningStatusBackfill jobs.RunningStatus = "populating schema"
	// RunningStatusValidation is for jobs that are currently validating
	// a schema element.
	RunningStatusValidation jobs.RunningStatus = "validating schema"
)
View Source
const (

	// OmitFKClausesFromCreate will not include any foreign key information in the
	// create statement.
	OmitFKClausesFromCreate shouldOmitFKClausesFromCreate
	// IncludeFkClausesInCreate will include foreign key information in the create
	// statement, and error if a FK cannot be resolved.
	IncludeFkClausesInCreate
	// OmitMissingFKClausesFromCreate will include foreign key information only if they
	// can be resolved. If not, it will ignore those constraints.
	// This is used in the case when showing the create statement for
	// tables stored in backups. Not all relevant tables may have been
	// included in the back up, so some foreign key information may be
	// impossible to retrieve.
	OmitMissingFKClausesFromCreate
)
View Source
const (
	// PgServerVersion is the latest version of postgres that we claim to support.
	PgServerVersion = "13.0.0"
	// PgServerVersionNum is the latest version of postgres that we claim to support in the numeric format of "server_version_num".
	PgServerVersionNum = "130000"
	// PgCompatLocale is the locale string we advertise in `LC_*` session
	// variables. C.UTF-8 is the only locale that is allowed in CREATE DATABASE
	// at the time of writing.
	// See https://www.postgresql.org/docs/14/locale.html
	PgCompatLocale = "C.UTF-8"
)
View Source
const AuthAuditingClusterSettingName = "server.auth_log.sql_sessions.enabled"

AuthAuditingClusterSettingName is the name of the cluster setting for the cluster setting that enables pgwire-level authentication audit logs.

This name is defined here because it is needed in the telemetry counts in SetClusterSetting() and importing pgwire here would create a circular dependency.

View Source
const ConnAuditingClusterSettingName = "server.auth_log.sql_connections.enabled"

ConnAuditingClusterSettingName is the name of the cluster setting for the cluster setting that enables pgwire-level connection audit logs.

This name is defined here because it is needed in the telemetry counts in SetClusterSetting() and importing pgwire here would create a circular dependency.

CrdbInternalName is the name of the crdb_internal schema.

View Source
const DefaultPrimaryRegionClusterSettingName = "sql.defaults.primary_region"

DefaultPrimaryRegionClusterSettingName is the name of the cluster setting that returns

View Source
const ExperimentalDistSQLPlanningClusterSettingName = "sql.defaults.experimental_distsql_planning"

ExperimentalDistSQLPlanningClusterSettingName is the name for the cluster setting that controls experimentalDistSQLPlanningClusterMode below.

View Source
const FailedHashedValue = "unknown"

FailedHashedValue is used as a default return value for when HashForReporting cannot hash a value correctly.

View Source
const GetPGMetadataSQL = `` /* 324-byte string literal not displayed */

GetPGMetadataSQL is a query uses udt_name::regtype instead of data_type column because data_type only says "ARRAY" but does not say which kind of array it is.

View Source
const MaxSQLBytes = 1000

MaxSQLBytes is the maximum length in bytes of SQL statements serialized into a serverpb.Session. Exported for testing.

View Source
const MultitenancyZoneCfgIssueNo = 49854

MultitenancyZoneCfgIssueNo points to the multitenancy zone config issue number.

View Source
const ReorderJoinsLimitClusterSettingName = "sql.defaults.reorder_joins_limit"

ReorderJoinsLimitClusterSettingName is the name of the cluster setting for the maximum number of joins to reorder.

View Source
const RevertTableDefaultBatchSize = 500000

RevertTableDefaultBatchSize is the default batch size for reverting tables. This only needs to be small enough to keep raft/rocks happy -- there is no reply size to worry about. TODO(dt): tune this via experimentation.

View Source
const TemporarySchemaNameForRestorePrefix string = "pg_temp_0_"

TemporarySchemaNameForRestorePrefix is the prefix name of the schema we synthesize during a full cluster restore. All temporary objects being restored are remapped to belong to this schema allowing the reconciliation job to gracefully clean up these objects when it runs.

View Source
const VectorizeClusterSettingName = "sql.defaults.vectorize"

VectorizeClusterSettingName is the name for the cluster setting that controls the VectorizeClusterMode below.

Variables ¶

View Source
var (
	// ErrLimitedResultNotSupported is an error produced by pgwire
	// indicating an unsupported feature of row count limits was attempted.
	ErrLimitedResultNotSupported = unimplemented.NewWithIssue(40195, "multiple active portals not supported")
	// ErrLimitedResultClosed is a sentinel error produced by pgwire
	// indicating the portal should be closed without error.
	ErrLimitedResultClosed = errors.New("row count limit closed")
)
View Source
var (
	MetaSQLExecLatency = metric.Metadata{
		Name:        "sql.exec.latency",
		Help:        "Latency of SQL statement execution",
		Measurement: "Latency",
		Unit:        metric.Unit_NANOSECONDS,
	}
	MetaSQLServiceLatency = metric.Metadata{
		Name:        "sql.service.latency",
		Help:        "Latency of SQL request execution",
		Measurement: "Latency",
		Unit:        metric.Unit_NANOSECONDS,
	}
	MetaSQLOptFallback = metric.Metadata{
		Name:        "sql.optimizer.fallback.count",
		Help:        "Number of statements which the cost-based optimizer was unable to plan",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLOptPlanCacheHits = metric.Metadata{
		Name:        "sql.optimizer.plan_cache.hits",
		Help:        "Number of non-prepared statements for which a cached plan was used",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLOptPlanCacheMisses = metric.Metadata{
		Name:        "sql.optimizer.plan_cache.misses",
		Help:        "Number of non-prepared statements for which a cached plan was not used",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaDistSQLSelect = metric.Metadata{
		Name:        "sql.distsql.select.count",
		Help:        "Number of DistSQL SELECT statements",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaDistSQLExecLatency = metric.Metadata{
		Name:        "sql.distsql.exec.latency",
		Help:        "Latency of DistSQL statement execution",
		Measurement: "Latency",
		Unit:        metric.Unit_NANOSECONDS,
	}
	MetaDistSQLServiceLatency = metric.Metadata{
		Name:        "sql.distsql.service.latency",
		Help:        "Latency of DistSQL request execution",
		Measurement: "Latency",
		Unit:        metric.Unit_NANOSECONDS,
	}
	MetaTxnAbort = metric.Metadata{
		Name:        "sql.txn.abort.count",
		Help:        "Number of SQL transaction abort errors",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaFailure = metric.Metadata{
		Name:        "sql.failure.count",
		Help:        "Number of statements resulting in a planning or runtime error",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLTxnLatency = metric.Metadata{
		Name:        "sql.txn.latency",
		Help:        "Latency of SQL transactions",
		Measurement: "Latency",
		Unit:        metric.Unit_NANOSECONDS,
	}
	MetaSQLTxnsOpen = metric.Metadata{
		Name:        "sql.txns.open",
		Help:        "Number of currently open user SQL transactions",
		Measurement: "Open SQL Transactions",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLActiveQueries = metric.Metadata{
		Name:        "sql.statements.active",
		Help:        "Number of currently active user SQL statements",
		Measurement: "Active Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaFullTableOrIndexScan = metric.Metadata{
		Name:        "sql.full.scan.count",
		Help:        "Number of full table or index scans",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}

	// Below are the metadata for the statement started counters.
	MetaQueryStarted = metric.Metadata{
		Name:        "sql.query.started.count",
		Help:        "Number of SQL queries started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnBeginStarted = metric.Metadata{
		Name:        "sql.txn.begin.started.count",
		Help:        "Number of SQL transaction BEGIN statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnCommitStarted = metric.Metadata{
		Name:        "sql.txn.commit.started.count",
		Help:        "Number of SQL transaction COMMIT statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnRollbackStarted = metric.Metadata{
		Name:        "sql.txn.rollback.started.count",
		Help:        "Number of SQL transaction ROLLBACK statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSelectStarted = metric.Metadata{
		Name:        "sql.select.started.count",
		Help:        "Number of SQL SELECT statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaUpdateStarted = metric.Metadata{
		Name:        "sql.update.started.count",
		Help:        "Number of SQL UPDATE statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaInsertStarted = metric.Metadata{
		Name:        "sql.insert.started.count",
		Help:        "Number of SQL INSERT statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaDeleteStarted = metric.Metadata{
		Name:        "sql.delete.started.count",
		Help:        "Number of SQL DELETE statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSavepointStarted = metric.Metadata{
		Name:        "sql.savepoint.started.count",
		Help:        "Number of SQL SAVEPOINT statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaReleaseSavepointStarted = metric.Metadata{
		Name:        "sql.savepoint.release.started.count",
		Help:        "Number of `RELEASE SAVEPOINT` statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaRollbackToSavepointStarted = metric.Metadata{
		Name:        "sql.savepoint.rollback.started.count",
		Help:        "Number of `ROLLBACK TO SAVEPOINT` statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaRestartSavepointStarted = metric.Metadata{
		Name:        "sql.restart_savepoint.started.count",
		Help:        "Number of `SAVEPOINT cockroach_restart` statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaReleaseRestartSavepointStarted = metric.Metadata{
		Name:        "sql.restart_savepoint.release.started.count",
		Help:        "Number of `RELEASE SAVEPOINT cockroach_restart` statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaRollbackToRestartSavepointStarted = metric.Metadata{
		Name:        "sql.restart_savepoint.rollback.started.count",
		Help:        "Number of `ROLLBACK TO SAVEPOINT cockroach_restart` statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaDdlStarted = metric.Metadata{
		Name:        "sql.ddl.started.count",
		Help:        "Number of SQL DDL statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaCopyStarted = metric.Metadata{
		Name:        "sql.copy.started.count",
		Help:        "Number of COPY SQL statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaMiscStarted = metric.Metadata{
		Name:        "sql.misc.started.count",
		Help:        "Number of other SQL statements started",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}

	// Below are the metadata for the statement executed counters.
	MetaQueryExecuted = metric.Metadata{
		Name:        "sql.query.count",
		Help:        "Number of SQL queries executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnBeginExecuted = metric.Metadata{
		Name:        "sql.txn.begin.count",
		Help:        "Number of SQL transaction BEGIN statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnCommitExecuted = metric.Metadata{
		Name:        "sql.txn.commit.count",
		Help:        "Number of SQL transaction COMMIT statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnRollbackExecuted = metric.Metadata{
		Name:        "sql.txn.rollback.count",
		Help:        "Number of SQL transaction ROLLBACK statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSelectExecuted = metric.Metadata{
		Name:        "sql.select.count",
		Help:        "Number of SQL SELECT statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaUpdateExecuted = metric.Metadata{
		Name:        "sql.update.count",
		Help:        "Number of SQL UPDATE statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaInsertExecuted = metric.Metadata{
		Name:        "sql.insert.count",
		Help:        "Number of SQL INSERT statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaDeleteExecuted = metric.Metadata{
		Name:        "sql.delete.count",
		Help:        "Number of SQL DELETE statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSavepointExecuted = metric.Metadata{
		Name:        "sql.savepoint.count",
		Help:        "Number of SQL SAVEPOINT statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaReleaseSavepointExecuted = metric.Metadata{
		Name:        "sql.savepoint.release.count",
		Help:        "Number of `RELEASE SAVEPOINT` statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaRollbackToSavepointExecuted = metric.Metadata{
		Name:        "sql.savepoint.rollback.count",
		Help:        "Number of `ROLLBACK TO SAVEPOINT` statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaRestartSavepointExecuted = metric.Metadata{
		Name:        "sql.restart_savepoint.count",
		Help:        "Number of `SAVEPOINT cockroach_restart` statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaReleaseRestartSavepointExecuted = metric.Metadata{
		Name:        "sql.restart_savepoint.release.count",
		Help:        "Number of `RELEASE SAVEPOINT cockroach_restart` statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaRollbackToRestartSavepointExecuted = metric.Metadata{
		Name:        "sql.restart_savepoint.rollback.count",
		Help:        "Number of `ROLLBACK TO SAVEPOINT cockroach_restart` statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaDdlExecuted = metric.Metadata{
		Name:        "sql.ddl.count",
		Help:        "Number of SQL DDL statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaCopyExecuted = metric.Metadata{
		Name:        "sql.copy.count",
		Help:        "Number of COPY SQL statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaMiscExecuted = metric.Metadata{
		Name:        "sql.misc.count",
		Help:        "Number of other SQL statements successfully executed",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLStatsMemMaxBytes = metric.Metadata{
		Name:        "sql.stats.mem.max",
		Help:        "Memory usage for fingerprint storage",
		Measurement: "Memory",
		Unit:        metric.Unit_BYTES,
	}
	MetaSQLStatsMemCurBytes = metric.Metadata{
		Name:        "sql.stats.mem.current",
		Help:        "Current memory usage for fingerprint storage",
		Measurement: "Memory",
		Unit:        metric.Unit_BYTES,
	}
	MetaReportedSQLStatsMemMaxBytes = metric.Metadata{
		Name:        "sql.stats.reported.mem.max",
		Help:        "Memory usage for reported fingerprint storage",
		Measurement: "Memory",
		Unit:        metric.Unit_BYTES,
	}
	MetaReportedSQLStatsMemCurBytes = metric.Metadata{
		Name:        "sql.stats.reported.mem.current",
		Help:        "Current memory usage for reported fingerprint storage",
		Measurement: "Memory",
		Unit:        metric.Unit_BYTES,
	}
	MetaDiscardedSQLStats = metric.Metadata{
		Name:        "sql.stats.discarded.current",
		Help:        "Number of fingerprint statistics being discarded",
		Measurement: "Discarded SQL Stats",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLStatsFlushStarted = metric.Metadata{
		Name:        "sql.stats.flush.count",
		Help:        "Number of times SQL Stats are flushed to persistent storage",
		Measurement: "SQL Stats Flush",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLStatsFlushFailure = metric.Metadata{
		Name:        "sql.stats.flush.error",
		Help:        "Number of errors encountered when flushing SQL Stats",
		Measurement: "SQL Stats Flush",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLStatsFlushDuration = metric.Metadata{
		Name:        "sql.stats.flush.duration",
		Help:        "Time took to in nanoseconds to complete SQL Stats flush",
		Measurement: "SQL Stats Flush",
		Unit:        metric.Unit_NANOSECONDS,
	}
	MetaSQLStatsRemovedRows = metric.Metadata{
		Name:        "sql.stats.cleanup.rows_removed",
		Help:        "Number of stale statistics rows that are removed",
		Measurement: "SQL Stats Cleanup",
		Unit:        metric.Unit_COUNT,
	}
	MetaSQLTxnStatsCollectionOverhead = metric.Metadata{
		Name:        "sql.stats.txn_stats_collection.duration",
		Help:        "Time took in nanoseconds to collect transaction stats",
		Measurement: "SQL Transaction Stats Collection Overhead",
		Unit:        metric.Unit_NANOSECONDS,
	}
	MetaTxnRowsWrittenLog = metric.Metadata{
		Name:        "sql.guardrails.transaction_rows_written_log.count",
		Help:        "Number of transactions logged because of transaction_rows_written_log guardrail",
		Measurement: "Logged transactions",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnRowsWrittenErr = metric.Metadata{
		Name:        "sql.guardrails.transaction_rows_written_err.count",
		Help:        "Number of transactions errored because of transaction_rows_written_err guardrail",
		Measurement: "Errored transactions",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnRowsReadLog = metric.Metadata{
		Name:        "sql.guardrails.transaction_rows_read_log.count",
		Help:        "Number of transactions logged because of transaction_rows_read_log guardrail",
		Measurement: "Logged transactions",
		Unit:        metric.Unit_COUNT,
	}
	MetaTxnRowsReadErr = metric.Metadata{
		Name:        "sql.guardrails.transaction_rows_read_err.count",
		Help:        "Number of transactions errored because of transaction_rows_read_err guardrail",
		Measurement: "Errored transactions",
		Unit:        metric.Unit_COUNT,
	}
	MetaFullTableOrIndexScanRejected = metric.Metadata{
		Name:        "sql.guardrails.full_scan_rejected.count",
		Help:        "Number of full table or index scans that have been rejected because of `disallow_full_table_scans` guardrail",
		Measurement: "SQL Statements",
		Unit:        metric.Unit_COUNT,
	}
)

Fully-qualified names for metrics.

View Source
var AllowSessionRevival = settings.RegisterBoolSetting(
	settings.TenantReadOnly,
	"server.user_login.session_revival_token.enabled",
	"if set, the cluster is able to create session revival tokens and use them "+
		"to authenticate a new session",
	false,
)

AllowSessionRevival is true if the cluster is allowed to create session revival tokens and use them to authenticate a session. It is a non-public setting since this is only intended to be used by CockroachDB-serverless at the time of this writing.

View Source
var AlterColTypeInTxnNotSupportedErr = unimplemented.NewWithIssuef(
	49351, "ALTER COLUMN TYPE is not supported inside a transaction")

AlterColTypeInTxnNotSupportedErr is returned when an ALTER COLUMN TYPE is tried in an explicit transaction.

View Source
var ApplyZoneConfigForMultiRegionTableOptionTableAndIndexes = func(
	zc zonepb.ZoneConfig,
	regionConfig multiregion.RegionConfig,
	table catalog.TableDescriptor,
) (bool, zonepb.ZoneConfig, error) {
	localityConfig := *table.GetLocalityConfig()
	localityZoneConfig, err := zoneConfigForMultiRegionTable(
		localityConfig,
		regionConfig,
	)
	if err != nil {
		return false, zonepb.ZoneConfig{}, err
	}

	zc.ClearFieldsOfAllSubzones(zonepb.MultiRegionZoneConfigFields)

	zc.CopyFromZone(*localityZoneConfig, zonepb.MultiRegionZoneConfigFields)

	hasNewSubzones := table.IsLocalityRegionalByRow()
	if hasNewSubzones {
		for _, region := range regionConfig.Regions() {
			subzoneConfig, err := zoneConfigForMultiRegionPartition(region, regionConfig)
			if err != nil {
				return false, zc, err
			}
			for _, idx := range table.NonDropIndexes() {
				zc.SetSubzone(zonepb.Subzone{
					IndexID:       uint32(idx.GetID()),
					PartitionName: string(region),
					Config:        subzoneConfig,
				})
			}
		}
	}
	return hasNewSubzones, zc, nil
}

ApplyZoneConfigForMultiRegionTableOptionTableAndIndexes applies table zone configs on the entire table as well as its indexes, replacing multi-region related zone configuration fields.

View Source
var BoundTxnStateTransitions = fsm.Compile(fsm.Pattern{
	stateOpen{ImplicitTxn: fsm.False}: {

		eventNonRetriableErr{IsCommit: fsm.Any}: {
			Next: stateInternalError{},
			Action: func(args fsm.Args) error {
				ts := args.Extended.(*txnState)
				finishedTxnID := ts.finishSQLTxn()
				ts.setAdvanceInfo(
					skipBatch,
					noRewind,
					txnEvent{eventType: txnRollback, txnID: finishedTxnID},
				)
				return nil
			},
		},
		eventRetriableErr{CanAutoRetry: fsm.Any, IsCommit: fsm.False}: {
			Next: stateInternalError{},
			Action: func(args fsm.Args) error {
				ts := args.Extended.(*txnState)
				finishedTxnID := ts.finishSQLTxn()
				ts.setAdvanceInfo(
					skipBatch,
					noRewind,
					txnEvent{eventType: txnRollback, txnID: finishedTxnID},
				)
				return nil
			},
		},
	},
})

BoundTxnStateTransitions is the state machine used by the InternalExecutor when running SQL inside a higher-level txn. It's a very limited state machine: it doesn't allow starting or finishing txns, auto-retries, etc.

View Source
var ClusterOrganization = settings.RegisterStringSetting(
	settings.TenantWritable,
	"cluster.organization",
	"organization name",
	"",
).WithPublic()

ClusterOrganization is the organization name.

View Source
var ClusterSecret = func() *settings.StringSetting {
	s := settings.RegisterStringSetting(
		settings.TenantWritable,
		"cluster.secret",
		"cluster specific secret",
		"",
	)

	s.SetReportable(false)
	return s
}()

ClusterSecret is a cluster specific secret. This setting is non-reportable.

View Source
var CreatePartitioningCCL = func(
	ctx context.Context,
	st *cluster.Settings,
	evalCtx *tree.EvalContext,
	columnLookupFn func(tree.Name) (catalog.Column, error),
	oldNumImplicitColumns int,
	oldKeyColumnNames []string,
	partBy *tree.PartitionBy,
	allowedNewColumnNames []tree.Name,
	allowImplicitPartitioning bool,
) (newImplicitCols []catalog.Column, newPartitioning catpb.PartitioningDescriptor, err error) {
	return nil, catpb.PartitioningDescriptor{}, sqlerrors.NewCCLRequiredError(errors.New(
		"creating or manipulating partitions requires a CCL binary"))
}

CreatePartitioningCCL is the public hook point for the CCL-licensed partitioning creation code.

View Source
var DefaultPrimaryRegion = settings.RegisterStringSetting(
	settings.TenantWritable,
	DefaultPrimaryRegionClusterSettingName,
	`if not empty, all databases created without a PRIMARY REGION will `+
		`implicitly have the given PRIMARY REGION`,
	"",
).WithPublic()

DefaultPrimaryRegion is a cluster setting that contains the default primary region.

View Source
var DistSQLClusterExecMode = settings.RegisterEnumSetting(
	settings.TenantWritable,
	"sql.defaults.distsql",
	"default distributed SQL execution mode",
	"auto",
	map[int64]string{
		int64(sessiondatapb.DistSQLOff):    "off",
		int64(sessiondatapb.DistSQLAuto):   "auto",
		int64(sessiondatapb.DistSQLOn):     "on",
		int64(sessiondatapb.DistSQLAlways): "always",
	},
).WithPublic()

DistSQLClusterExecMode controls the cluster default for when DistSQL is used.

View Source
var DummyVars = map[string]sessionVar{
	"enable_seqscan": makeDummyBooleanSessionVar(
		"enable_seqscan",
		func(evalCtx *extendedEvalContext) (string, error) {
			return formatBoolAsPostgresSetting(evalCtx.SessionData().EnableSeqScan), nil
		},
		func(m sessionDataMutator, v bool) {
			m.SetEnableSeqScan(v)
		},
		func(sv *settings.Values) string { return "on" },
	),
	"synchronous_commit": makeDummyBooleanSessionVar(
		"synchronous_commit",
		func(evalCtx *extendedEvalContext) (string, error) {
			return formatBoolAsPostgresSetting(evalCtx.SessionData().SynchronousCommit), nil
		},
		func(m sessionDataMutator, v bool) {
			m.SetSynchronousCommit(v)
		},
		func(sv *settings.Values) string { return "on" },
	),
}

DummyVars contains a list of dummy vars we do not support that PostgreSQL does, but are required as an easy fix to make certain tooling/ORMs work. These vars should not affect the correctness of results.

View Source
var FeatureTLSAutoJoinEnabled = settings.RegisterBoolSetting(
	settings.TenantWritable,
	"feature.tls_auto_join.enabled",
	"set to true to enable tls auto join through join tokens, false to disable; default is false",
	false,
)

FeatureTLSAutoJoinEnabled is used to enable and disable the TLS auto-join feature.

View Source
var GetMultiRegionEnumAddValuePlacementCCL = func(
	execCfg *ExecutorConfig, typeDesc *typedesc.Mutable, region tree.Name,
) (tree.AlterTypeAddValue, error) {
	return tree.AlterTypeAddValue{}, sqlerrors.NewCCLRequiredError(
		errors.New("adding regions to a multi-region database requires a CCL binary"),
	)
}

GetMultiRegionEnumAddValuePlacementCCL is the public hook point for the CCL-licensed code to determine the placement for a new region inside a region enum.

View Source
var InitializeMultiRegionMetadataCCL = func(
	ctx context.Context,
	execCfg *ExecutorConfig,
	liveClusterRegions LiveClusterRegions,
	survivalGoal tree.SurvivalGoal,
	primaryRegion catpb.RegionName,
	regions []tree.Name,
	dataPlacement tree.DataPlacement,
) (*multiregion.RegionConfig, error) {
	return nil, sqlerrors.NewCCLRequiredError(
		errors.New("creating multi-region databases requires a CCL binary"),
	)
}

InitializeMultiRegionMetadataCCL is the public hook point for the CCL-licensed multi-region initialization code.

View Source
var NoticesEnabled = settings.RegisterBoolSetting(
	settings.TenantWritable,
	"sql.notices.enabled",
	"enable notices in the server/client protocol being sent",
	true,
).WithPublic()

NoticesEnabled is the cluster setting that allows users to enable notices.

View Source
var PreservedSplitCountMultiple = settings.RegisterIntSetting(
	settings.TenantWritable,
	"sql.truncate.preserved_split_count_multiple",
	"set to non-zero to cause TRUNCATE to preserve range splits from the "+
		"table's indexes. The multiple given will be multiplied with the number of "+
		"nodes in the cluster to produce the number of preserved range splits. This "+
		"can improve performance when truncating a table with significant write traffic.",
	4)

PreservedSplitCountMultiple is the setting that configures the number of split points that we re-create on a table after a truncate. It's scaled by the number of nodes in the cluster.

View Source
var ReorderJoinsLimitClusterValue = settings.RegisterIntSetting(
	settings.TenantWritable,
	ReorderJoinsLimitClusterSettingName,
	"default number of joins to reorder",
	opt.DefaultJoinOrderLimit,
	func(limit int64) error {
		if limit < 0 || limit > opt.MaxReorderJoinsLimit {
			return pgerror.Newf(pgcode.InvalidParameterValue,
				"cannot set %s to a value less than 0 or greater than %v",
				ReorderJoinsLimitClusterSettingName,
				opt.MaxReorderJoinsLimit,
			)
		}
		return nil
	},
).WithPublic()

ReorderJoinsLimitClusterValue controls the cluster default for the maximum number of joins reordered.

View Source
var ReplicaOraclePolicy = replicaoracle.BinPackingChoice

ReplicaOraclePolicy controls which policy the physical planner uses to choose a replica for a given range. It is exported so that it may be overwritten during initialization by CCL code to enable follower reads.

View Source
var SerialNormalizationMode = settings.RegisterEnumSetting(
	settings.TenantWritable,
	"sql.defaults.serial_normalization",
	"default handling of SERIAL in table definitions",
	"rowid",
	map[int64]string{
		int64(sessiondatapb.SerialUsesRowID):              "rowid",
		int64(sessiondatapb.SerialUsesUnorderedRowID):     "unordered_rowid",
		int64(sessiondatapb.SerialUsesVirtualSequences):   "virtual_sequence",
		int64(sessiondatapb.SerialUsesSQLSequences):       "sql_sequence",
		int64(sessiondatapb.SerialUsesCachedSQLSequences): "sql_sequence_cached",
	},
).WithPublic()

SerialNormalizationMode controls how the SERIAL type is interpreted in table definitions.

View Source
var TempObjectCleanupInterval = settings.RegisterDurationSetting(
	settings.TenantWritable,
	"sql.temp_object_cleaner.cleanup_interval",
	"how often to clean up orphaned temporary objects",
	30*time.Minute,
).WithPublic()

TempObjectCleanupInterval is a ClusterSetting controlling how often temporary objects get cleaned up.

View Source
var TempObjectWaitInterval = settings.RegisterDurationSetting(
	settings.TenantWritable,
	"sql.temp_object_cleaner.wait_interval",
	"how long after creation a temporary object will be cleaned up",
	30*time.Minute,
).WithPublic()

TempObjectWaitInterval is a ClusterSetting controlling how long after a creation a temporary object will be cleaned up.

View Source
var TraceStmtThreshold = settings.RegisterDurationSetting(
	settings.TenantWritable,
	"sql.trace.stmt.enable_threshold",
	"duration beyond which all statements are traced (set to 0 to disable). "+
		"This applies to individual statements within a transaction and is therefore "+
		"finer-grained than sql.trace.txn.enable_threshold.",
	0,
).WithPublic()

TraceStmtThreshold is identical to traceTxnThreshold except it applies to individual statements in a transaction. The motivation for this setting is to be able to reduce the noise associated with a larger transaction (e.g. round trips to client).

View Source
var TxnStateTransitions = fsm.Compile(fsm.Pattern{

	stateNoTxn{}: {
		eventTxnStart{fsm.Var("implicitTxn")}: {
			Description: "BEGIN, or before a statement running as an implicit txn",
			Next:        stateOpen{ImplicitTxn: fsm.Var("implicitTxn")},
			Action:      noTxnToOpen,
		},
		eventNonRetriableErr{IsCommit: fsm.Any}: {

			Description: "anything but BEGIN or extended protocol command error",
			Next:        stateNoTxn{},
			Action: func(args fsm.Args) error {
				ts := args.Extended.(*txnState)
				ts.setAdvanceInfo(skipBatch, noRewind, txnEvent{eventType: noEvent})
				return nil
			},
		},
	},

	stateOpen{ImplicitTxn: fsm.Any}: {
		eventTxnFinishCommitted{}: {
			Description: "COMMIT, or after a statement running as an implicit txn",
			Next:        stateNoTxn{},
			Action: func(args fsm.Args) error {

				return args.Extended.(*txnState).finishTxn(txnCommit)
			},
		},
		eventTxnFinishAborted{}: {
			Description: "ROLLBACK, or after a statement running as an implicit txn fails",
			Next:        stateNoTxn{},
			Action: func(args fsm.Args) error {

				return args.Extended.(*txnState).finishTxn(txnRollback)
			},
		},

		eventRetriableErr{CanAutoRetry: fsm.False, IsCommit: fsm.True}: {
			Description: "Retriable err on COMMIT",
			Next:        stateNoTxn{},
			Action:      cleanupAndFinishOnError,
		},
		eventNonRetriableErr{IsCommit: fsm.True}: {
			Next:   stateNoTxn{},
			Action: cleanupAndFinishOnError,
		},
	},
	stateOpen{ImplicitTxn: fsm.Var("implicitTxn")}: {

		eventRetriableErr{CanAutoRetry: fsm.True, IsCommit: fsm.Any}: {

			Description: "Retriable err; will auto-retry",
			Next:        stateOpen{ImplicitTxn: fsm.Var("implicitTxn")},
			Action:      prepareTxnForRetryWithRewind,
		},
	},

	stateOpen{ImplicitTxn: fsm.True}: {
		eventRetriableErr{CanAutoRetry: fsm.False, IsCommit: fsm.False}: {
			Next:   stateNoTxn{},
			Action: cleanupAndFinishOnError,
		},
		eventNonRetriableErr{IsCommit: fsm.False}: {
			Next:   stateNoTxn{},
			Action: cleanupAndFinishOnError,
		},
		eventTxnUpgradeToExplicit{}: {
			Next: stateOpen{ImplicitTxn: fsm.False},
			Action: func(args fsm.Args) error {
				args.Extended.(*txnState).setAdvanceInfo(
					advanceOne,
					noRewind,
					txnEvent{eventType: noEvent},
				)
				return nil
			},
		},
	},

	stateOpen{ImplicitTxn: fsm.False}: {
		eventNonRetriableErr{IsCommit: fsm.False}: {
			Next: stateAborted{},
			Action: func(args fsm.Args) error {
				ts := args.Extended.(*txnState)
				ts.setAdvanceInfo(skipBatch, noRewind, txnEvent{eventType: noEvent})
				return nil
			},
		},

		eventTxnRestart{}: {
			Description: "ROLLBACK TO SAVEPOINT cockroach_restart",
			Next:        stateOpen{ImplicitTxn: fsm.False},
			Action:      prepareTxnForRetry,
		},
		eventRetriableErr{CanAutoRetry: fsm.False, IsCommit: fsm.False}: {
			Next: stateAborted{},
			Action: func(args fsm.Args) error {
				args.Extended.(*txnState).setAdvanceInfo(
					skipBatch,
					noRewind,
					txnEvent{eventType: noEvent},
				)
				return nil
			},
		},
		eventTxnReleased{}: {
			Description: "RELEASE SAVEPOINT cockroach_restart",
			Next:        stateCommitWait{},
			Action: func(args fsm.Args) error {
				ts := args.Extended.(*txnState)
				ts.mu.Lock()
				txnID := ts.mu.txn.ID()
				ts.mu.Unlock()
				ts.setAdvanceInfo(
					advanceOne,
					noRewind,
					txnEvent{eventType: txnCommit, txnID: txnID},
				)
				return nil
			},
		},
	},

	stateAborted{}: {
		eventTxnFinishAborted{}: {
			Description: "ROLLBACK",
			Next:        stateNoTxn{},
			Action: func(args fsm.Args) error {
				ts := args.Extended.(*txnState)
				ts.txnAbortCount.Inc(1)

				return ts.finishTxn(txnRollback)
			},
		},

		eventNonRetriableErr{IsCommit: fsm.False}: {

			Description: "any other statement",
			Next:        stateAborted{},
			Action: func(args fsm.Args) error {
				args.Extended.(*txnState).setAdvanceInfo(
					skipBatch,
					noRewind,
					txnEvent{eventType: noEvent},
				)
				return nil
			},
		},

		eventNonRetriableErr{IsCommit: fsm.True}: {

			Description: "ConnExecutor closing",
			Next:        stateAborted{},
			Action:      cleanupAndFinishOnError,
		},

		eventSavepointRollback{}: {
			Description: "ROLLBACK TO SAVEPOINT (not cockroach_restart) success",
			Next:        stateOpen{ImplicitTxn: fsm.False},
			Action: func(args fsm.Args) error {
				args.Extended.(*txnState).setAdvanceInfo(
					advanceOne,
					noRewind,
					txnEvent{eventType: noEvent},
				)
				return nil
			},
		},

		eventRetriableErr{CanAutoRetry: fsm.Any, IsCommit: fsm.Any}: {

			Description: "ROLLBACK TO SAVEPOINT (not cockroach_restart) failed because txn needs restart",
			Next:        stateAborted{},
			Action: func(args fsm.Args) error {
				args.Extended.(*txnState).setAdvanceInfo(
					skipBatch,
					noRewind,
					txnEvent{eventType: noEvent},
				)
				return nil
			},
		},

		eventTxnRestart{}: {
			Description: "ROLLBACK TO SAVEPOINT cockroach_restart",
			Next:        stateOpen{ImplicitTxn: fsm.False},
			Action:      prepareTxnForRetry,
		},
	},

	stateCommitWait{}: {
		eventTxnFinishCommitted{}: {
			Description: "COMMIT",
			Next:        stateNoTxn{},
			Action: func(args fsm.Args) error {

				return args.Extended.(*txnState).finishTxn(noEvent)
			},
		},
		eventNonRetriableErr{IsCommit: fsm.Any}: {

			Description: "any other statement",
			Next:        stateCommitWait{},
			Action: func(args fsm.Args) error {
				args.Extended.(*txnState).setAdvanceInfo(
					skipBatch,
					noRewind,
					txnEvent{eventType: noEvent},
				)
				return nil
			},
		},
	},
})

TxnStateTransitions describe the transitions used by a connExecutor's fsm.Machine. Args.Extended is a txnState, which is muted by the Actions.

This state machine accepts the eventNonRetriableErr{IsCommit: fsm.True} in all states. This contract is in place to support the cleanup of connExecutor -> this event can always be sent when the connExecutor is tearing down.

NOTE: The Args.Ctx passed to the actions is the connExecutor's context. While we are inside a SQL txn, the txn's ctx should be used for operations (i.e txnState.Ctx, which is a child ctx). This is so because transitions that move in and out of transactions need to have access to both contexts.

View Source
var UnsupportedVars = func(ss ...string) map[string]struct{} {
	m := map[string]struct{}{}
	for _, s := range ss {
		m[s] = struct{}{}
	}
	return m
}(

	"optimize_bounded_sort",

	"array_nulls",
	"backend_flush_after",

	"commit_delay",
	"commit_siblings",
	"constraint_exclusion",
	"cpu_index_tuple_cost",
	"cpu_operator_cost",
	"cpu_tuple_cost",
	"cursor_tuple_fraction",
	"deadlock_timeout",
	"debug_deadlocks",
	"debug_pretty_print",
	"debug_print_parse",
	"debug_print_plan",
	"debug_print_rewritten",
	"default_statistics_target",
	"default_text_search_config",
	"default_transaction_deferrable",

	"dynamic_library_path",
	"effective_cache_size",
	"enable_bitmapscan",
	"enable_gathermerge",
	"enable_hashagg",
	"enable_hashjoin",
	"enable_indexonlyscan",
	"enable_indexscan",
	"enable_material",
	"enable_mergejoin",
	"enable_nestloop",

	"enable_sort",
	"enable_tidscan",

	"exit_on_error",

	"force_parallel_mode",
	"from_collapse_limit",
	"geqo",
	"geqo_effort",
	"geqo_generations",
	"geqo_pool_size",
	"geqo_seed",
	"geqo_selection_bias",
	"geqo_threshold",
	"gin_fuzzy_search_limit",
	"gin_pending_list_limit",

	"ignore_checksum_failure",
	"join_collapse_limit",

	"lo_compat_privileges",
	"local_preload_libraries",

	"log_btree_build_stats",
	"log_duration",
	"log_error_verbosity",
	"log_executor_stats",
	"log_lock_waits",
	"log_min_duration_statement",
	"log_min_error_statement",
	"log_min_messages",
	"log_parser_stats",
	"log_planner_stats",
	"log_replication_commands",
	"log_statement",
	"log_statement_stats",
	"log_temp_files",
	"maintenance_work_mem",
	"max_parallel_workers",
	"max_parallel_workers_per_gather",
	"max_stack_depth",
	"min_parallel_index_scan_size",
	"min_parallel_table_scan_size",
	"operator_precedence_warning",
	"parallel_setup_cost",
	"parallel_tuple_cost",

	"quote_all_identifiers",
	"random_page_cost",
	"replacement_sort_tuples",

	"seed",
	"seq_page_cost",

	"session_preload_libraries",
	"session_replication_role",

	"tcp_keepalives_count",
	"tcp_keepalives_idle",
	"tcp_keepalives_interval",
	"temp_buffers",
	"temp_file_limit",
	"temp_tablespaces",
	"timezone_abbreviations",
	"trace_lock_oidmin",
	"trace_lock_table",
	"trace_locks",
	"trace_lwlocks",
	"trace_notify",
	"trace_sort",
	"trace_syncscan",
	"trace_userlocks",
	"track_activities",
	"track_counts",
	"track_functions",
	"track_io_timing",
	"transaction_deferrable",

	"transform_null_equals",
	"update_process_title",
	"vacuum_cost_delay",
	"vacuum_cost_limit",
	"vacuum_cost_page_dirty",
	"vacuum_cost_page_hit",
	"vacuum_cost_page_miss",
	"vacuum_freeze_min_age",
	"vacuum_freeze_table_age",
	"vacuum_multixact_freeze_min_age",
	"vacuum_multixact_freeze_table_age",
	"wal_compression",
	"wal_consistency_checking",
	"wal_debug",
	"work_mem",
	"xmlbinary",

	"zero_damaged_pages",
)

UnsupportedVars contains the set of PostgreSQL session variables and client parameters that are not supported in CockroachDB. These are used to produce error messages and telemetry.

View Source
var VectorizeClusterMode = settings.RegisterEnumSetting(
	settings.TenantWritable,
	VectorizeClusterSettingName,
	"default vectorize mode",
	"on",
	map[int64]string{
		int64(sessiondatapb.VectorizeUnset):              "on",
		int64(sessiondatapb.VectorizeOn):                 "on",
		int64(sessiondatapb.VectorizeExperimentalAlways): "experimental_always",
		int64(sessiondatapb.VectorizeOff):                "off",
	},
).WithPublic()

VectorizeClusterMode controls the cluster default for when automatic vectorization is enabled.

Functions ¶

func ActivateTenant ¶

func ActivateTenant(ctx context.Context, execCfg *ExecutorConfig, txn *kv.Txn, tenID uint64) error

ActivateTenant marks a tenant active.

func AddPlanHook ¶

func AddPlanHook(name string, fn planHookFn)

AddPlanHook adds a hook used to short-circuit creating a planNode from a tree.Statement. If the func returned by the hook is non-nil, it is used to construct a planNode that runs that func in a goroutine during Start.

See PlanHookState comments for information about why plan hooks are needed.

func AlterColumnType ¶

func AlterColumnType(
	ctx context.Context,
	tableDesc *tabledesc.Mutable,
	col catalog.Column,
	t *tree.AlterTableAlterColumnType,
	params runParams,
	cmds tree.AlterTableCmds,
	tn *tree.TableName,
) error

AlterColumnType takes an AlterTableAlterColumnType, determines which conversion to use and applies the type conversion.

func ApplyZoneConfigForMultiRegionTable ¶

func ApplyZoneConfigForMultiRegionTable(
	ctx context.Context,
	txn *kv.Txn,
	execCfg *ExecutorConfig,
	regionConfig multiregion.RegionConfig,
	table catalog.TableDescriptor,
	opts ...applyZoneConfigForMultiRegionTableOption,
) error

ApplyZoneConfigForMultiRegionTable applies zone config settings based on the options provided.

func ApplyZoneConfigFromDatabaseRegionConfig ¶

func ApplyZoneConfigFromDatabaseRegionConfig(
	ctx context.Context,
	dbID descpb.ID,
	regionConfig multiregion.RegionConfig,
	txn *kv.Txn,
	execConfig *ExecutorConfig,
) error

ApplyZoneConfigFromDatabaseRegionConfig applies a zone configuration to the database using the information in the supplied RegionConfig.

func CheckClusterRegionIsLive ¶

func CheckClusterRegionIsLive(
	liveClusterRegions LiveClusterRegions, region catpb.RegionName,
) error

CheckClusterRegionIsLive checks whether a region supplied is one of the currently active cluster regions.

func CheckSessionVariableValueValid ¶

func CheckSessionVariableValueValid(
	ctx context.Context, settings *cluster.Settings, varName, varValue string,
) error

CheckSessionVariableValueValid returns an error if the value is not valid for the given variable. It also returns an error if there is no variable with the given name or if the variable is not configurable.

func ClearPlanHooks ¶

func ClearPlanHooks()

ClearPlanHooks is used by tests to clear out any mocked out plan hooks that were registered.

func ClearTableDataInChunks ¶

func ClearTableDataInChunks(
	ctx context.Context,
	db *kv.DB,
	codec keys.SQLCodec,
	sv *settings.Values,
	tableDesc catalog.TableDescriptor,
	traceKV bool,
) error

ClearTableDataInChunks truncates the data of a table in chunks. It deletes a range of data for the table, which includes the PK and all indexes. The table has already been marked for deletion and has been purged from the descriptor cache on all nodes.

TODO(vivek): No node is reading/writing data on the table at this stage, therefore the entire table can be deleted with no concern for conflicts (we can even eliminate the need to use a transaction for each chunk at a later stage if it proves inefficient).

func ClusterIsInternal ¶

func ClusterIsInternal(sv *settings.Values) bool

ClusterIsInternal returns true if the cluster organization contains "Cockroach Labs", indicating an internal cluster.

func CopyInFileStmt ¶

func CopyInFileStmt(destination, schema, table string) string

CopyInFileStmt creates a COPY FROM statement which can be used to upload files, and be prepared with Tx.Prepare().

func CreateEnumArrayTypeDesc ¶

func CreateEnumArrayTypeDesc(
	params runParams,
	typDesc *typedesc.Mutable,
	db catalog.DatabaseDescriptor,
	schemaID descpb.ID,
	id descpb.ID,
	arrayTypeName string,
) (*typedesc.Mutable, error)

CreateEnumArrayTypeDesc creates a type descriptor for the array of the given enum.

func CreateEnumTypeDesc ¶

func CreateEnumTypeDesc(
	params runParams,
	id descpb.ID,
	enumLabels tree.EnumValueList,
	dbDesc catalog.DatabaseDescriptor,
	schema catalog.SchemaDescriptor,
	typeName *tree.TypeName,
	enumType EnumType,
) (*typedesc.Mutable, error)

CreateEnumTypeDesc creates a new enum type descriptor.

func CreateGCJobRecord ¶

func CreateGCJobRecord(
	originalDescription string, username security.SQLUsername, details jobspb.SchemaChangeGCDetails,
) jobs.Record

CreateGCJobRecord creates the job record for a GC job, setting some properties which are common for all GC jobs.

func CreatePartitioning ¶

func CreatePartitioning(
	ctx context.Context,
	st *cluster.Settings,
	evalCtx *tree.EvalContext,
	tableDesc catalog.TableDescriptor,
	indexDesc descpb.IndexDescriptor,
	partBy *tree.PartitionBy,
	allowedNewColumnNames []tree.Name,
	allowImplicitPartitioning bool,
) (newImplicitCols []catalog.Column, newPartitioning catpb.PartitioningDescriptor, err error)

CreatePartitioning returns a set of implicit columns and a new partitioning descriptor to build an index with partitioning fields populated to align with the tree.PartitionBy clause.

func CreateRowLevelTTLScheduledJob ¶

func CreateRowLevelTTLScheduledJob(
	ctx context.Context,
	execCfg *ExecutorConfig,
	txn *kv.Txn,
	owner security.SQLUsername,
	tblID descpb.ID,
	ttl *catpb.RowLevelTTL,
) (*jobs.ScheduledJob, error)

CreateRowLevelTTLScheduledJob creates a new row-level TTL schedule.

func CreateSchemaDescriptorWithPrivileges ¶

func CreateSchemaDescriptorWithPrivileges(
	ctx context.Context,
	kvDB *kv.DB,
	codec keys.SQLCodec,
	db catalog.DatabaseDescriptor,
	schemaName string,
	user, owner security.SQLUsername,
	allocateID bool,
) (*schemadesc.Mutable, *catpb.PrivilegeDescriptor, error)

CreateSchemaDescriptorWithPrivileges creates a new schema descriptor with the provided name and privileges.

func CreateTenantRecord ¶

func CreateTenantRecord(
	ctx context.Context, execCfg *ExecutorConfig, txn *kv.Txn, info *descpb.TenantInfoWithUsage,
) error

CreateTenantRecord creates a tenant in system.tenants and installs an initial span config (in system.span_configurations) for it. It also initializes the usage data in system.tenant_usage if info.Usage is set.

func CreateTestTableDescriptor ¶

func CreateTestTableDescriptor(
	ctx context.Context, parentID, id descpb.ID, schema string, privileges *catpb.PrivilegeDescriptor,
) (*tabledesc.Mutable, error)

CreateTestTableDescriptor converts a SQL string to a table for test purposes. Will fail on complex tables where that operation requires e.g. looking up other tables.

func CreateUserDefinedSchemaDescriptor ¶

func CreateUserDefinedSchemaDescriptor(
	ctx context.Context,
	sessionData *sessiondata.SessionData,
	n *tree.CreateSchema,
	txn *kv.Txn,
	descriptors *descs.Collection,
	execCfg *ExecutorConfig,
	db catalog.DatabaseDescriptor,
	allocateID bool,
) (*schemadesc.Mutable, *catpb.PrivilegeDescriptor, error)

CreateUserDefinedSchemaDescriptor constructs a mutable schema descriptor.

func DeleteSchedule ¶

func DeleteSchedule(
	ctx context.Context, execCfg *ExecutorConfig, txn *kv.Txn, scheduleID int64,
) error

DeleteSchedule deletes specified schedule.

func DeleteTableDescAndZoneConfig ¶

func DeleteTableDescAndZoneConfig(
	ctx context.Context,
	db *kv.DB,
	settings *cluster.Settings,
	codec keys.SQLCodec,
	tableDesc catalog.TableDescriptor,
) error

DeleteTableDescAndZoneConfig removes a table's descriptor and zone config from the KV database.

func DescsTxn ¶

func DescsTxn(
	ctx context.Context,
	execCfg *ExecutorConfig,
	f func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error,
) error

DescsTxn is a convenient method for running a transaction on descriptors when you have an ExecutorConfig.

func GCTenantSync ¶

func GCTenantSync(ctx context.Context, execCfg *ExecutorConfig, info *descpb.TenantInfo) error

GCTenantSync clears the tenant's data and removes its record.

func GenerateSubzoneSpans ¶

func GenerateSubzoneSpans(
	st *cluster.Settings,
	clusterID uuid.UUID,
	codec keys.SQLCodec,
	tableDesc catalog.TableDescriptor,
	subzones []zonepb.Subzone,
	hasNewSubzones bool,
) ([]zonepb.SubzoneSpan, error)

GenerateSubzoneSpans constructs from a TableDescriptor the entries mapping zone config spans to subzones for use in the SubzoneSpans field of zonepb.ZoneConfig. SubzoneSpans controls which splits are created, so only the spans corresponding to entries in subzones are returned.

Zone configs target indexes and partitions via `subzones`, which are attached to a table-scoped row in `system.zones`. Each subzone represents one index (primary or secondary) or one partition (or subpartition) and contains the usual zone config constraints. They are saved to `system.zones` sparsely (only when set by a user) and are the most specific entry in the normal cluster-default/database/table/subzone config hierarchy.

Each index and partition can be mapped to spans in the keyspace. Indexes and range partitions each map to one span, while each list partition maps to one or more spans. Each partition span is contained by some index span and each subpartition span is contained by one of its parent partition's spans. The spans for a given level of a range partitioning (corresponding to one `PARTITION BY` in sql or one `PartitionDescriptor`) are disjoint, but the spans for a given level of a list partitioning may overlap if DEFAULT is used. A list partitioning which includes both (1, DEFAULT) and (1, 2) will overlap with the latter getting precedence in the zone config hierarchy. NB: In a valid PartitionDescriptor, no partitions with the same number of DEFAULTs will overlap (this property is used by `indexCoveringsForPartitioning`).

These subzone spans are kept denormalized to the relevant `system.zone` row for performance. Given a TableDescriptor, the spans for every index/partition/subpartition are created, filtered out if they don't have a config set for them, and precedence applied (via `OverlapCoveringMerge`) to produce a set of non-overlapping spans, which each map to a subzone. There may be "holes" (uncovered spans) in this set.

The returned spans are returned in exactly the format required by `system.zones`. They must be sorted and non-overlapping. Each contains an IndexID, which maps to one of the input `subzones` by indexing into the slice. As space optimizations, all `Key`s and `EndKey`s of `SubzoneSpan` omit the common prefix (the encoded table ID) and if `EndKey` is equal to `Key.PrefixEnd()` it is omitted.

This function has tests in the partitionccl package.

TODO(benesch): remove the hasNewSubzones parameter when a statement to clear all subzones at once is introduced.

func GetHydratedZoneConfigForDatabase ¶

func GetHydratedZoneConfigForDatabase(
	ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, id descpb.ID,
) (*zonepb.ZoneConfig, error)

GetHydratedZoneConfigForDatabase returns a fully hydrated zone config for a given database ID.

func GetHydratedZoneConfigForNamedZone ¶

func GetHydratedZoneConfigForNamedZone(
	ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, zoneName zonepb.NamedZone,
) (*zonepb.ZoneConfig, error)

GetHydratedZoneConfigForNamedZone returns a zone config for the given named zone. Any missing fields are filled through the RANGE DEFAULT zone config.

func GetHydratedZoneConfigForTable ¶

func GetHydratedZoneConfigForTable(
	ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, id descpb.ID,
) (*zonepb.ZoneConfig, error)

GetHydratedZoneConfigForTable returns a fully hydrated zone config for a given table ID.

func GetSequenceDescFromIdentifier ¶

func GetSequenceDescFromIdentifier(
	ctx context.Context, sc resolver.SchemaResolver, seqIdentifier seqexpr.SeqIdentifier,
) (*tabledesc.Mutable, error)

GetSequenceDescFromIdentifier resolves the sequence descriptor for the given sequence identifier.

func GetTenantRecord ¶

func GetTenantRecord(
	ctx context.Context, execCfg *ExecutorConfig, txn *kv.Txn, tenID uint64,
) (*descpb.TenantInfo, error)

GetTenantRecord retrieves a tenant in system.tenants.

func GetUserSessionInitInfo ¶

func GetUserSessionInitInfo(
	ctx context.Context,
	execCfg *ExecutorConfig,
	ie *InternalExecutor,
	username security.SQLUsername,
	databaseName string,
) (
	exists bool,
	canLoginSQL bool,
	canLoginDBConsole bool,
	isSuperuser bool,
	defaultSettings []sessioninit.SettingsCacheEntry,
	pwRetrieveFn func(ctx context.Context) (expired bool, hashedPassword security.PasswordHash, err error),
	err error,
)

GetUserSessionInitInfo determines if the given user exists and also returns a password retrieval function, other authentication-related information, and default session variable settings that are to be applied before a SQL session is created.

The caller is responsible for normalizing the username. (CockroachDB has case-insensitive usernames, unlike PostgreSQL.)

The function is tolerant of unavailable clusters (or unavailable system database) as follows:

  • if the user is root, the user is reported to exist immediately without querying system.users at all. The password retrieval is delayed until actually needed by the authentication method. This way, if the client presents a valid TLS certificate the password is not even needed at all. This is useful for e.g. `cockroach node status`.

    If root is forced to use a password (e.g. logging in onto the UI) then a user login timeout greater than 5 seconds is also ignored. This ensures that root has a modicum of comfort logging into an unavailable cluster.

    TODO(knz): this does not yet quite work because even if the pw auth on the UI succeeds writing to system.web_sessions will still stall on an unavailable cluster and prevent root from logging in.

  • if the user is another user than root, then the function fails after a timeout instead of blocking. The timeout is configurable via the cluster setting server.user_login.timeout. Note that this is a single timeout for looking up the password, role options, and default session variable settings.
  • there is a cache for the the information from system.users, system.role_options, and system.database_role_settings. As long as the lookup succeeded before and there haven't been any CREATE/ALTER/DROP ROLE commands since, then the cache is used without a KV lookup.

func GetZoneConfigInTxn ¶

func GetZoneConfigInTxn(
	ctx context.Context,
	txn *kv.Txn,
	codec keys.SQLCodec,
	id descpb.ID,
	index catalog.Index,
	partition string,
	getInheritedDefault bool,
) (descpb.ID, *zonepb.ZoneConfig, *zonepb.Subzone, error)

GetZoneConfigInTxn looks up the zone and subzone for the specified object ID, index, and partition. See the documentation on getZoneConfig for information about the getInheritedDefault parameter.

Unlike ZoneConfigHook, GetZoneConfigInTxn does not used a cached system config. Instead, it uses the provided txn to make transactionally consistent KV lookups.

func HashForReporting ¶

func HashForReporting(secret, appName string) string

HashForReporting 1-way hashes values for use in stat reporting. The secret should be the cluster.secret setting.

func InsertEventRecord ¶

func InsertEventRecord(
	ctx context.Context,
	ex *InternalExecutor,
	txn *kv.Txn,
	reportingID int32,
	dst LogEventDestination,
	targetID int32,
	info eventpb.EventPayload,
) error

InsertEventRecord inserts a single event into the event log as part of the provided transaction, using the provided internal executor.

This converts to a call to insertEventRecords() with just 1 entry.

func IsConstraintError ¶

func IsConstraintError(err error) bool

IsConstraintError returns true if the error is considered as an error introduced by the user. For example a constraint violation.

func IsCustomOptionSessionVariable ¶

func IsCustomOptionSessionVariable(varName string) bool

IsCustomOptionSessionVariable returns whether the given varName is a custom session variable.

func IsOwner ¶

func IsOwner(desc catalog.Descriptor, role security.SQLUsername) bool

IsOwner returns if the role has ownership on the descriptor.

func IsPermanentSchemaChangeError ¶

func IsPermanentSchemaChangeError(err error) bool

IsPermanentSchemaChangeError returns true if the error results in a permanent failure of a schema change. This function is a allowlist instead of a blocklist: only known safe errors are confirmed to not be permanent errors. Anything unknown is assumed to be permanent.

func IsSessionVariableConfigurable ¶

func IsSessionVariableConfigurable(varName string) (exists, configurable bool)

IsSessionVariableConfigurable returns true iff there is a session variable with the given name and it is settable by a client (e.g. in pgwire).

func JobSchedulerEnv ¶

func JobSchedulerEnv(execCfg *ExecutorConfig) scheduledjobs.JobSchedulerEnv

JobSchedulerEnv returns JobSchedulerEnv.

func LogEventForJobs ¶

func LogEventForJobs(
	ctx context.Context,
	execCfg *ExecutorConfig,
	txn *kv.Txn,
	event eventpb.EventPayload,
	jobID int64,
	payload jobspb.Payload,
	user security.SQLUsername,
	status jobs.Status,
) error

LogEventForJobs emits a cluster event in the context of a job.

func MakeSequenceKeyVal ¶

func MakeSequenceKeyVal(
	codec keys.SQLCodec, sequence catalog.TableDescriptor, newVal int64, isCalled bool,
) ([]byte, int64, error)

MakeSequenceKeyVal returns the key and value of a sequence being set with newVal.

func MaybeUpgradeStoredPasswordHash ¶

func MaybeUpgradeStoredPasswordHash(
	ctx context.Context,
	execCfg *ExecutorConfig,
	username security.SQLUsername,
	cleartext string,
	currentHash security.PasswordHash,
)

MaybeUpgradeStoredPasswordHash attempts to convert a stored hash that was encoded using crdb-bcrypt, to the SCRAM-SHA-256 format.

This auto-conversion is a CockroachDB-specific feature, which pushes clusters upgraded from a previous version into using SCRAM-SHA-256.

The caller is responsible for ensuring this function is only called after a successful authentication, that is, the provided cleartext password is known to match the previously-encoded prevHash.

func MemberOfWithAdminOption ¶

func MemberOfWithAdminOption(
	ctx context.Context,
	execCfg *ExecutorConfig,
	ie sqlutil.InternalExecutor,
	descsCol *descs.Collection,
	txn *kv.Txn,
	member security.SQLUsername,
) (map[security.SQLUsername]bool, error)

MemberOfWithAdminOption looks up all the roles 'member' belongs to (direct and indirect) and returns a map of "role" -> "isAdmin". The "isAdmin" flag applies to both direct and indirect members. Requires a valid transaction to be open.

func NewFakeSessionData ¶

func NewFakeSessionData(sv *settings.Values) *sessiondata.SessionData

NewFakeSessionData returns "fake" session data for use in internal queries that are not run on behalf of a user session, such as those run during the steps of background jobs and schema changes.

func NewInternalPlanner ¶

func NewInternalPlanner(
	opName string,
	txn *kv.Txn,
	user security.SQLUsername,
	memMetrics *MemoryMetrics,
	execCfg *ExecutorConfig,
	sessionData sessiondatapb.SessionData,
	opts ...InternalPlannerParamsOption,
) (interface{}, func())

NewInternalPlanner is an exported version of newInternalPlanner. It returns an interface{} so it can be used outside of the sql package.

func NewRowMetrics ¶

func NewRowMetrics(internal bool) row.Metrics

NewRowMetrics creates a row.Metrics struct for either internal or user queries.

func NewSchemaChangerEventLogger ¶

func NewSchemaChangerEventLogger(
	txn *kv.Txn, execCfg *ExecutorConfig, depth int,
) scexec.EventLogger

NewSchemaChangerEventLogger returns a scexec.EventLogger implementation.

func NewSequenceTableDesc ¶

func NewSequenceTableDesc(
	ctx context.Context,
	p *planner,
	settings *clustersettings.Settings,
	sequenceName string,
	sequenceOptions tree.SequenceOptions,
	parentID descpb.ID,
	schemaID descpb.ID,
	id descpb.ID,
	creationTime hlc.Timestamp,
	privileges *catpb.PrivilegeDescriptor,
	persistence tree.Persistence,
	isMultiRegion bool,
) (*tabledesc.Mutable, error)

NewSequenceTableDesc creates a sequence descriptor.

func NewTableDesc ¶

func NewTableDesc(
	ctx context.Context,
	txn *kv.Txn,
	vt resolver.SchemaResolver,
	st *cluster.Settings,
	n *tree.CreateTable,
	db catalog.DatabaseDescriptor,
	sc catalog.SchemaDescriptor,
	id descpb.ID,
	regionConfig *multiregion.RegionConfig,
	creationTime hlc.Timestamp,
	privileges *catpb.PrivilegeDescriptor,
	affected map[descpb.ID]*tabledesc.Mutable,
	semaCtx *tree.SemaContext,
	evalCtx *tree.EvalContext,
	sessionData *sessiondata.SessionData,
	persistence tree.Persistence,
	inOpts ...NewTableDescOption,
) (*tabledesc.Mutable, error)

NewTableDesc creates a table descriptor from a CreateTable statement.

txn and vt can be nil if the table to be created does not contain references to other tables (e.g. foreign keys). This is useful at bootstrap when creating descriptors for virtual tables.

parentID refers to the databaseID under which the descriptor is being created and parentSchemaID refers to the schemaID of the schema under which the descriptor is being created.

evalCtx can be nil if the table to be created has no default expression for any of the columns and no partitioning expression.

semaCtx can be nil if the table to be created has no default expression on any of the columns and no check constraints.

regionConfig indicates if the table is being created in a multi-region db. A non-nil regionConfig represents the region configuration of a multi-region db. A nil regionConfig means current db is not multi-regional.

The caller must also ensure that the SchemaResolver is configured to bypass caching and enable visibility of just-added descriptors. This is used to resolve sequence and FK dependencies. Also see the comment at the start of ResolveFK().

If the table definition *may* use the SERIAL type, the caller is also responsible for processing serial types using processSerialLikeInColumnDef() on every column definition, and creating the necessary sequences in KV before calling NewTableDesc().

func NumRangesInSpanContainedBy ¶

func NumRangesInSpanContainedBy(
	ctx context.Context,
	db *kv.DB,
	distSQLPlanner *DistSQLPlanner,
	outerSpan roachpb.Span,
	containedBy []roachpb.Span,
) (total, inContainedBy int, _ error)

NumRangesInSpanContainedBy returns the number of ranges that covers a span and how many of those ranged are wholly contained in containedBy.

It operates entirely on the current goroutine and is thus able to reuse an existing kv.Txn safely.

func PlanAndRunCTAS ¶

func PlanAndRunCTAS(
	ctx context.Context,
	dsp *DistSQLPlanner,
	planner *planner,
	txn *kv.Txn,
	isLocal bool,
	in planMaybePhysical,
	out execinfrapb.ProcessorCoreUnion,
	recv *DistSQLReceiver,
)

PlanAndRunCTAS plans and runs the CREATE TABLE AS command.

func RemoveIndexZoneConfigs ¶

func RemoveIndexZoneConfigs(
	ctx context.Context,
	txn *kv.Txn,
	execCfg *ExecutorConfig,
	tableDesc catalog.TableDescriptor,
	indexIDs []uint32,
) error

RemoveIndexZoneConfigs removes the zone configurations for some indexes being dropped. It is a no-op if there is no zone configuration, there's no index zone configs to be dropped, or it is run on behalf of a tenant.

It operates entirely on the current goroutine and is thus able to reuse an existing client.Txn safely.

func ResolveCastForStyleUsingVisitor ¶

func ResolveCastForStyleUsingVisitor(
	ctx context.Context,
	semaCtx *tree.SemaContext,
	desc *descpb.TableDescriptor,
	expr tree.Expr,
	tn *tree.TableName,
) (tree.Expr, bool, error)

ResolveCastForStyleUsingVisitor checks expression for stable cast that affect DateStyle/IntervalStyle and rewrites them.

func ResolveFK ¶

ResolveFK looks up the tables and columns mentioned in a `REFERENCES` constraint and adds metadata representing that constraint to the descriptor. It may, in doing so, add to or alter descriptors in the passed in `backrefs` map of other tables that need to be updated when this table is created. Constraints that are not known to hold for existing data are created "unvalidated", but when table is empty (e.g. during creation), no existing data implies no existing violations, and thus the constraint can be created without the unvalidated flag.

The caller should pass an instance of fkSelfResolver as SchemaResolver, so that FK references can find the newly created table for self-references.

The caller must also ensure that the SchemaResolver is configured to bypass caching and enable visibility of just-added descriptors. If there are any FKs, the descriptor of the depended-on table must be looked up uncached, and we'll allow FK dependencies on tables that were just added.

The passed Txn is used to lookup databases to qualify names in error messages but if nil, will result in unqualified names in those errors.

The passed validationBehavior is used to determine whether or not preexisting entries in the table need to be validated against the foreign key being added. This only applies for existing tables, not new tables.

func ResolveUniqueWithoutIndexConstraint ¶

func ResolveUniqueWithoutIndexConstraint(
	ctx context.Context,
	tbl *tabledesc.Mutable,
	constraintName string,
	colNames []string,
	predicate string,
	ts TableState,
	validationBehavior tree.ValidationBehavior,
) error

ResolveUniqueWithoutIndexConstraint looks up the columns mentioned in a UNIQUE WITHOUT INDEX constraint and adds metadata representing that constraint to the descriptor.

The passed validationBehavior is used to determine whether or not preexisting entries in the table need to be validated against the unique constraint being added. This only applies for existing tables, not new tables.

func RevertTables ¶

func RevertTables(
	ctx context.Context,
	db *kv.DB,
	execCfg *ExecutorConfig,
	tables []catalog.TableDescriptor,
	targetTime hlc.Timestamp,
	ignoreGCThreshold bool,
	batchSize int64,
) error

RevertTables reverts the passed table to the target time, which much be above the GC threshold for every range (unless the flag ignoreGCThreshold is passed which should be done with care -- see RevertRangeRequest.IgnoreGCThreshold).

func RoleExists ¶

func RoleExists(
	ctx context.Context, execCfg *ExecutorConfig, txn *kv.Txn, role security.SQLUsername,
) (bool, error)

RoleExists returns true if the role exists.

func Save ¶

func Save(writer io.Writer, file interface{})

Save stores any file into the writer in JSON format

func ShowCreatePartitioning ¶

func ShowCreatePartitioning(
	a *tree.DatumAlloc,
	codec keys.SQLCodec,
	tableDesc catalog.TableDescriptor,
	idx catalog.Index,
	part catalog.Partitioning,
	buf *bytes.Buffer,
	indent int,
	colOffset int,
) error

ShowCreatePartitioning returns a PARTITION BY clause for the specified index, if applicable.

func ShowCreateSequence ¶

func ShowCreateSequence(
	ctx context.Context, tn *tree.TableName, desc catalog.TableDescriptor,
) (string, error)

ShowCreateSequence returns a valid SQL representation of the CREATE SEQUENCE statement used to create the given sequence.

func ShowCreateTable ¶

func ShowCreateTable(
	ctx context.Context,
	p PlanHookState,
	tn *tree.TableName,
	dbPrefix string,
	desc catalog.TableDescriptor,
	lCtx simpleSchemaResolver,
	displayOptions ShowCreateDisplayOptions,
) (string, error)

ShowCreateTable returns a valid SQL representation of the CREATE TABLE statement used to create the given table.

The names of the tables referenced by foreign keys are prefixed by their own database name unless it is equal to the given dbPrefix. This allows us to elide the prefix when the given table references other tables in the current database.

func ShowCreateView ¶

func ShowCreateView(
	ctx context.Context,
	semaCtx *tree.SemaContext,
	sessionData *sessiondata.SessionData,
	tn *tree.TableName,
	desc catalog.TableDescriptor,
) (string, error)

ShowCreateView returns a valid SQL representation of the CREATE VIEW statement used to create the given view. It is used in the implementation of the crdb_internal.create_statements virtual table.

func SimplifySerialInColumnDefWithRowID ¶

func SimplifySerialInColumnDefWithRowID(
	ctx context.Context, d *tree.ColumnTableDef, tableName *tree.TableName,
) error

SimplifySerialInColumnDefWithRowID analyzes a column definition and simplifies any use of SERIAL as if SerialNormalizationMode was set to SerialUsesRowID. No sequence needs to be created.

This is currently used by bulk I/O import statements which do not (yet?) support customization of the SERIAL behavior.

func StubTableStats ¶

func StubTableStats(
	desc catalog.TableDescriptor, name string, multiColEnabled bool,
) ([]*stats.TableStatisticProto, error)

StubTableStats generates "stub" statistics for a table which are missing histograms and have 0 for all values.

func SynthesizeRegionConfig ¶

func SynthesizeRegionConfig(
	ctx context.Context,
	txn *kv.Txn,
	dbID descpb.ID,
	descsCol *descs.Collection,
	opts ...SynthesizeRegionConfigOption,
) (multiregion.RegionConfig, error)

SynthesizeRegionConfig returns a RegionConfig representing the user configured state of a multi-region database by coalescing state from both the database descriptor and multi-region type descriptor. By default, it avoids the cache and is intended for use by DDL statements.

TODO(ajwerner): Refactor this to take the database descriptor rather than the database ID.

func TablesMetadataFilename ¶

func TablesMetadataFilename(path, rdbms, schema string) string

TablesMetadataFilename give the appropriate name where to store or read any schema description from a specific database.

func TestingDescsTxn ¶

func TestingDescsTxn(
	ctx context.Context,
	s serverutils.TestServerInterface,
	f func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error,
) error

TestingDescsTxn is a convenience function for running a transaction on descriptors when you have a serverutils.TestServerInterface.

func TestingGetAllNames ¶

func TestingGetAllNames(
	ctx context.Context, txn *kv.Txn, executor *InternalExecutor,
) (map[descpb.ID]catalog.NameKey, error)

TestingGetAllNames is a wrapper for getAllNames.

func TestingOverrideExplainEnvVersion ¶

func TestingOverrideExplainEnvVersion(ver string) func()

TestingOverrideExplainEnvVersion overrides the version reported by EXPLAIN (OPT, ENV). Used for testing.

func TestingUpdateTenantRecord ¶

func TestingUpdateTenantRecord(
	ctx context.Context, execCfg *ExecutorConfig, txn *kv.Txn, info *descpb.TenantInfo,
) error

TestingUpdateTenantRecord is a public wrapper around updateTenantRecord intended for testing purposes.

func TranslateDataPlacement ¶

func TranslateDataPlacement(g tree.DataPlacement) (descpb.DataPlacement, error)

TranslateDataPlacement translates a tree.DataPlacement into a descpb.DataPlacement.

func TranslateSurvivalGoal ¶

func TranslateSurvivalGoal(g tree.SurvivalGoal) (descpb.SurvivalGoal, error)

TranslateSurvivalGoal translates a tree.SurvivalGoal into a descpb.SurvivalGoal.

func UnsplitRangesInSpan ¶

func UnsplitRangesInSpan(ctx context.Context, kvDB *kv.DB, span roachpb.Span) error

UnsplitRangesInSpan unsplist any manually split ranges within a span. TODO(Chengxiong): move this function to gc_job.go in 22.2

func ValidateForwardIndexes ¶

func ValidateForwardIndexes(
	ctx context.Context,
	tableDesc catalog.TableDescriptor,
	indexes []catalog.Index,
	runHistoricalTxn sqlutil.HistoricalInternalExecTxnRunner,
	withFirstMutationPublic bool,
	gatherAllInvalid bool,
	execOverride sessiondata.InternalExecutorOverride,
) error

ValidateForwardIndexes checks that the indexes have entries for all the rows.

This operates over multiple goroutines concurrently and is thus not able to reuse the original kv.Txn safely. Instead it uses the provided runHistoricalTxn which can operate at the historical fixed timestamp for checks. Typically it fails as soon as any index fails validation as this usually means the schema change should rollback. However, if gatherAllInvalid is true, it instead accumulates all the indexes which fail and returns them together. withFirstMutationPublic should be set to true if we are validating and assuming the first mutation is made public. This should be used when finalizing a schema change after a backfill.

func ValidateInvertedIndexes ¶

func ValidateInvertedIndexes(
	ctx context.Context,
	codec keys.SQLCodec,
	tableDesc catalog.TableDescriptor,
	indexes []catalog.Index,
	runHistoricalTxn sqlutil.HistoricalInternalExecTxnRunner,
	withFirstMutationPublic bool,
	gatherAllInvalid bool,
	execOverride sessiondata.InternalExecutorOverride,
) error

ValidateInvertedIndexes checks that the indexes have entries for all the items of data in rows.

This operates over multiple goroutines concurrently and is thus not able to reuse the original kv.Txn safely. Instead it uses the provided runHistoricalTxn which can operate at the historical fixed timestamp for checks.

func WaitToUpdateLeases ¶

func WaitToUpdateLeases(
	ctx context.Context, leaseMgr *lease.Manager, descID descpb.ID,
) (catalog.Descriptor, error)

WaitToUpdateLeases until the entire cluster has been updated to the latest version of the descriptor.

func WithAnonymizedStatement ¶

func WithAnonymizedStatement(err error, stmt tree.Statement, vt VirtualTabler) error

WithAnonymizedStatement attaches the anonymized form of a statement to an error object.

func WithOnlyGlobalTables ¶

func WithOnlyGlobalTables(opts *updateZoneConfigOptions)

WithOnlyGlobalTables modifies an updateZoneConfigOptions to only apply to global tables.

func WithOnlyRegionalTablesAndGlobalTables ¶

func WithOnlyRegionalTablesAndGlobalTables(opts *updateZoneConfigOptions)

WithOnlyRegionalTablesAndGlobalTables modifies an updateZoneConfigOptions to only apply to global tables and regional tables.

Types ¶

type AuthorizationAccessor ¶

type AuthorizationAccessor interface {
	// CheckPrivilege verifies that the user has `privilege` on `descriptor`.
	CheckPrivilegeForUser(
		ctx context.Context, descriptor catalog.Descriptor, privilege privilege.Kind, user security.SQLUsername,
	) error

	// CheckPrivilege verifies that the current user has `privilege` on `descriptor`.
	CheckPrivilege(
		ctx context.Context, descriptor catalog.Descriptor, privilege privilege.Kind,
	) error

	// CheckAnyPrivilege returns nil if user has any privileges at all.
	CheckAnyPrivilege(ctx context.Context, descriptor catalog.Descriptor) error

	// UserHasAdminRole returns tuple of bool and error:
	// (true, nil) means that the user has an admin role (i.e. root or node)
	// (false, nil) means that the user has NO admin role
	// (false, err) means that there was an error running the query on
	// the `system.users` table
	UserHasAdminRole(ctx context.Context, user security.SQLUsername) (bool, error)

	// HasAdminRole checks if the current session's user has admin role.
	HasAdminRole(ctx context.Context) (bool, error)

	// RequireAdminRole is a wrapper on top of HasAdminRole.
	// It errors if HasAdminRole errors or if the user isn't a super-user.
	// Includes the named action in the error message.
	RequireAdminRole(ctx context.Context, action string) error

	// MemberOfWithAdminOption looks up all the roles (direct and indirect) that 'member' is a member
	// of and returns a map of role -> isAdmin.
	MemberOfWithAdminOption(ctx context.Context, member security.SQLUsername) (map[security.SQLUsername]bool, error)

	// HasRoleOption converts the roleoption to its SQL column name and checks if
	// the user belongs to a role where the option has value true. Requires a
	// valid transaction to be open.
	//
	// This check should be done on the version of the privilege that is stored in
	// the role options table. Example: CREATEROLE instead of NOCREATEROLE.
	// NOLOGIN instead of LOGIN.
	HasRoleOption(ctx context.Context, roleOption roleoption.Option) (bool, error)
}

AuthorizationAccessor for checking authorization (e.g. desc privileges).

type BackupRestoreTestingKnobs ¶

type BackupRestoreTestingKnobs struct {
	// CaptureResolvedTableDescSpans allows for intercepting the spans which are
	// resolved during backup planning, and will eventually be backed up during
	// execution.
	CaptureResolvedTableDescSpans func([]roachpb.Span)

	// RunAfterProcessingRestoreSpanEntry allows blocking the RESTORE job after a
	// single RestoreSpanEntry has been processed and added to the SSTBatcher.
	RunAfterProcessingRestoreSpanEntry func(ctx context.Context)

	// RunAfterExportingSpanEntry allows blocking the BACKUP job after a single
	// span has been exported.
	RunAfterExportingSpanEntry func(ctx context.Context, response *roachpb.ExportResponse)

	// BackupMonitor is used to overwrite the monitor used by backup during
	// testing. This is typically the bulk mem monitor if not
	// specified here.
	BackupMemMonitor *mon.BytesMonitor
}

BackupRestoreTestingKnobs contains knobs for backup and restore behavior.

func (*BackupRestoreTestingKnobs) ModuleTestingKnobs ¶

func (*BackupRestoreTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs implements the base.ModuleTestingKnobs interface.

type BaseMemoryMetrics ¶

type BaseMemoryMetrics struct {
	MaxBytesHist  *metric.Histogram
	CurBytesCount *metric.Gauge
}

BaseMemoryMetrics contains a max histogram and a current count of the bytes allocated by a sql endpoint.

func MakeBaseMemMetrics ¶

func MakeBaseMemMetrics(endpoint string, histogramWindow time.Duration) BaseMemoryMetrics

MakeBaseMemMetrics instantiates the metric objects for an SQL endpoint, but only includes the root metrics: .max and .current, without txn and session.

type BindResult ¶

type BindResult interface {
	ResultBase
}

BindResult represents the result of a Bind command.

type BindStmt ¶

type BindStmt struct {
	PreparedStatementName string
	PortalName            string
	// OutFormats contains the requested formats for the output columns.
	// It either contains a bunch of format codes, in which case the number will
	// need to match the number of output columns of the portal, or contains a single
	// code, in which case that code will be applied to all columns.
	OutFormats []pgwirebase.FormatCode
	// Args are the arguments for the prepared statement.
	// They are passed in without decoding because decoding requires type
	// inference to have been performed.
	//
	// A nil element means a tree.DNull argument.
	Args [][]byte
	// ArgFormatCodes are the codes to be used to deserialize the Args.
	// It either contains a bunch of format codes, in which case the number will
	// need to match the number of arguments for the portal, or contains a single
	// code, in which case that code will be applied to all arguments.
	ArgFormatCodes []pgwirebase.FormatCode
	// contains filtered or unexported fields
}

BindStmt is the Command for creating a portal from a prepared statement.

func (BindStmt) String ¶

func (b BindStmt) String() string

type CallbackResultWriter ¶

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

CallbackResultWriter is a rowResultWriter that runs a callback function on AddRow.

func NewCallbackResultWriter ¶

func NewCallbackResultWriter(
	fn func(ctx context.Context, row tree.Datums) error,
) *CallbackResultWriter

NewCallbackResultWriter creates a new CallbackResultWriter.

func (*CallbackResultWriter) AddRow ¶

func (c *CallbackResultWriter) AddRow(ctx context.Context, row tree.Datums) error

AddRow is part of the rowResultWriter interface.

func (*CallbackResultWriter) Err ¶

func (c *CallbackResultWriter) Err() error

Err is part of the rowResultWriter interface.

func (*CallbackResultWriter) IncrementRowsAffected ¶

func (c *CallbackResultWriter) IncrementRowsAffected(ctx context.Context, n int)

IncrementRowsAffected is part of the rowResultWriter interface.

func (*CallbackResultWriter) SetError ¶

func (c *CallbackResultWriter) SetError(err error)

SetError is part of the rowResultWriter interface.

type ClientComm ¶

type ClientComm interface {
	// createStatementResult creates a StatementResult for stmt.
	//
	// descOpt specifies if result needs to inform the client about row schema. If
	// it doesn't, a SetColumns call becomes a no-op.
	//
	// pos is the stmt's position within the connection and is used to enforce
	// that results are created in order and also to discard results through
	// ClientLock.rtrim(pos).
	//
	// formatCodes describe how each column in the result rows is to be encoded.
	// It should be nil if statement type != Rows. Otherwise, it can be nil, in
	// which case every column will be encoded using the text encoding, otherwise
	// it needs to contain a value for every column.
	CreateStatementResult(
		stmt tree.Statement,
		descOpt RowDescOpt,
		pos CmdPos,
		formatCodes []pgwirebase.FormatCode,
		conv sessiondatapb.DataConversionConfig,
		location *time.Location,
		limit int,
		portalName string,
		implicitTxn bool,
	) CommandResult
	// CreatePrepareResult creates a result for a PrepareStmt command.
	CreatePrepareResult(pos CmdPos) ParseResult
	// CreateDescribeResult creates a result for a DescribeStmt command.
	CreateDescribeResult(pos CmdPos) DescribeResult
	// CreateBindResult creates a result for a BindStmt command.
	CreateBindResult(pos CmdPos) BindResult
	// CreateDeleteResult creates a result for a DeletePreparedStmt command.
	CreateDeleteResult(pos CmdPos) DeleteResult
	// CreateSyncResult creates a result for a Sync command.
	CreateSyncResult(pos CmdPos) SyncResult
	// CreateFlushResult creates a result for a Flush command.
	CreateFlushResult(pos CmdPos) FlushResult
	// CreateErrorResult creates a result on which only errors can be communicated
	// to the client.
	CreateErrorResult(pos CmdPos) ErrorResult
	// CreateEmptyQueryResult creates a result for an empty-string query.
	CreateEmptyQueryResult(pos CmdPos) EmptyQueryResult
	// CreateCopyInResult creates a result for a Copy-in command.
	CreateCopyInResult(pos CmdPos) CopyInResult
	// CreateDrainResult creates a result for a Drain command.
	CreateDrainResult(pos CmdPos) DrainResult

	// lockCommunication ensures that no further results are delivered to the
	// client. The returned ClientLock can be queried to see what results have
	// been already delivered to the client and to discard results that haven't
	// been delivered.
	//
	// ClientLock.Close() needs to be called on the returned lock once
	// communication can be unlocked (i.e. results can be delivered to the client
	// again).
	LockCommunication() ClientLock

	// Flush delivers all the previous results to the client. The results might
	// have been buffered, in which case this flushes the buffer.
	Flush(pos CmdPos) error
}

ClientComm is the interface used by the connExecutor for creating results to be communicated to client and for exerting some control over this communication.

ClientComm is implemented by the pgwire connection.

type ClientLock ¶

type ClientLock interface {
	// Close unlocks the ClientComm from whence this ClientLock came from. After
	// Close is called, buffered results may again be sent to the client,
	// according to the result streaming policy.
	//
	// Once Close() is called, the ClientLock cannot be used anymore.
	Close()

	// ClientPos returns the position of the latest command for which results
	// have been sent to the client. The position is relative to the start of the
	// connection.
	ClientPos() CmdPos

	// RTrim iterates backwards through the results and drops all results with
	// position >= pos.
	// It is illegal to call rtrim with a position <= clientPos(). In other words,
	// results can
	RTrim(ctx context.Context, pos CmdPos)
}

ClientLock is an interface returned by ClientComm.lockCommunication(). It represents a lock on the delivery of results to a SQL client. While such a lock is used, no more results are delivered. The lock itself can be used to query what results have already been delivered and to discard results that haven't been delivered.

type ClusterWideID ¶

type ClusterWideID struct {
	uint128.Uint128
}

ClusterWideID represents an identifier that is guaranteed to be unique across a cluster. It is a wrapper around a uint128. It logically consists of 96 bits of HLC timestamp, and 32 bits of node ID.

func BytesToClusterWideID ¶

func BytesToClusterWideID(b []byte) ClusterWideID

BytesToClusterWideID converts raw bytes into a ClusterWideID. The caller is responsible for ensuring the byte slice contains 16 bytes.

func GenerateClusterWideID ¶

func GenerateClusterWideID(timestamp hlc.Timestamp, instID base.SQLInstanceID) ClusterWideID

GenerateClusterWideID takes a timestamp and SQLInstanceID, and generates a ClusterWideID.

func StringToClusterWideID ¶

func StringToClusterWideID(s string) (ClusterWideID, error)

StringToClusterWideID converts a string to a ClusterWideID. If the string is not a valid uint128, an error is returned.

func (ClusterWideID) GetNodeID ¶

func (id ClusterWideID) GetNodeID() int32

GetNodeID extracts the node ID from a ClusterWideID.

type CmdPos ¶

type CmdPos int64

CmdPos represents the index of a command relative to the start of a connection. The first command received on a connection has position 0.

type Command ¶

type Command interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Command is an interface implemented by all commands pushed by pgwire into the buffer.

type CommandResult ¶

type CommandResult interface {
	RestrictedCommandResult
	CommandResultClose
}

CommandResult represents the result of a statement. It which needs to be ultimately delivered to the client. pgwire.conn implements this.

type CommandResultClose ¶

type CommandResultClose interface {
	// Close marks a result as complete. No further uses of the CommandResult are
	// allowed after this call. All results must be eventually closed through
	// Close()/Discard(), except in case query processing has encountered an
	// irrecoverable error and the client connection will be closed; in such
	// cases it is not mandated that these functions are called on the result
	// that may have been open at the time the error occurred.
	// NOTE(andrei): We might want to tighten the contract if the results get any
	// state that needs to be closed even when the whole connection is about to be
	// terminated.
	Close(context.Context, TransactionStatusIndicator)

	// Discard is called to mark the fact that the result is being disposed off.
	// No completion message will be sent to the client. The expectation is that
	// either the no other methods on the result had previously been used (and so
	// no data has been buffered for the client), or there is a communication lock
	// in effect and the buffer will be rewound - in either case, the client will
	// never see any bytes pertaining to this result.
	Discard()
}

CommandResultClose is a subset of CommandResult dealing with the closing of the result.

type CommandResultErrBase ¶

type CommandResultErrBase interface {
	// SetError accumulates an execution error that needs to be reported to the
	// client. No further calls other than SetError(), Close() and Discard() are
	// allowed.
	//
	// Calling SetError() a second time overwrites the previously set error.
	SetError(error)

	// Err returns the error previously set with SetError(), if any.
	Err() error
}

CommandResultErrBase is the subset of CommandResult dealing with setting a query execution error.

type ConnectionHandler ¶

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

ConnectionHandler is the interface between the result of SetupConn and the ServeConn below. It encapsulates the connExecutor and hides it away from other packages.

func (ConnectionHandler) GetParamStatus ¶

func (h ConnectionHandler) GetParamStatus(ctx context.Context, varName string) string

GetParamStatus retrieves the configured value of the session variable identified by varName. This is used for the initial message sent to a client during a session set-up.

func (ConnectionHandler) GetQueryCancelKey ¶

func (h ConnectionHandler) GetQueryCancelKey() pgwirecancel.BackendKeyData

GetQueryCancelKey returns the per-session identifier that can be used to cancel a query using the pgwire cancel protocol.

type CopyIn ¶

type CopyIn struct {
	Stmt *tree.CopyFrom
	// Conn is the network connection. Execution of the CopyFrom statement takes
	// control of the connection.
	Conn pgwirebase.Conn
	// CopyDone is decremented once execution finishes, signaling that control of
	// the connection is being handed back to the network routine.
	CopyDone *sync.WaitGroup
}

CopyIn is the command for execution of the Copy-in pgwire subprotocol.

func (CopyIn) String ¶

func (CopyIn) String() string

type CopyInResult ¶

type CopyInResult interface {
	ResultBase
}

CopyInResult represents the result of a CopyIn command. Closing this result produces no output for the client.

type CreateRoleNode ¶

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

CreateRoleNode creates entries in the system.users table. This is called from CREATE USER and CREATE ROLE.

func (*CreateRoleNode) Close ¶

func (*CreateRoleNode) Close(context.Context)

Close implements the planNode interface.

func (*CreateRoleNode) Next ¶

func (*CreateRoleNode) Next(runParams) (bool, error)

Next implements the planNode interface.

func (*CreateRoleNode) Values ¶

func (*CreateRoleNode) Values() tree.Datums

Values implements the planNode interface.

type DeletePreparedStmt ¶

type DeletePreparedStmt struct {
	Name string
	Type pgwirebase.PrepareType
}

DeletePreparedStmt is the Command for freeing a prepared statement.

func (DeletePreparedStmt) String ¶

func (d DeletePreparedStmt) String() string

type DeleteResult ¶

type DeleteResult interface {
	ResultBase
}

DeleteResult represents the result of a DeletePreparedStatement command.

type DescribeResult ¶

type DescribeResult interface {
	ResultBase

	// SetInferredTypes tells the client about the inferred placeholder types.
	SetInferredTypes([]oid.Oid)
	// SetNoDataRowDescription is used to tell the client that the prepared
	// statement or portal produces no rows.
	SetNoDataRowDescription()
	// SetPrepStmtOutput tells the client about the results schema of a prepared
	// statement.
	SetPrepStmtOutput(context.Context, colinfo.ResultColumns)
	// SetPortalOutput tells the client about the results schema and formatting of
	// a portal.
	SetPortalOutput(context.Context, colinfo.ResultColumns, []pgwirebase.FormatCode)
}

DescribeResult represents the result of a Describe command (for either describing a prepared statement or a portal).

type DescribeStmt ¶

type DescribeStmt struct {
	Name string
	Type pgwirebase.PrepareType
}

DescribeStmt is the Command for producing info about a prepared statement or portal.

func (DescribeStmt) String ¶

func (d DescribeStmt) String() string

type DistSQLPlanner ¶

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

DistSQLPlanner is used to generate distributed plans from logical plans. A rough overview of the process:

  • the plan is based on a planNode tree (in the future it will be based on an intermediate representation tree). Only a subset of the possible trees is supported (this can be checked via CheckSupport).

  • we generate a PhysicalPlan for the planNode tree recursively. The PhysicalPlan consists of a network of processors and streams, with a set of unconnected "result routers". The PhysicalPlan also has information on ordering and on the mapping planNode columns to columns in the result streams (all result routers output streams with the same schema).

    The PhysicalPlan for a scanNode leaf consists of TableReaders, one for each node that has one or more ranges.

  • for each an internal planNode we start with the plan of the child node(s) and add processing stages (connected to the result routers of the children node).

func NewDistSQLPlanner ¶

func NewDistSQLPlanner(
	ctx context.Context,
	planVersion execinfrapb.DistSQLVersion,
	st *cluster.Settings,
	sqlInstanceID base.SQLInstanceID,
	rpcCtx *rpc.Context,
	distSQLSrv *distsql.ServerImpl,
	distSender *kvcoord.DistSender,
	nodeDescs kvcoord.NodeDescStore,
	gw gossip.OptionalGossip,
	stopper *stop.Stopper,
	isAvailable func(base.SQLInstanceID) bool,
	nodeDialer *nodedialer.Dialer,
	podNodeDialer *nodedialer.Dialer,
	codec keys.SQLCodec,
	sqlInstanceProvider sqlinstance.Provider,
) *DistSQLPlanner

NewDistSQLPlanner initializes a DistSQLPlanner.

sqlInstanceID is the ID of the node on which this planner runs. It is used to favor itself and other close-by nodes when planning. An invalid sqlInstanceID can be passed to aid bootstrapping, but then SetSQLInstanceInfo() needs to be called before this planner is used.

func (*DistSQLPlanner) CheckInstanceHealthAndVersion ¶

func (dsp *DistSQLPlanner) CheckInstanceHealthAndVersion(
	planCtx *PlanningCtx, sqlInstanceID base.SQLInstanceID,
) NodeStatus

CheckInstanceHealthAndVersion returns a information about a node's health and compatibility. The info is also recorded in planCtx.Nodes.

func (*DistSQLPlanner) Exec ¶

func (dsp *DistSQLPlanner) Exec(
	ctx context.Context, localPlanner interface{}, sql string, distribute bool,
) error

Exec is a test utility function that takes a localPlanner (of type interface{} so that external packages can call NewInternalPlanner and pass the result) and executes a sql statement through the DistSQLPlanner.

func (*DistSQLPlanner) FinalizePlan ¶

func (dsp *DistSQLPlanner) FinalizePlan(planCtx *PlanningCtx, plan *PhysicalPlan)

FinalizePlan adds a final "result" stage and a final projection if necessary as well as populates the endpoints of the plan.

func (*DistSQLPlanner) GatewayID ¶

func (dsp *DistSQLPlanner) GatewayID() base.SQLInstanceID

GatewayID returns the ID of the gateway.

func (*DistSQLPlanner) GetSQLInstanceInfo ¶

func (dsp *DistSQLPlanner) GetSQLInstanceInfo(
	sqlInstanceID base.SQLInstanceID,
) (*roachpb.NodeDescriptor, error)

GetSQLInstanceInfo gets a node descriptor by node ID.

func (*DistSQLPlanner) NewPlanningCtx ¶

func (dsp *DistSQLPlanner) NewPlanningCtx(
	ctx context.Context,
	evalCtx *extendedEvalContext,
	planner *planner,
	txn *kv.Txn,
	distributionType DistributionType,
) *PlanningCtx

NewPlanningCtx returns a new PlanningCtx. When distribute is false, a lightweight version PlanningCtx is returned that can be used when the caller knows plans will only be run on one node. On SQL tenants, the plan is only distributed if tenantDistributionEnabled is true. planner argument can be left nil.

func (*DistSQLPlanner) PartitionSpans ¶

func (dsp *DistSQLPlanner) PartitionSpans(
	planCtx *PlanningCtx, spans roachpb.Spans,
) ([]SpanPartition, error)

PartitionSpans finds out which nodes are owners for ranges touching the given spans, and splits the spans according to owning nodes. The result is a set of SpanPartitions (guaranteed one for each relevant node), which form a partitioning of the spans (i.e. they are non-overlapping and their union is exactly the original set of spans).

PartitionSpans does its best to not assign ranges on nodes that are known to either be unhealthy or running an incompatible version. The ranges owned by such nodes are assigned to the gateway.

func (*DistSQLPlanner) PlanAndRun ¶

func (dsp *DistSQLPlanner) PlanAndRun(
	ctx context.Context,
	evalCtx *extendedEvalContext,
	planCtx *PlanningCtx,
	txn *kv.Txn,
	plan planMaybePhysical,
	recv *DistSQLReceiver,
) (cleanup func())

PlanAndRun generates a physical plan from a planNode tree and executes it. It assumes that the tree is supported (see CheckSupport).

All errors encountered are reported to the DistSQLReceiver's resultWriter. Additionally, if the error is a "communication error" (an error encountered while using that resultWriter), the error is also stored in DistSQLReceiver.commErr. That can be tested to see if a client session needs to be closed.

It returns a non-nil (although it can be a noop when an error is encountered) cleanup function that must be called once the planTop AST is no longer needed and can be closed. Note that this function also cleans up the flow which is unfortunate but is caused by the sharing of memory monitors between planning and execution - cleaning up the flow wants to close the monitor, but it cannot do so because the AST needs to live longer and still uses the same monitor. That's why we end up in a situation that in order to clean up the flow, we need to close the AST first, but we can only do that after PlanAndRun returns.

func (*DistSQLPlanner) PlanAndRunCascadesAndChecks ¶

func (dsp *DistSQLPlanner) PlanAndRunCascadesAndChecks(
	ctx context.Context,
	planner *planner,
	evalCtxFactory func() *extendedEvalContext,
	plan *planComponents,
	recv *DistSQLReceiver,
) bool

PlanAndRunCascadesAndChecks runs any cascade and check queries.

Because cascades can themselves generate more cascades or check queries, this method can append to plan.cascades and plan.checkPlans (and all these plans must be closed later).

Returns false if an error was encountered and sets that error in the provided receiver.

func (*DistSQLPlanner) PlanAndRunSubqueries ¶

func (dsp *DistSQLPlanner) PlanAndRunSubqueries(
	ctx context.Context,
	planner *planner,
	evalCtxFactory func() *extendedEvalContext,
	subqueryPlans []subquery,
	recv *DistSQLReceiver,
	subqueryResultMemAcc *mon.BoundAccount,
) bool

PlanAndRunSubqueries returns false if an error was encountered and sets that error in the provided receiver. Note that if false is returned, then this function will have closed all the subquery plans because it assumes that the caller will not try to run the main plan given that the subqueries' evaluation failed.

  • subqueryResultMemAcc must be a non-nil memory account that the result of subqueries' evaluation will be registered with. It is the caller's responsibility to shrink (or close) the account accordingly, once the references to those results are lost.

func (*DistSQLPlanner) Run ¶

func (dsp *DistSQLPlanner) Run(
	planCtx *PlanningCtx,
	txn *kv.Txn,
	plan *PhysicalPlan,
	recv *DistSQLReceiver,
	evalCtx *extendedEvalContext,
	finishedSetupFn func(),
) (cleanup func())

Run executes a physical plan. The plan should have been finalized using FinalizePlan.

All errors encountered are reported to the DistSQLReceiver's resultWriter. Additionally, if the error is a "communication error" (an error encountered while using that resultWriter), the error is also stored in DistSQLReceiver.commErr. That can be tested to see if a client session needs to be closed.

Args: - txn is the transaction in which the plan will run. If nil, the different processors are expected to manage their own internal transactions. - evalCtx is the evaluation context in which the plan will run. It might be mutated. - finishedSetupFn, if non-nil, is called synchronously after all the processors have successfully started up.

It returns a non-nil (although it can be a noop when an error is encountered) cleanup function that must be called in order to release the resources.

func (*DistSQLPlanner) SetSQLInstanceInfo ¶

func (dsp *DistSQLPlanner) SetSQLInstanceInfo(desc roachpb.NodeDescriptor)

SetSQLInstanceInfo sets the planner's node descriptor. The first call to SetSQLInstanceInfo leads to the construction of the SpanResolver.

func (*DistSQLPlanner) SetSpanResolver ¶

func (dsp *DistSQLPlanner) SetSpanResolver(spanResolver physicalplan.SpanResolver)

SetSpanResolver switches to a different SpanResolver. It is the caller's responsibility to make sure the DistSQLPlanner is not in use.

func (*DistSQLPlanner) SetupAllNodesPlanning ¶

func (dsp *DistSQLPlanner) SetupAllNodesPlanning(
	ctx context.Context, evalCtx *extendedEvalContext, execCfg *ExecutorConfig,
) (*PlanningCtx, []base.SQLInstanceID, error)

SetupAllNodesPlanning creates a planCtx and sets up the planCtx.NodeStatuses map for all nodes. It returns all nodes that can be used for planning.

type DistSQLReceiver ¶

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

DistSQLReceiver is an execinfra.RowReceiver and execinfra.BatchReceiver that writes results to a rowResultWriter and batchResultWriter, respectively. This is where the DistSQL execution meets the SQL Session - the result writer comes from a client Session.

DistSQLReceiver also update the RangeDescriptorCache in response to DistSQL metadata about misplanned ranges.

func MakeDistSQLReceiver ¶

func MakeDistSQLReceiver(
	ctx context.Context,
	resultWriter rowResultWriter,
	stmtType tree.StatementReturnType,
	rangeCache *rangecache.RangeCache,
	txn *kv.Txn,
	clockUpdater clockUpdater,
	tracing *SessionTracing,
	contentionRegistry *contention.Registry,
	testingPushCallback func(rowenc.EncDatumRow, *execinfrapb.ProducerMetadata),
) *DistSQLReceiver

MakeDistSQLReceiver creates a DistSQLReceiver.

ctx is the Context that the receiver will use throughout its lifetime. resultWriter is the container where the results will be stored. If only the row count is needed, this can be nil.

txn is the transaction in which the producer flow runs; it will be updated on errors. Nil if the flow overall doesn't run in a transaction.

func (*DistSQLReceiver) ProducerDone ¶

func (r *DistSQLReceiver) ProducerDone()

ProducerDone is part of the execinfra.RowReceiver interface.

func (*DistSQLReceiver) Push ¶

Push is part of the execinfra.RowReceiver interface.

func (*DistSQLReceiver) PushBatch ¶

PushBatch is part of the execinfra.BatchReceiver interface.

func (*DistSQLReceiver) Release ¶

func (r *DistSQLReceiver) Release()

Release releases this DistSQLReceiver back to the pool.

func (*DistSQLReceiver) SetError ¶

func (r *DistSQLReceiver) SetError(err error)

SetError provides a convenient way for a client to pass in an error, thus pretending that a query execution error happened. The error is passed along to the resultWriter.

The status of DistSQLReceiver is updated accordingly.

type DistributionType ¶

type DistributionType int

DistributionType is an enum defining when a plan should be distributed.

type DrainRequest ¶

type DrainRequest struct{}

DrainRequest represents a notice that the server is draining and command processing should stop soon.

DrainRequest commands don't produce results.

func (DrainRequest) String ¶

func (DrainRequest) String() string

type DrainResult ¶

type DrainResult interface {
	ResultBase
}

DrainResult represents the result of a Drain command. Closing this result produces no output for the client.

type DropRoleNode ¶

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

DropRoleNode deletes entries from the system.users table. This is called from DROP USER and DROP ROLE.

func (*DropRoleNode) Close ¶

func (*DropRoleNode) Close(context.Context)

Close implements the planNode interface.

func (*DropRoleNode) Next ¶

func (*DropRoleNode) Next(runParams) (bool, error)

Next implements the planNode interface.

func (*DropRoleNode) Values ¶

func (*DropRoleNode) Values() tree.Datums

Values implements the planNode interface.

type EmptyQueryResult ¶

type EmptyQueryResult interface {
	ResultBase
}

EmptyQueryResult represents the result of an empty query (a query representing a blank string).

type EngineMetrics ¶

type EngineMetrics struct {
	// The subset of SELECTs that are processed through DistSQL.
	DistSQLSelectCount *metric.Counter
	// The subset of queries which we attempted and failed to plan with the
	// cost-based optimizer.
	SQLOptFallbackCount   *metric.Counter
	SQLOptPlanCacheHits   *metric.Counter
	SQLOptPlanCacheMisses *metric.Counter

	DistSQLExecLatency    *metric.Histogram
	SQLExecLatency        *metric.Histogram
	DistSQLServiceLatency *metric.Histogram
	SQLServiceLatency     *metric.Histogram
	SQLTxnLatency         *metric.Histogram
	SQLTxnsOpen           *metric.Gauge
	SQLActiveStatements   *metric.Gauge

	// TxnAbortCount counts transactions that were aborted, either due
	// to non-retriable errors, or retriable errors when the client-side
	// retry protocol is not in use.
	TxnAbortCount *metric.Counter

	// FailureCount counts non-retriable errors in open transactions.
	FailureCount *metric.Counter

	// FullTableOrIndexScanCount counts the number of full table or index scans.
	FullTableOrIndexScanCount *metric.Counter

	// FullTableOrIndexScanRejectedCount counts the number of queries that were
	// rejected because of the `disallow_full_table_scans` guardrail.
	FullTableOrIndexScanRejectedCount *metric.Counter
}

EngineMetrics groups a set of SQL metrics.

func (EngineMetrics) MetricStruct ¶

func (EngineMetrics) MetricStruct()

MetricStruct is part of the metric.Struct interface.

type EnumType ¶

type EnumType int

EnumType is the type of an enum.

type ErrorResult ¶

type ErrorResult interface {
	ResultBase
}

ErrorResult represents the result of a SendError command.

type ExecPortal ¶

type ExecPortal struct {
	Name string
	// limit is a feature of pgwire that we don't really support. We accept it and
	// don't complain as long as the statement produces fewer results than this.
	Limit int
	// TimeReceived is the time at which the exec message was received
	// from the client. Used to compute the service latency.
	TimeReceived time.Time
	// FollowedBySync is true if the next command after this is a Sync. This is
	// used to enable the 1PC txn fast path in the extended protocol.
	FollowedBySync bool
}

ExecPortal is the Command for executing a portal.

func (ExecPortal) String ¶

func (e ExecPortal) String() string

type ExecStmt ¶

type ExecStmt struct {
	// Information returned from parsing: AST, SQL, NumPlaceholders.
	// Note that AST can be nil, in which case executing it should produce an
	// "empty query response" message.
	parser.Statement

	// TimeReceived is the time at which the exec message was received
	// from the client. Used to compute the service latency.
	TimeReceived time.Time
	// ParseStart/ParseEnd are the timing info for parsing of the query. Used for
	// stats reporting.
	ParseStart time.Time
	ParseEnd   time.Time

	// LastInBatch indicates if this command contains the last query in a
	// simple protocol Query message that contains a batch of 1 or more queries.
	LastInBatch bool
}

ExecStmt is the command for running a query sent through the "simple" pgwire protocol.

func (ExecStmt) String ¶

func (e ExecStmt) String() string

type ExecutorConfig ¶

type ExecutorConfig struct {
	Settings *cluster.Settings
	NodeInfo
	Codec             keys.SQLCodec
	DefaultZoneConfig *zonepb.ZoneConfig
	Locality          roachpb.Locality
	AmbientCtx        log.AmbientContext
	DB                *kv.DB
	Gossip            gossip.OptionalGossip
	NodeLiveness      optionalnodeliveness.Container
	SystemConfig      config.SystemConfigProvider
	DistSender        *kvcoord.DistSender
	RPCContext        *rpc.Context
	LeaseManager      *lease.Manager
	Clock             *hlc.Clock
	DistSQLSrv        *distsql.ServerImpl
	// NodesStatusServer gives access to the NodesStatus service and is only
	// available when running as a system tenant.
	NodesStatusServer serverpb.OptionalNodesStatusServer
	// SQLStatusServer gives access to a subset of the Status service and is
	// available when not running as a system tenant.
	SQLStatusServer    serverpb.SQLStatusServer
	TenantStatusServer serverpb.TenantStatusServer
	RegionsServer      serverpb.RegionsServer
	MetricsRecorder    nodeStatusGenerator
	SessionRegistry    *SessionRegistry
	SQLLiveness        sqlliveness.Liveness
	JobRegistry        *jobs.Registry
	VirtualSchemas     *VirtualSchemaHolder
	DistSQLPlanner     *DistSQLPlanner
	TableStatsCache    *stats.TableStatisticsCache
	StatsRefresher     *stats.Refresher
	InternalExecutor   *InternalExecutor
	QueryCache         *querycache.C

	SchemaChangerMetrics *SchemaChangerMetrics
	FeatureFlagMetrics   *featureflag.DenialMetrics
	RowMetrics           *row.Metrics
	InternalRowMetrics   *row.Metrics

	TestingKnobs                         ExecutorTestingKnobs
	MigrationTestingKnobs                *migration.TestingKnobs
	PGWireTestingKnobs                   *PGWireTestingKnobs
	SchemaChangerTestingKnobs            *SchemaChangerTestingKnobs
	DeclarativeSchemaChangerTestingKnobs *scrun.TestingKnobs
	TypeSchemaChangerTestingKnobs        *TypeSchemaChangerTestingKnobs
	GCJobTestingKnobs                    *GCJobTestingKnobs
	DistSQLRunTestingKnobs               *execinfra.TestingKnobs
	EvalContextTestingKnobs              tree.EvalContextTestingKnobs
	TenantTestingKnobs                   *TenantTestingKnobs
	TTLTestingKnobs                      *TTLTestingKnobs
	BackupRestoreTestingKnobs            *BackupRestoreTestingKnobs
	StreamingTestingKnobs                *StreamingTestingKnobs
	SQLStatsTestingKnobs                 *sqlstats.TestingKnobs
	TelemetryLoggingTestingKnobs         *TelemetryLoggingTestingKnobs
	SpanConfigTestingKnobs               *spanconfig.TestingKnobs
	CaptureIndexUsageStatsKnobs          *scheduledlogging.CaptureIndexUsageStatsTestingKnobs
	// HistogramWindowInterval is (server.Config).HistogramWindowInterval.
	HistogramWindowInterval time.Duration

	// RangeDescriptorCache is updated by DistSQL when it finds out about
	// misplanned spans.
	RangeDescriptorCache *rangecache.RangeCache

	// Role membership cache.
	RoleMemberCache *MembershipCache

	// SessionInitCache cache; contains information used during authentication
	// and per-role default settings.
	SessionInitCache *sessioninit.Cache

	// ProtectedTimestampProvider encapsulates the protected timestamp subsystem.
	ProtectedTimestampProvider protectedts.Provider

	// StmtDiagnosticsRecorder deals with recording statement diagnostics.
	StmtDiagnosticsRecorder *stmtdiagnostics.Registry

	ExternalIODirConfig base.ExternalIODirConfig

	GCJobNotifier *gcjobnotifier.Notifier

	RangeFeedFactory *rangefeed.Factory

	// VersionUpgradeHook is called after validating a `SET CLUSTER SETTING
	// version` but before executing it. It can carry out arbitrary migrations
	// that allow us to eventually remove legacy code.
	VersionUpgradeHook VersionUpgradeHook

	// MigrationJobDeps is used to drive migrations.
	MigrationJobDeps migration.JobDeps

	// IndexBackfiller is used to backfill indexes. It is another rather circular
	// object which mostly just holds on to an ExecConfig.
	IndexBackfiller *IndexBackfillPlanner

	// IndexValidator is used to validate indexes.
	IndexValidator scexec.IndexValidator

	// DescMetadaUpdaterFactory is used to issue queries for updating comments.
	DescMetadaUpdaterFactory scexec.DescriptorMetadataUpdaterFactory

	// ContentionRegistry is a node-level registry of contention events used for
	// contention observability.
	ContentionRegistry *contention.Registry

	// RootMemoryMonitor is the root memory monitor of the entire server. Do not
	// use this for normal purposes. It is to be used to establish any new
	// root-level memory accounts that are not related to a user sessions.
	RootMemoryMonitor *mon.BytesMonitor

	// CompactEngineSpanFunc is used to inform a storage engine of the need to
	// perform compaction over a key span.
	CompactEngineSpanFunc tree.CompactEngineSpanFunc

	// TraceCollector is used to contact all live nodes in the cluster, and
	// collect trace spans from their inflight node registries.
	TraceCollector *collector.TraceCollector

	// TenantUsageServer is used to implement configuration APIs for tenant cost
	// control.
	TenantUsageServer multitenant.TenantUsageServer

	// CollectionFactory is used to construct a descs.Collection.
	CollectionFactory *descs.CollectionFactory

	// SystemTableIDResolver is used to obtain dynamic IDs for system tables.
	SystemTableIDResolver catalog.SystemTableIDResolver

	// SpanConfigReconciler is used to drive the span config reconciliation job
	// and related migrations.
	SpanConfigReconciler spanconfig.Reconciler

	// SpanConfigKVAccessor is used when creating and deleting tenant
	// records.
	SpanConfigKVAccessor spanconfig.KVAccessor

	// InternalExecutorFactory is used to create an InternalExecutor binded with
	// SessionData and other ExtraTxnState.
	// This is currently only for builtin functions where we need to execute sql.
	InternalExecutorFactory sqlutil.SessionBoundInternalExecutorFactory
}

An ExecutorConfig encompasses the auxiliary objects and configuration required to create an executor. All fields holding a pointer or an interface are required to create a Executor; the rest will have sane defaults set if omitted.

func (*ExecutorConfig) GetFeatureFlagMetrics ¶

func (cfg *ExecutorConfig) GetFeatureFlagMetrics() *featureflag.DenialMetrics

GetFeatureFlagMetrics returns the value of the FeatureFlagMetrics struct.

func (*ExecutorConfig) GetRowMetrics ¶

func (cfg *ExecutorConfig) GetRowMetrics(internal bool) *row.Metrics

GetRowMetrics returns the proper RowMetrics for either internal or user queries.

func (*ExecutorConfig) Organization ¶

func (cfg *ExecutorConfig) Organization() string

Organization returns the value of cluster.organization.

func (*ExecutorConfig) SV ¶

func (cfg *ExecutorConfig) SV() *settings.Values

SV returns the setting values.

type ExecutorTestingKnobs ¶

type ExecutorTestingKnobs struct {
	// StatementFilter can be used to trap execution of SQL statements and
	// optionally change their results. The filter function is invoked after each
	// statement has been executed.
	StatementFilter StatementFilter

	// BeforePrepare can be used to trap execution of SQL statement preparation.
	// If a nil error is returned, planning continues as usual.
	BeforePrepare func(ctx context.Context, stmt string, txn *kv.Txn) error

	// BeforeExecute is called by the Executor before plan execution. It is useful
	// for synchronizing statement execution.
	BeforeExecute func(ctx context.Context, stmt string)

	// AfterExecute is like StatementFilter, but it runs in the same goroutine of the
	// statement.
	AfterExecute func(ctx context.Context, stmt string, err error)

	// AfterExecCmd is called after successful execution of any command.
	AfterExecCmd func(ctx context.Context, cmd Command, buf *StmtBuf)

	// BeforeRestart is called before a transaction restarts.
	BeforeRestart func(ctx context.Context, reason error)

	// DisableAutoCommitDuringExec, if set, disables the auto-commit functionality
	// of some SQL statements. That functionality allows some statements to commit
	// directly when they're executed in an implicit SQL txn, without waiting for
	// the Executor to commit the implicit txn.
	// This has to be set in tests that need to abort such statements using a
	// StatementFilter; otherwise, the statement commits at the same time as
	// execution so there'll be nothing left to abort by the time the filter runs.
	DisableAutoCommitDuringExec bool

	// BeforeAutoCommit is called when the Executor is about to commit the KV
	// transaction after running a statement in an implicit transaction, allowing
	// tests to inject errors into that commit.
	// If an error is returned, that error will be considered the result of
	// txn.Commit(), and the txn.Commit() call will not actually be
	// made. If no error is returned, txn.Commit() is called normally.
	//
	// Note that this is not called if the SQL statement representing the implicit
	// transaction has committed the KV txn itself (e.g. if it used the 1-PC
	// optimization). This is only called when the Executor is the one doing the
	// committing.
	BeforeAutoCommit func(ctx context.Context, stmt string) error

	// DisableTempObjectsCleanupOnSessionExit disables cleaning up temporary schemas
	// and tables when a session is closed.
	DisableTempObjectsCleanupOnSessionExit bool
	// TempObjectsCleanupCh replaces the time.Ticker.C channel used for scheduling
	// a cleanup on every temp object in the cluster. If this is set, the job
	// will now trigger when items come into this channel.
	TempObjectsCleanupCh chan time.Time
	// OnTempObjectsCleanupDone will trigger when the temporary objects cleanup
	// job is done.
	OnTempObjectsCleanupDone func()

	// WithStatementTrace is called after the statement is executed in
	// execStmtInOpenState.
	WithStatementTrace func(trace tracing.Recording, stmt string)

	// RunAfterSCJobsCacheLookup is called after the SchemaChangeJobCache is checked for
	// a given table id.
	RunAfterSCJobsCacheLookup func(record *jobs.Record)

	// TestingSaveFlows, if set, will be called with the given stmt. The resulting
	// function will be called with the physical plan of that statement's main
	// query (i.e. no subqueries). The physical plan is only safe for use for the
	// lifetime of this function. Note that returning a nil function is
	// unsupported and will lead to a panic.
	TestingSaveFlows func(stmt string) func(map[base.SQLInstanceID]*execinfrapb.FlowSpec, execinfra.OpChains) error

	// DeterministicExplain, if set, will result in overriding fields in EXPLAIN
	// and EXPLAIN ANALYZE that can vary between runs (like elapsed times).
	//
	// TODO(radu): this flag affects EXPLAIN and EXPLAIN ANALYZE differently. It
	// hides the vectorization, distribution, and cluster nodes in EXPLAIN ANALYZE
	// but not in EXPLAIN. This is just a consequence of how the tests we have are
	// written. We should replace this knob with a session setting that allows
	// exact control of the redaction flags (and have each test set it as
	// necessary).
	DeterministicExplain bool

	// ForceRealTracingSpans, if set, forces the use of real (i.e. not no-op)
	// tracing spans for every statement.
	ForceRealTracingSpans bool

	// DistSQLReceiverPushCallbackFactory, if set, will be called every time a
	// DistSQLReceiver is created for a new query execution, and it should
	// return, possibly nil, a callback that will be called every time
	// DistSQLReceiver.Push is called.
	DistSQLReceiverPushCallbackFactory func(query string) func(rowenc.EncDatumRow, *execinfrapb.ProducerMetadata)

	// OnTxnRetry, if set, will be called if there is a transaction retry.
	OnTxnRetry func(autoRetryReason error, evalCtx *tree.EvalContext)

	// BeforeTxnStatsRecorded, if set, will be called before the statistics
	// of a transaction is being recorded.
	BeforeTxnStatsRecorded func(
		sessionData *sessiondata.SessionData,
		txnID uuid.UUID,
		txnFingerprintID roachpb.TransactionFingerprintID,
	)
}

ExecutorTestingKnobs is part of the context used to control parts of the system during testing.

func (*ExecutorTestingKnobs) ModuleTestingKnobs ¶

func (*ExecutorTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.

type FakeJobExecContext ¶

type FakeJobExecContext struct {
	JobExecContext
	ExecutorConfig *ExecutorConfig
}

FakeJobExecContext is used for mocking the JobExecContext in tests.

func (*FakeJobExecContext) DistSQLPlanner ¶

func (p *FakeJobExecContext) DistSQLPlanner() *DistSQLPlanner

DistSQLPlanner implements the JobExecContext interface.

func (*FakeJobExecContext) ExecCfg ¶

func (p *FakeJobExecContext) ExecCfg() *ExecutorConfig

ExecCfg implements the JobExecContext interface.

func (*FakeJobExecContext) ExtendedEvalContext ¶

func (p *FakeJobExecContext) ExtendedEvalContext() *extendedEvalContext

ExtendedEvalContext implements the JobExecContext interface.

func (*FakeJobExecContext) LeaseMgr ¶

func (p *FakeJobExecContext) LeaseMgr() *lease.Manager

LeaseMgr implements the JobExecContext interface.

func (*FakeJobExecContext) MigrationJobDeps ¶

func (p *FakeJobExecContext) MigrationJobDeps() migration.JobDeps

MigrationJobDeps implements the JobExecContext interface.

func (*FakeJobExecContext) SemaCtx ¶

func (p *FakeJobExecContext) SemaCtx() *tree.SemaContext

SemaCtx implements the JobExecContext interface.

func (*FakeJobExecContext) SessionData ¶

func (p *FakeJobExecContext) SessionData() *sessiondata.SessionData

SessionData implements the JobExecContext interface.

func (*FakeJobExecContext) SessionDataMutatorIterator ¶

func (p *FakeJobExecContext) SessionDataMutatorIterator() *sessionDataMutatorIterator

SessionDataMutatorIterator implements the JobExecContext interface.

func (*FakeJobExecContext) SpanConfigReconciler ¶

func (p *FakeJobExecContext) SpanConfigReconciler() spanconfig.Reconciler

SpanConfigReconciler implements the JobExecContext interface.

func (*FakeJobExecContext) User ¶

User implements the JobExecContext interface.

type Flush ¶

type Flush struct{}

Flush is a Command asking for the results of all previous commands to be delivered to the client.

func (Flush) String ¶

func (Flush) String() string

type FlushResult ¶

type FlushResult interface {
	ResultBase
}

FlushResult represents the result of a Flush command. When this result is closed, all previously accumulated results are flushed to the client.

type GCJobTestingKnobs ¶

type GCJobTestingKnobs struct {
	RunBeforeResume    func(jobID jobspb.JobID) error
	RunBeforePerformGC func(jobID jobspb.JobID) error
}

GCJobTestingKnobs is for testing the Schema Changer GC job. Note that this is defined here for testing purposes to avoid cyclic dependencies.

func (*GCJobTestingKnobs) ModuleTestingKnobs ¶

func (*GCJobTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.

type GrantRoleNode ¶

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

GrantRoleNode creates entries in the system.role_members table. This is called from GRANT <ROLE>

func (*GrantRoleNode) Close ¶

func (*GrantRoleNode) Close(context.Context)

Close implements the planNode interface.

func (*GrantRoleNode) Next ¶

func (*GrantRoleNode) Next(runParams) (bool, error)

Next implements the planNode interface.

func (*GrantRoleNode) Values ¶

func (*GrantRoleNode) Values() tree.Datums

Values implements the planNode interface.

type GuardrailMetrics ¶

type GuardrailMetrics struct {
	TxnRowsWrittenLogCount *metric.Counter
	TxnRowsWrittenErrCount *metric.Counter
	TxnRowsReadLogCount    *metric.Counter
	TxnRowsReadErrCount    *metric.Counter
}

GuardrailMetrics groups metrics related to different guardrails in the SQL layer.

func (GuardrailMetrics) MetricStruct ¶

func (GuardrailMetrics) MetricStruct()

MetricStruct is part of the metric.Struct interface.

type HasAdminRoleCache ¶

type HasAdminRoleCache struct {
	HasAdminRole bool

	// IsSet is used to determine if the value for caching is set or not.
	IsSet bool
}

HasAdminRoleCache is stored in extraTxnState and used to cache if the user has admin role throughout a transaction. This is used for admin audit logging to check if a transaction is being executed with admin privileges. HasAdminRoleCache does not have to be reset when a transaction restarts or roles back as the user's admin status will not change throughout the lifecycle of a single transaction.

type IndexBackfillPlanner ¶

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

IndexBackfillPlanner holds dependencies for an index backfiller for use in the declarative schema changer.

func NewIndexBackfiller ¶

func NewIndexBackfiller(
	execCfg *ExecutorConfig, ieFactory sqlutil.SessionBoundInternalExecutorFactory,
) *IndexBackfillPlanner

NewIndexBackfiller creates a new IndexBackfillPlanner.

func (*IndexBackfillPlanner) BackfillIndex ¶

func (ib *IndexBackfillPlanner) BackfillIndex(
	ctx context.Context,
	progress scexec.BackfillProgress,
	tracker scexec.BackfillProgressWriter,
	descriptor catalog.TableDescriptor,
) error

BackfillIndex is part of the scexec.Backfiller interface.

func (*IndexBackfillPlanner) MaybePrepareDestIndexesForBackfill ¶

func (ib *IndexBackfillPlanner) MaybePrepareDestIndexesForBackfill(
	ctx context.Context, current scexec.BackfillProgress, td catalog.TableDescriptor,
) (scexec.BackfillProgress, error)

MaybePrepareDestIndexesForBackfill is part of the scexec.Backfiller interface.

type IndexBackfillerMergePlanner ¶

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

IndexBackfillerMergePlanner holds dependencies for the merge step of the index backfiller.

func NewIndexBackfillerMergePlanner ¶

func NewIndexBackfillerMergePlanner(
	execCfg *ExecutorConfig, ieFactory sqlutil.SessionBoundInternalExecutorFactory,
) *IndexBackfillerMergePlanner

NewIndexBackfillerMergePlanner creates a new IndexBackfillerMergePlanner.

type IndexMergeTracker ¶

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

IndexMergeTracker abstracts the infrastructure to read and write merge progress to job state.

func NewIndexMergeTracker ¶

func NewIndexMergeTracker(progress *MergeProgress, job *jobs.Job) *IndexMergeTracker

NewIndexMergeTracker creates a new IndexMergeTracker

func (*IndexMergeTracker) FlushCheckpoint ¶

func (imt *IndexMergeTracker) FlushCheckpoint(ctx context.Context) error

FlushCheckpoint writes out a checkpoint containing any data which has been previously updated via UpdateMergeProgress.

func (*IndexMergeTracker) FlushFractionCompleted ¶

func (imt *IndexMergeTracker) FlushFractionCompleted(ctx context.Context) error

FlushFractionCompleted writes out the fraction completed.

func (*IndexMergeTracker) UpdateMergeProgress ¶

func (imt *IndexMergeTracker) UpdateMergeProgress(
	ctx context.Context, updateFn func(ctx context.Context, progress *MergeProgress),
)

UpdateMergeProgress allow the caller to modify the current progress with updateFn.

type InternalExecutor ¶

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

InternalExecutor can be used internally by code modules to execute SQL statements without needing to open a SQL connection.

InternalExecutor can execute one statement at a time. As of 03/2018, it doesn't offer a session interface for maintaining session state or for running explicit SQL transactions. However, it supports running SQL statements inside a higher-lever (KV) txn and inheriting session variables from another session.

Methods not otherwise specified are safe for concurrent execution.

func MakeInternalExecutor ¶

func MakeInternalExecutor(
	ctx context.Context, s *Server, memMetrics MemoryMetrics, settings *cluster.Settings,
) InternalExecutor

MakeInternalExecutor creates an InternalExecutor.

func (*InternalExecutor) Exec ¶

func (ie *InternalExecutor) Exec(
	ctx context.Context, opName string, txn *kv.Txn, stmt string, qargs ...interface{},
) (int, error)

Exec executes the supplied SQL statement and returns the number of rows affected (not like the results; see Query()). If no user has been previously set through SetSessionData, the statement is executed as the root user.

If txn is not nil, the statement will be executed in the respective txn.

Exec is deprecated because it may transparently execute a query as root. Use ExecEx instead.

func (*InternalExecutor) ExecEx ¶

func (ie *InternalExecutor) ExecEx(
	ctx context.Context,
	opName string,
	txn *kv.Txn,
	session sessiondata.InternalExecutorOverride,
	stmt string,
	qargs ...interface{},
) (int, error)

ExecEx is like Exec, but allows the caller to override some session data fields (e.g. the user).

The fields set in session that are set override the respective fields if they have previously been set through SetSessionData().

func (*InternalExecutor) QueryBuffered ¶

func (ie *InternalExecutor) QueryBuffered(
	ctx context.Context, opName string, txn *kv.Txn, stmt string, qargs ...interface{},
) ([]tree.Datums, error)

QueryBuffered executes the supplied SQL statement and returns the resulting rows (meaning all of them are buffered at once). If no user has been previously set through SetSessionData, the statement is executed as the root user.

If txn is not nil, the statement will be executed in the respective txn.

QueryBuffered is deprecated because it may transparently execute a query as root. Use QueryBufferedEx instead.

func (*InternalExecutor) QueryBufferedEx ¶

func (ie *InternalExecutor) QueryBufferedEx(
	ctx context.Context,
	opName string,
	txn *kv.Txn,
	session sessiondata.InternalExecutorOverride,
	stmt string,
	qargs ...interface{},
) ([]tree.Datums, error)

QueryBufferedEx executes the supplied SQL statement and returns the resulting rows (meaning all of them are buffered at once).

If txn is not nil, the statement will be executed in the respective txn.

The fields set in session that are set override the respective fields if they have previously been set through SetSessionData().

func (*InternalExecutor) QueryBufferedExWithCols ¶

func (ie *InternalExecutor) QueryBufferedExWithCols(
	ctx context.Context,
	opName string,
	txn *kv.Txn,
	session sessiondata.InternalExecutorOverride,
	stmt string,
	qargs ...interface{},
) ([]tree.Datums, colinfo.ResultColumns, error)

QueryBufferedExWithCols is like QueryBufferedEx, additionally returning the computed ResultColumns of the input query.

func (*InternalExecutor) QueryIterator ¶

func (ie *InternalExecutor) QueryIterator(
	ctx context.Context, opName string, txn *kv.Txn, stmt string, qargs ...interface{},
) (sqlutil.InternalRows, error)

QueryIterator executes the query, returning an iterator that can be used to get the results. If the call is successful, the returned iterator *must* be closed.

QueryIterator is deprecated because it may transparently execute a query as root. Use QueryIteratorEx instead.

func (*InternalExecutor) QueryIteratorEx ¶

func (ie *InternalExecutor) QueryIteratorEx(
	ctx context.Context,
	opName string,
	txn *kv.Txn,
	session sessiondata.InternalExecutorOverride,
	stmt string,
	qargs ...interface{},
) (sqlutil.InternalRows, error)

QueryIteratorEx executes the query, returning an iterator that can be used to get the results. If the call is successful, the returned iterator *must* be closed.

func (*InternalExecutor) QueryRow ¶

func (ie *InternalExecutor) QueryRow(
	ctx context.Context, opName string, txn *kv.Txn, stmt string, qargs ...interface{},
) (tree.Datums, error)

QueryRow is like Query, except it returns a single row, or nil if not row is found, or an error if more that one row is returned.

QueryRow is deprecated (like Query). Use QueryRowEx() instead.

func (*InternalExecutor) QueryRowEx ¶

func (ie *InternalExecutor) QueryRowEx(
	ctx context.Context,
	opName string,
	txn *kv.Txn,
	session sessiondata.InternalExecutorOverride,
	stmt string,
	qargs ...interface{},
) (tree.Datums, error)

QueryRowEx is like QueryRow, but allows the caller to override some session data fields (e.g. the user).

The fields set in session that are set override the respective fields if they have previously been set through SetSessionData().

func (*InternalExecutor) QueryRowExWithCols ¶

func (ie *InternalExecutor) QueryRowExWithCols(
	ctx context.Context,
	opName string,
	txn *kv.Txn,
	session sessiondata.InternalExecutorOverride,
	stmt string,
	qargs ...interface{},
) (tree.Datums, colinfo.ResultColumns, error)

QueryRowExWithCols is like QueryRowEx, additionally returning the computed ResultColumns of the input query.

func (*InternalExecutor) SetSessionData ¶

func (ie *InternalExecutor) SetSessionData(sessionData *sessiondata.SessionData)

SetSessionData binds the session variables that will be used by queries performed through this executor from now on. This creates a new session stack. It is recommended to use SetSessionDataStack.

SetSessionData cannot be called concurrently with query execution.

func (*InternalExecutor) WithSyntheticDescriptors ¶

func (ie *InternalExecutor) WithSyntheticDescriptors(
	descs []catalog.Descriptor, run func() error,
) error

WithSyntheticDescriptors sets the synthetic descriptors before running the the provided closure and resets them afterward. Used for queries/statements that need to use in-memory synthetic descriptors different from descriptors written to disk. These descriptors override all other descriptors on the immutable resolution path.

Warning: Not safe for concurrent use from multiple goroutines. This API is flawed in that the internal executor is meant to function as a stateless wrapper, and creates a new connExecutor and descs.Collection on each query/ statement, so these descriptors should really be specified at a per-query/ statement level. See #34304.

type InternalPlannerParamsOption ¶

type InternalPlannerParamsOption func(*internalPlannerParams)

InternalPlannerParamsOption is an option that can be passed to NewInternalPlanner.

func WithDescCollection ¶

func WithDescCollection(collection *descs.Collection) InternalPlannerParamsOption

WithDescCollection configures the planner with the provided collection instead of the default (creating a new one from scratch).

type InvalidIndexesError ¶

type InvalidIndexesError struct {
	Indexes []descpb.IndexID
}

InvalidIndexesError is used to represent indexes that failed revalidation.

func (InvalidIndexesError) Error ¶

func (e InvalidIndexesError) Error() string

type JobExecContext ¶

type JobExecContext interface {
	SemaCtx() *tree.SemaContext
	ExtendedEvalContext() *extendedEvalContext
	SessionData() *sessiondata.SessionData
	SessionDataMutatorIterator() *sessionDataMutatorIterator
	ExecCfg() *ExecutorConfig
	DistSQLPlanner() *DistSQLPlanner
	LeaseMgr() *lease.Manager
	User() security.SQLUsername
	MigrationJobDeps() migration.JobDeps
	SpanConfigReconciler() spanconfig.Reconciler
}

JobExecContext provides the execution environment for a job. It is what is passed to the Resume/OnFailOrCancel/OnPauseRequested methods of a jobs's Resumer to give that resumer access to things like ExecutorCfg, LeaseMgr, etc -- the kinds of things that would usually be on planner or similar during a non-job SQL statement's execution. Unlike a planner however, or planner-ish interfaces like PlanHookState, JobExecContext does not include a txn or the methods that defined in terms of "the" txn, such as privilege/name accessors. (though note that ExtendedEvalContext may transitively include methods that close over/expect a txn so use it with caution).

func MakeJobExecContext ¶

func MakeJobExecContext(
	opName string, user security.SQLUsername, memMetrics *MemoryMetrics, execCfg *ExecutorConfig,
) (JobExecContext, func())

MakeJobExecContext makes a JobExecContext.

type KVStringOptValidate ¶

type KVStringOptValidate string

KVStringOptValidate indicates the requested validation of a TypeAsStringOpts option.

const (
	KVStringOptAny            KVStringOptValidate = `any`
	KVStringOptRequireNoValue KVStringOptValidate = `no-value`
	KVStringOptRequireValue   KVStringOptValidate = `value`
)

KVStringOptValidate values

type LiveClusterRegions ¶

type LiveClusterRegions map[catpb.RegionName]struct{}

LiveClusterRegions is a set representing regions that are live in a given cluster.

func GetLiveClusterRegions ¶

func GetLiveClusterRegions(ctx context.Context, p PlanHookState) (LiveClusterRegions, error)

GetLiveClusterRegions returns a set of live region names in the cluster. A region name is deemed active if there is at least one alive node in the cluster in with locality set to a given region.

func (*LiveClusterRegions) IsActive ¶

func (s *LiveClusterRegions) IsActive(region catpb.RegionName) bool

IsActive returns whether the given region is a live region.

type LogEventDestination ¶

type LogEventDestination int

LogEventDestination indicates for InsertEventRecord where the event should be directed to.

const (
	// LogToSystemTable makes InsertEventRecord write one or more
	// entries to the system eventlog table. (This behavior may be
	// removed in a later version.)
	LogToSystemTable LogEventDestination = 1 << iota
	// LogExternally makes InsertEventRecord write the event(s) to the
	// external logs.
	LogExternally
	// LogToDevChannelIfVerbose makes InsertEventRecord copy
	// the structured event to the DEV logging channel
	// if the vmodule filter for the log call is set high enough.
	LogToDevChannelIfVerbose

	// LogEverywhere logs to all the possible outputs.
	LogEverywhere LogEventDestination = LogExternally | LogToSystemTable | LogToDevChannelIfVerbose
)

type MembershipCache ¶

type MembershipCache struct {
	syncutil.Mutex
	// contains filtered or unexported fields
}

MembershipCache is a shared cache for role membership information.

func NewMembershipCache ¶

func NewMembershipCache(account mon.BoundAccount, stopper *stop.Stopper) *MembershipCache

NewMembershipCache initializes a new MembershipCache.

type MemoryMetrics ¶

type MemoryMetrics struct {
	BaseMemoryMetrics
	TxnMaxBytesHist      *metric.Histogram
	TxnCurBytesCount     *metric.Gauge
	SessionMaxBytesHist  *metric.Histogram
	SessionCurBytesCount *metric.Gauge
}

MemoryMetrics contains pointers to the metrics object for one of the SQL endpoints: - "client" for connections received via pgwire. - "admin" for connections received via the admin RPC. - "internal" for activities related to leases, schema changes, etc.

func MakeMemMetrics ¶

func MakeMemMetrics(endpoint string, histogramWindow time.Duration) MemoryMetrics

MakeMemMetrics instantiates the metric objects for an SQL endpoint.

func (MemoryMetrics) MetricStruct ¶

func (MemoryMetrics) MetricStruct()

MetricStruct implements the metrics.Struct interface.

type MergeProgress ¶

type MergeProgress struct {
	// TodoSpans contains the all the spans for all the temporary
	// indexes that still need to be merged.
	TodoSpans [][]roachpb.Span

	// MutationIdx contains the indexes of the mutations for the
	// temporary indexes in the list of mutations.
	MutationIdx []int

	// AddedIndexes and TemporaryIndexes contain the index IDs for
	// all newly added indexes and their corresponding temporary
	// index.
	AddedIndexes, TemporaryIndexes []descpb.IndexID
}

MergeProgress tracks the progress for an index backfill merge.

func (*MergeProgress) Copy ¶

func (mp *MergeProgress) Copy() *MergeProgress

Copy returns a copy of this MergeProcess. Note that roachpb.Span's aren't deep copied.

type MetadataCallbackWriter ¶

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

MetadataCallbackWriter wraps a rowResultWriter to stream metadata in a DistSQL flow. It executes a given callback when metadata is added.

func NewMetadataCallbackWriter ¶

func NewMetadataCallbackWriter(
	rowResultWriter rowResultWriter,
	metaFn func(ctx context.Context, meta *execinfrapb.ProducerMetadata) error,
) *MetadataCallbackWriter

NewMetadataCallbackWriter creates a new MetadataCallbackWriter.

func (*MetadataCallbackWriter) AddMeta ¶

AddMeta implements the MetadataResultWriter interface.

type MetadataResultWriter ¶

type MetadataResultWriter interface {
	AddMeta(ctx context.Context, meta *execinfrapb.ProducerMetadata)
}

MetadataResultWriter is used to stream metadata rather than row results in a DistSQL flow.

type Metrics ¶

type Metrics struct {
	// EngineMetrics is exported as required by the metrics.Struct magic we use
	// for metrics registration.
	EngineMetrics EngineMetrics

	// StartedStatementCounters contains metrics for statements initiated by
	// users. These metrics count user-initiated operations, regardless of
	// success (in particular, TxnCommitCount is the number of COMMIT statements
	// attempted, not the number of transactions that successfully commit).
	StartedStatementCounters StatementCounters

	// ExecutedStatementCounters contains metrics for successfully executed
	// statements.
	ExecutedStatementCounters StatementCounters

	// GuardrailMetrics contains metrics related to different guardrails in the
	// SQL layer.
	GuardrailMetrics GuardrailMetrics
}

Metrics collects timeseries data about SQL activity.

type NewTableDescOption ¶

type NewTableDescOption func(o *newTableDescOptions)

NewTableDescOption is an option on NewTableDesc.

func NewTableDescOptionBypassLocalityOnNonMultiRegionDatabaseCheck ¶

func NewTableDescOptionBypassLocalityOnNonMultiRegionDatabaseCheck() NewTableDescOption

NewTableDescOptionBypassLocalityOnNonMultiRegionDatabaseCheck will allow LOCALITY on non multi-region tables.

type NodeInfo ¶

type NodeInfo struct {
	ClusterID func() uuid.UUID
	NodeID    *base.SQLIDContainer
	AdminURL  func() *url.URL
	PGURL     func(*url.Userinfo) (*pgurl.URL, error)
}

NodeInfo contains metadata about the executing node and cluster.

type NodeStatus ¶

type NodeStatus int

NodeStatus represents a node's health and compatibility in the context of physical planning for a query.

const (
	// NodeOK means that the node can be used for planning.
	NodeOK NodeStatus = iota
	// NodeUnhealthy means that the node should be avoided because
	// it's not healthy.
	NodeUnhealthy
	// NodeDistSQLVersionIncompatible means that the node should be avoided
	// because it's DistSQL version is not compatible.
	NodeDistSQLVersionIncompatible
)

func (NodeStatus) String ¶

func (i NodeStatus) String() string

type PGMetadataColumnDiff ¶

type PGMetadataColumnDiff struct {
	Oid              uint32 `json:"oid"`
	DataType         string `json:"dataType"`
	ExpectedOid      uint32 `json:"expectedOid"`
	ExpectedDataType string `json:"expectedDataType"`
}

PGMetadataColumnDiff describes diffs information for a column type. Fields are exported for marshaling purposes.

type PGMetadataColumnDiffs ¶

type PGMetadataColumnDiffs map[string]*PGMetadataColumnDiff

PGMetadataColumnDiffs maps column names to datatype diffs.

type PGMetadataColumnType ¶

type PGMetadataColumnType struct {
	Oid      uint32 `json:"oid"`
	DataType string `json:"dataType"`
}

PGMetadataColumnType represents a column type from postgres/mysql.

type PGMetadataColumns ¶

type PGMetadataColumns map[string]*PGMetadataColumnType

PGMetadataColumns maps columns names to datatypes.

type PGMetadataDiffFile ¶

type PGMetadataDiffFile struct {
	Version            string               `json:"version"`
	DiffSummary        Summary              `json:"diffSummary"`
	Diffs              PGMetadataTableDiffs `json:"diffs"`
	UnimplementedTypes map[oid.Oid]string   `json:"unimplementedTypes"`
}

PGMetadataDiffFile is used to store expected diffs or by the diff tool to validate a diff is an expected diff.

func (*PGMetadataDiffFile) Save ¶

func (df *PGMetadataDiffFile) Save(writer io.Writer)

Save stores the diff file in a JSON format.

type PGMetadataFile ¶

type PGMetadataFile struct {
	Version    string           `json:"version"`
	PGMetadata PGMetadataTables `json:"tables"`
}

PGMetadataFile stores the schema gotten from postgres/mysql.

func (*PGMetadataFile) Save ¶

func (f *PGMetadataFile) Save(writer io.Writer)

Save stores the table metadata in a JSON format.

type PGMetadataTableDiffs ¶

type PGMetadataTableDiffs map[string]PGMetadataColumnDiffs

PGMetadataTableDiffs is used to store and load expected diffs:

  • A table name pointing to a zero length PGMetadataColumnDiffs means that we expect this table to be missing in cockroach db.
  • If PGMetadataColumnDiffs is not empty but columnName points to null, we expect that column to be missing in that table in cockroach db.
  • If column Name points to a not null PGMetadataColumnDiff, the test column describes how we expect that data type to be different between cockroach db and postgres.

type PGMetadataTableInfo ¶

type PGMetadataTableInfo struct {
	ColumnNames []string          `json:"columnNames"`
	Columns     PGMetadataColumns `json:"columns"`
}

PGMetadataTableInfo represents a table with column mapping and column names in insertion order.

type PGMetadataTables ¶

type PGMetadataTables map[string]PGMetadataTableInfo

PGMetadataTables maps tables with columns.

func (PGMetadataTables) AddColumnMetadata ¶

func (p PGMetadataTables) AddColumnMetadata(
	tableName string, columnName string, dataType string, dataTypeOid uint32,
)

AddColumnMetadata is used to load data from postgres or cockroach pg_catalog schema

type PGShDependType ¶

type PGShDependType string

PGShDependType is an enumeration that lists pg_shdepend deptype column values

type PGWireTestingKnobs ¶

type PGWireTestingKnobs struct {
	// CatchPanics causes the pgwire.conn to recover from panics in its execution
	// thread and return them as errors to the client, closing the connection
	// afterward.
	CatchPanics bool

	// AuthHook is used to override the normal authentication handling on new
	// connections.
	AuthHook func(context.Context) error

	// AfterReadMsgTestingKnob is called after reading a message from the
	// pgwire read buffer.
	AfterReadMsgTestingKnob func(context.Context) error
}

PGWireTestingKnobs contains knobs for the pgwire module.

func (*PGWireTestingKnobs) ModuleTestingKnobs ¶

func (*PGWireTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs implements the base.ModuleTestingKnobs interface.

type ParseResult ¶

type ParseResult interface {
	ResultBase
}

ParseResult represents the result of a Parse command.

type PhysicalPlan ¶

type PhysicalPlan struct {
	physicalplan.PhysicalPlan

	// PlanToStreamColMap maps planNode columns (see planColumns()) to columns in
	// the result streams. These stream indices correspond to the streams
	// referenced in ResultTypes.
	//
	// Note that in some cases, not all columns in the result streams are
	// referenced in the map; for example, columns that are only required for
	// stream merges in downstream input synchronizers are not included here.
	// (This is due to some processors not being configurable to output only
	// certain columns and will be fixed.)
	//
	// Conversely, in some cases not all planNode columns have a corresponding
	// result stream column (these map to index -1); this is the case for scanNode
	// and indexJoinNode where not all columns in the table are actually used in
	// the plan, but are kept for possible use downstream (e.g., sorting).
	//
	// Before the query is run, the physical plan must be finalized, and during
	// the finalization a projection is added to the plan so that
	// DistSQLReceiver gets rows of the desired schema from the output
	// processor.
	PlanToStreamColMap []int
}

PhysicalPlan is a partial physical plan which corresponds to a planNode (partial in that it can correspond to a planNode subtree and not necessarily to the entire planNode for a given query).

It augments physicalplan.PhysicalPlan with information relating the physical plan to a planNode subtree.

These plans are built recursively on a planNode tree.

type PlanHookRowFn ¶

type PlanHookRowFn func(context.Context, []planNode, chan<- tree.Datums) error

PlanHookRowFn describes the row-production for hook-created plans. The channel argument is used to return results to the plan's runner. It's a blocking channel, so implementors should be careful to only use blocking sends on it when necessary. Any subplans returned by the hook when initially called are passed back, planned and started, for the RowFn's use.

TODO(dt): should this take runParams like a normal planNode.Next?

type PlanHookState ¶

type PlanHookState interface {
	resolver.SchemaResolver
	RunParams(ctx context.Context) runParams
	SemaCtx() *tree.SemaContext
	ExtendedEvalContext() *extendedEvalContext
	SessionData() *sessiondata.SessionData
	SessionDataMutatorIterator() *sessionDataMutatorIterator
	ExecCfg() *ExecutorConfig
	DistSQLPlanner() *DistSQLPlanner
	LeaseMgr() *lease.Manager
	TypeAsString(ctx context.Context, e tree.Expr, op string) (func() (string, error), error)
	TypeAsStringArray(ctx context.Context, e tree.Exprs, op string) (func() ([]string, error), error)
	TypeAsStringOpts(
		ctx context.Context, opts tree.KVOptions, optsValidate map[string]KVStringOptValidate,
	) (func() (map[string]string, error), error)
	User() security.SQLUsername
	AuthorizationAccessor
	// The role create/drop call into OSS code to reuse plan nodes.
	// TODO(mberhault): it would be easier to just pass a planner to plan hooks.
	GetAllRoles(ctx context.Context) (map[security.SQLUsername]bool, error)
	BumpRoleMembershipTableVersion(ctx context.Context) error
	EvalAsOfTimestamp(
		ctx context.Context,
		asOf tree.AsOfClause,
		opts ...tree.EvalAsOfTimestampOption,
	) (tree.AsOfSystemTime, error)
	ResolveMutableTableDescriptor(ctx context.Context, tn *tree.TableName, required bool, requiredType tree.RequiredTableKind) (prefix catalog.ResolvedObjectPrefix, table *tabledesc.Mutable, err error)
	ShowCreate(
		ctx context.Context, dbPrefix string, allDescs []descpb.Descriptor, desc catalog.TableDescriptor, displayOptions ShowCreateDisplayOptions,
	) (string, error)
	CreateSchemaNamespaceEntry(ctx context.Context, schemaNameKey roachpb.Key,
		schemaID descpb.ID) error
	MigrationJobDeps() migration.JobDeps
	SpanConfigReconciler() spanconfig.Reconciler
	BufferClientNotice(ctx context.Context, notice pgnotice.Notice)
	IsAutoCommit() bool
}

PlanHookState exposes the subset of planner needed by plan hooks. We pass this as one interface, rather than individually passing each field or interface as we find we need them, to avoid churn in the planHookFn sig and the hooks that implement it.

The PlanHookState is used by modules that are under the CCL. Since the OSS modules cannot depend on the CCL modules, the CCL modules need to inform the planner when they should be invoked (via plan hooks). The only way for the CCL statements to get access to a "planner" is through this PlanHookState that gets passed back due to this inversion of roles.

type PlanNode ¶

type PlanNode = planNode

PlanNode is the exported name for planNode. Useful for CCL hooks.

type PlanningCtx ¶

type PlanningCtx struct {
	ExtendedEvalCtx *extendedEvalContext

	// NodesStatuses contains info for all SQLInstanceIDs that are referenced by
	// any PhysicalPlan we generate with this context.
	NodeStatuses map[base.SQLInstanceID]NodeStatus
	// contains filtered or unexported fields
}

PlanningCtx contains data used and updated throughout the planning process of a single query.

func (*PlanningCtx) EvalContext ¶

func (p *PlanningCtx) EvalContext() *tree.EvalContext

EvalContext returns the associated EvalContext, or nil if there isn't one.

func (*PlanningCtx) IsLocal ¶

func (p *PlanningCtx) IsLocal() bool

IsLocal returns true if this PlanningCtx is being used to plan a query that has no remote flows.

func (*PlanningCtx) NewPhysicalPlan ¶

func (p *PlanningCtx) NewPhysicalPlan() *PhysicalPlan

NewPhysicalPlan creates an empty PhysicalPlan, backed by the PlanInfrastructure in the planning context.

Note that any processors created in the physical plan cannot be discarded; they have to be part of the final plan.

type PrepareStmt ¶

type PrepareStmt struct {
	// Name of the prepared statement (optional).
	Name string

	// Information returned from parsing: AST, SQL, NumPlaceholders.
	// Note that AST can be nil, in which case executing it should produce an
	// "empty query response" message.
	parser.Statement

	TypeHints tree.PlaceholderTypes
	// RawTypeHints is the representation of type hints exactly as specified by
	// the client.
	RawTypeHints []oid.Oid
	ParseStart   time.Time
	ParseEnd     time.Time
}

PrepareStmt is the command for creating a prepared statement.

func (PrepareStmt) String ¶

func (p PrepareStmt) String() string

type PreparedPortal ¶

type PreparedPortal struct {
	Stmt  *PreparedStatement
	Qargs tree.QueryArguments

	// OutFormats contains the requested formats for the output columns.
	OutFormats []pgwirebase.FormatCode
	// contains filtered or unexported fields
}

PreparedPortal is a PreparedStatement that has been bound with query arguments.

type PreparedStatement ¶

type PreparedStatement struct {
	querycache.PrepareMetadata

	// Memo is the memoized data structure constructed by the cost-based optimizer
	// during prepare of a SQL statement. It can significantly speed up execution
	// if it is used by the optimizer as a starting point.
	Memo *memo.Memo

	StatementSummary string
	// contains filtered or unexported fields
}

PreparedStatement is a SQL statement that has been parsed and the types of arguments and results have been determined.

Note that PreparedStatements maintain a reference counter internally. References need to be registered with incRef() and de-registered with decRef().

func (*PreparedStatement) MemoryEstimate ¶

func (p *PreparedStatement) MemoryEstimate() int64

MemoryEstimate returns a rough estimate of the PreparedStatement's memory usage, in bytes.

type PreparedStatementOrigin ¶

type PreparedStatementOrigin int

PreparedStatementOrigin is an enum representing the source of where the prepare statement was made.

const (
	// PreparedStatementOriginWire signifies the prepared statement was made
	// over the wire.
	PreparedStatementOriginWire PreparedStatementOrigin = iota + 1
	// PreparedStatementOriginSQL signifies the prepared statement was made
	// over a parsed SQL query.
	PreparedStatementOriginSQL
	// PreparedStatementOriginSessionMigration signifies that the prepared
	// statement came from a call to crdb_internal.deserialize_session.
	PreparedStatementOriginSessionMigration
)

type ReqOrdering ¶

type ReqOrdering = colinfo.ColumnOrdering

ReqOrdering is the ordering that must be preserved by an operator when it is distributed. It is used to configure DistSQL with the orderings it needs to maintain when joining streams.

type RestrictedCommandResult ¶

type RestrictedCommandResult interface {
	CommandResultErrBase

	// BufferParamStatusUpdate buffers a parameter status update to the result.
	// This gets flushed only when the CommandResult is closed.
	BufferParamStatusUpdate(string, string)

	// BufferNotice appends a notice to the result.
	// This gets flushed only when the CommandResult is closed.
	BufferNotice(notice pgnotice.Notice)

	// SetColumns informs the client about the schema of the result. The columns
	// can be nil.
	//
	// This needs to be called (once) before AddRow.
	SetColumns(context.Context, colinfo.ResultColumns)

	// ResetStmtType allows a client to change the statement type of the current
	// result, from the original one set when the result was created trough
	// ClientComm.createStatementResult.
	ResetStmtType(stmt tree.Statement)

	// AddRow accumulates a result row.
	//
	// The implementation cannot hold on to the row slice; it needs to make a
	// shallow copy if it needs to.
	AddRow(ctx context.Context, row tree.Datums) error

	// AddBatch accumulates a result batch.
	//
	// The implementation cannot hold on to the contents of the batch without
	// deeply copying them. The memory in the input batch is safe to modify as
	// soon as AddBatch returns.
	AddBatch(ctx context.Context, batch coldata.Batch) error

	// SupportsAddBatch returns whether this command result supports AddBatch
	// method of adding the data. If false is returned, then the behavior of
	// AddBatch is undefined.
	SupportsAddBatch() bool

	// IncrementRowsAffected increments a counter by n. This is used for all
	// result types other than tree.Rows.
	IncrementRowsAffected(ctx context.Context, n int)

	// RowsAffected returns either the number of times AddRow was called, or the
	// sum of all n passed into IncrementRowsAffected.
	RowsAffected() int

	// DisableBuffering can be called during execution to ensure that
	// the results accumulated so far, and all subsequent rows added
	// to this CommandResult, will be flushed immediately to the client.
	// This is currently used for sinkless changefeeds.
	DisableBuffering()
}

RestrictedCommandResult is a subset of CommandResult meant to make it clear that its clients don't close the CommandResult.

type ResultBase ¶

type ResultBase interface {
	CommandResultErrBase
	CommandResultClose
}

ResultBase is the common interface implemented by all the different command results.

type RevokeRoleNode ¶

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

RevokeRoleNode removes entries from the system.role_members table. This is called from REVOKE <ROLE>

func (*RevokeRoleNode) Close ¶

func (*RevokeRoleNode) Close(context.Context)

Close implements the planNode interface.

func (*RevokeRoleNode) Next ¶

func (*RevokeRoleNode) Next(runParams) (bool, error)

Next implements the planNode interface.

func (*RevokeRoleNode) Values ¶

func (*RevokeRoleNode) Values() tree.Datums

Values implements the planNode interface.

type RewriteEvTypes ¶

type RewriteEvTypes string

RewriteEvTypes could be a enumeration if rewrite rules gets implemented

type RowDescOpt ¶

type RowDescOpt bool

RowDescOpt specifies whether a result needs a row description message.

const (
	// NeedRowDesc specifies that a row description message is needed.
	NeedRowDesc RowDescOpt = false
	// DontNeedRowDesc specifies that a row description message is not needed.
	DontNeedRowDesc RowDescOpt = true
)

type RowResultWriter ¶

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

RowResultWriter is a thin wrapper around a RowContainer.

func NewRowResultWriter ¶

func NewRowResultWriter(rowContainer *rowContainerHelper) *RowResultWriter

NewRowResultWriter creates a new RowResultWriter.

func (*RowResultWriter) AddRow ¶

func (b *RowResultWriter) AddRow(ctx context.Context, row tree.Datums) error

AddRow implements the rowResultWriter interface.

func (*RowResultWriter) Err ¶

func (b *RowResultWriter) Err() error

Err is part of the rowResultWriter interface.

func (*RowResultWriter) IncrementRowsAffected ¶

func (b *RowResultWriter) IncrementRowsAffected(ctx context.Context, n int)

IncrementRowsAffected implements the rowResultWriter interface.

func (*RowResultWriter) SetError ¶

func (b *RowResultWriter) SetError(err error)

SetError is part of the rowResultWriter interface.

type SchemaChanger ¶

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

SchemaChanger is used to change the schema on a table.

func NewSchemaChangerForTesting ¶

func NewSchemaChangerForTesting(
	tableID descpb.ID,
	mutationID descpb.MutationID,
	sqlInstanceID base.SQLInstanceID,
	db *kv.DB,
	leaseMgr *lease.Manager,
	jobRegistry *jobs.Registry,
	execCfg *ExecutorConfig,
	settings *cluster.Settings,
) SchemaChanger

NewSchemaChangerForTesting only for tests.

func (*SchemaChanger) RunStateMachineAfterIndexBackfill ¶

func (sc *SchemaChanger) RunStateMachineAfterIndexBackfill(ctx context.Context) error

RunStateMachineAfterIndexBackfill moves the state machine forward and wait to ensure that all nodes are seeing the latest version of the table.

Adding Mutations in BACKFILLING state move through DELETE -> MERGING.

func (*SchemaChanger) RunStateMachineBeforeBackfill ¶

func (sc *SchemaChanger) RunStateMachineBeforeBackfill(ctx context.Context) error

RunStateMachineBeforeBackfill moves the state machine forward and wait to ensure that all nodes are seeing the latest version of the table.

type SchemaChangerMetrics ¶

type SchemaChangerMetrics struct {
	RunningSchemaChanges *metric.Gauge
	Successes            *metric.Counter
	RetryErrors          *metric.Counter
	PermanentErrors      *metric.Counter
	ConstraintErrors     telemetry.Counter
	UncategorizedErrors  telemetry.Counter
}

SchemaChangerMetrics are metrics corresponding to the schema changer.

func NewSchemaChangerMetrics ¶

func NewSchemaChangerMetrics() *SchemaChangerMetrics

NewSchemaChangerMetrics constructs a new SchemaChangerMetrics.

func (*SchemaChangerMetrics) MetricStruct ¶

func (s *SchemaChangerMetrics) MetricStruct()

MetricStruct makes SchemaChangerMetrics a metric.Struct.

type SchemaChangerState ¶

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

SchemaChangerState is state associated with the new schema changer.

type SchemaChangerTestingKnobs ¶

type SchemaChangerTestingKnobs struct {
	// SchemaChangeJobNoOp returning true will cause the job to be a no-op.
	SchemaChangeJobNoOp func() bool

	// RunBeforePublishWriteAndDelete is called just before publishing the
	// write+delete state for the schema change.
	RunBeforePublishWriteAndDelete func()

	// RunBeforeBackfill is called just before starting the backfill.
	RunBeforeBackfill func() error

	// RunAfterBackfill is called after completing a backfill.
	RunAfterBackfill func(jobID jobspb.JobID) error

	// RunBeforeQueryBackfill is called before a query based backfill.
	RunBeforeQueryBackfill func() error

	// RunBeforeIndexBackfill is called just before starting the index backfill, after
	// fixing the index backfill scan timestamp.
	RunBeforeIndexBackfill func()

	// RunBeforeIndexBackfill is called after the index backfill
	// process is complete (including the temporary index merge)
	// but before the final validation of the indexes.
	RunAfterIndexBackfill func()

	// RunBeforeTempIndexMerge is called just before starting the
	// the merge from the temporary index into the new index,
	// after the backfill scan timestamp has been fixed.
	RunBeforeTempIndexMerge func()

	// RunAfterTempIndexMerge is called, before validating and
	// making the next index public.
	RunAfterTempIndexMerge func()

	// RunBeforeMaterializedViewRefreshCommit is called before committing a
	// materialized view refresh.
	RunBeforeMaterializedViewRefreshCommit func() error

	// RunBeforePrimaryKeySwap is called just before the primary key swap is committed.
	RunBeforePrimaryKeySwap func()

	// RunBeforeComputedColumnSwap is called just before the computed column swap is committed.
	RunBeforeComputedColumnSwap func()

	// RunBeforeIndexValidation is called just before starting the index validation,
	// after setting the job status to validating.
	RunBeforeIndexValidation func() error

	// RunBeforeConstraintValidation is called just before starting the checks validation,
	// after setting the job status to validating.
	RunBeforeConstraintValidation func(constraints []catalog.ConstraintToUpdate) error

	// RunBeforeMutationReversal runs at the beginning of maybeReverseMutations.
	RunBeforeMutationReversal func(jobID jobspb.JobID) error

	// RunAfterMutationReversal runs in OnFailOrCancel after the mutations have
	// been reversed.
	RunAfterMutationReversal func(jobID jobspb.JobID) error

	// RunAtStartOfOnFailOrCancel runs at the start of the OnFailOrCancel hook.
	RunBeforeOnFailOrCancel func(jobID jobspb.JobID) error

	// RunAfterOnFailOrCancel runs after the OnFailOrCancel hook.
	RunAfterOnFailOrCancel func(jobID jobspb.JobID) error

	// RunBeforeResume runs at the start of the Resume hook.
	RunBeforeResume func(jobID jobspb.JobID) error

	// RunBeforeDescTxn runs at the start of every call to
	// (*schemaChanger).txn.
	RunBeforeDescTxn func(jobID jobspb.JobID) error

	// OldNamesDrainedNotification is called during a schema change,
	// after all leases on the version of the descriptor with the old
	// names are gone, and just before the mapping of the old names to the
	// descriptor id are about to be deleted.
	OldNamesDrainedNotification func()

	// WriteCheckpointInterval is the interval after which a checkpoint is
	// written.
	WriteCheckpointInterval time.Duration

	// BackfillChunkSize is to be used for all backfill chunked operations.
	BackfillChunkSize int64

	// AlwaysUpdateIndexBackfillDetails indicates whether the index backfill
	// schema change job details should be updated everytime the coordinator
	// receives an update from the backfill processor.
	AlwaysUpdateIndexBackfillDetails bool

	// AlwaysUpdateIndexBackfillProgress indicates whether the index backfill
	// schema change job fraction completed should be updated everytime the
	// coordinator receives an update from the backfill processor.
	AlwaysUpdateIndexBackfillProgress bool

	// TwoVersionLeaseViolation is called whenever a schema change transaction is
	// unable to commit because it is violating the two version lease invariant.
	TwoVersionLeaseViolation func()

	// RunBeforeHashShardedIndexRangePreSplit is called before pre-splitting index
	// ranges for hash sharded index.
	RunBeforeHashShardedIndexRangePreSplit func(tbl *tabledesc.Mutable, kbDB *kv.DB, codec keys.SQLCodec) error

	// RunAfterHashShardedIndexRangePreSplit is called after index ranges
	// pre-splitting is done for hash sharded index.
	RunAfterHashShardedIndexRangePreSplit func(tbl *tabledesc.Mutable, kbDB *kv.DB, codec keys.SQLCodec) error

	// RunBeforeModifyRowLevelTTL is called just before the modify row level TTL is committed.
	RunBeforeModifyRowLevelTTL func() error
}

SchemaChangerTestingKnobs for testing the schema change execution path through both the synchronous and asynchronous paths.

func (*SchemaChangerTestingKnobs) ModuleTestingKnobs ¶

func (*SchemaChangerTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.

type SendError ¶

type SendError struct {
	// Err is a *pgerror.Error.
	Err error
}

SendError is a command that, upon execution, send a specific error to the client. This is used by pgwire to schedule errors to be sent at an appropriate time.

func (SendError) String ¶

func (s SendError) String() string

type Server ¶

type Server struct {

	// Metrics is used to account normal queries.
	Metrics Metrics

	// InternalMetrics is used to account internal queries.
	InternalMetrics Metrics

	// ServerMetrics is used to account for Server activities that are unrelated to
	// query planning and execution.
	ServerMetrics ServerMetrics

	// TelemetryLoggingMetrics is used to track metrics for logging to the telemetry channel.
	TelemetryLoggingMetrics *TelemetryLoggingMetrics
	// contains filtered or unexported fields
}

Server is the top level singleton for handling SQL connections. It creates connExecutors to server every incoming connection.

func NewServer ¶

func NewServer(cfg *ExecutorConfig, pool *mon.BytesMonitor) *Server

NewServer creates a new Server. Start() needs to be called before the Server is used.

func (*Server) DecrementConnectionCount ¶

func (s *Server) DecrementConnectionCount()

DecrementConnectionCount decreases connectionCount by 1.

func (*Server) GetConnectionCount ¶

func (s *Server) GetConnectionCount() int64

GetConnectionCount returns the current number of connections.

func (*Server) GetExecutorConfig ¶

func (s *Server) GetExecutorConfig() *ExecutorConfig

GetExecutorConfig returns this server's executor config.

func (*Server) GetIndexUsageStatsController ¶

func (s *Server) GetIndexUsageStatsController() *idxusage.Controller

GetIndexUsageStatsController returns the idxusage.Controller for current sql.Server's index usage stats.

func (*Server) GetLocalIndexStatistics ¶

func (s *Server) GetLocalIndexStatistics() *idxusage.LocalIndexUsageStats

GetLocalIndexStatistics returns a idxusage.LocalIndexUsageStats.

func (*Server) GetReportedSQLStatsController ¶

func (s *Server) GetReportedSQLStatsController() *sslocal.Controller

GetReportedSQLStatsController returns the sqlstats.Controller for the current sql.Server's reported SQL Stats.

func (*Server) GetSQLStatsController ¶

func (s *Server) GetSQLStatsController() *persistedsqlstats.Controller

GetSQLStatsController returns the persistedsqlstats.Controller for current sql.Server's SQL Stats.

func (*Server) GetSQLStatsProvider ¶

func (s *Server) GetSQLStatsProvider() sqlstats.Provider

GetSQLStatsProvider returns the provider for the sqlstats subsystem.

func (*Server) GetScrubbedReportingStats ¶

func (s *Server) GetScrubbedReportingStats(
	ctx context.Context,
) ([]roachpb.CollectedStatementStatistics, error)

GetScrubbedReportingStats does the same thing as GetScrubbedStmtStats but returns statistics from the reported stats pool.

func (*Server) GetScrubbedStmtStats ¶

func (s *Server) GetScrubbedStmtStats(
	ctx context.Context,
) ([]roachpb.CollectedStatementStatistics, error)

GetScrubbedStmtStats returns the statement statistics by app, with the queries scrubbed of their identifiers. Any statements which cannot be scrubbed will be omitted from the returned map.

func (*Server) GetStmtStatsLastReset ¶

func (s *Server) GetStmtStatsLastReset() time.Time

GetStmtStatsLastReset returns the time at which the statement statistics were last cleared.

func (*Server) GetTxnIDCache ¶

func (s *Server) GetTxnIDCache() *txnidcache.Cache

GetTxnIDCache returns the txnidcache.Cache for the current sql.Server.

func (*Server) GetUnscrubbedStmtStats ¶

func (s *Server) GetUnscrubbedStmtStats(
	ctx context.Context,
) ([]roachpb.CollectedStatementStatistics, error)

GetUnscrubbedStmtStats returns the same thing as GetScrubbedStmtStats, except identifiers (e.g. table and column names) aren't scrubbed from the statements.

func (*Server) GetUnscrubbedTxnStats ¶

func (s *Server) GetUnscrubbedTxnStats(
	ctx context.Context,
) ([]roachpb.CollectedTransactionStatistics, error)

GetUnscrubbedTxnStats returns the same transaction statistics by app. Identifiers (e.g. table and column names) aren't scrubbed from the statements.

func (*Server) IncrementConnectionCount ¶

func (s *Server) IncrementConnectionCount()

IncrementConnectionCount increases connectionCount by 1.

func (*Server) IncrementConnectionCountIfLessThan ¶

func (s *Server) IncrementConnectionCountIfLessThan(max int64) bool

IncrementConnectionCountIfLessThan increases connectionCount by and returns true if allowedConnectionCount < max, otherwise it does nothing and returns false.

func (*Server) ServeConn ¶

func (s *Server) ServeConn(
	ctx context.Context, h ConnectionHandler, reserved mon.BoundAccount, cancel context.CancelFunc,
) error

ServeConn serves a client connection by reading commands from the stmtBuf embedded in the ConnHandler.

If not nil, reserved represents memory reserved for the connection. The connExecutor takes ownership of this memory.

func (*Server) SetupConn ¶

func (s *Server) SetupConn(
	ctx context.Context,
	args SessionArgs,
	stmtBuf *StmtBuf,
	clientComm ClientComm,
	memMetrics MemoryMetrics,
	onDefaultIntSizeChange func(newSize int32),
) (ConnectionHandler, error)

SetupConn creates a connExecutor for the client connection.

When this method returns there are no resources allocated yet that need to be close()d.

Args: args: The initial session parameters. They are validated by SetupConn

and an error is returned if this validation fails.

stmtBuf: The incoming statement for the new connExecutor. clientComm: The interface through which the new connExecutor is going to

produce results for the client.

memMetrics: The metrics that statements executed on this connection will

contribute to.

func (*Server) Start ¶

func (s *Server) Start(ctx context.Context, stopper *stop.Stopper)

Start starts the Server's background processing.

type ServerMetrics ¶

type ServerMetrics struct {
	// StatsMetrics contains metrics for SQL statistics collection.
	StatsMetrics StatsMetrics

	// ContentionSubsystemMetrics contains metrics related to contention
	// subsystem.
	ContentionSubsystemMetrics txnidcache.Metrics
}

ServerMetrics collects timeseries data about Server activities that are unrelated to SQL planning and execution.

type SessionArgs ¶

type SessionArgs struct {
	User                        security.SQLUsername
	IsSuperuser                 bool
	SessionDefaults             SessionDefaults
	CustomOptionSessionDefaults SessionDefaults
	// RemoteAddr is the client's address. This is nil iff this is an internal
	// client.
	RemoteAddr            net.Addr
	ConnResultsBufferSize int64
	// SessionRevivalToken may contain a token generated from a different session
	// that can be used to authenticate this session. If it is set, all other
	// authentication is skipped. Once the token is used to authenticate, this
	// value should be zeroed out.
	SessionRevivalToken []byte
}

SessionArgs contains arguments for serving a client connection.

type SessionDefaults ¶

type SessionDefaults map[string]string

SessionDefaults mirrors fields in Session, for restoring default configuration values in SET ... TO DEFAULT (or RESET ...) statements.

type SessionRegistry ¶

type SessionRegistry struct {
	syncutil.Mutex
	// contains filtered or unexported fields
}

SessionRegistry stores a set of all sessions on this node. Use register() and deregister() to modify this registry.

func NewSessionRegistry ¶

func NewSessionRegistry() *SessionRegistry

NewSessionRegistry creates a new SessionRegistry with an empty set of sessions.

func (*SessionRegistry) CancelQuery ¶

func (r *SessionRegistry) CancelQuery(queryIDStr string) (bool, error)

CancelQuery looks up the associated query in the session registry and cancels it. The caller is responsible for all permission checks.

func (*SessionRegistry) CancelQueryByKey ¶

func (r *SessionRegistry) CancelQueryByKey(
	queryCancelKey pgwirecancel.BackendKeyData,
) (canceled bool, err error)

CancelQueryByKey looks up the associated query in the session registry and cancels it.

func (*SessionRegistry) CancelSession ¶

func (r *SessionRegistry) CancelSession(
	sessionIDBytes []byte,
) (*serverpb.CancelSessionResponse, error)

CancelSession looks up the specified session in the session registry and cancels it. The caller is responsible for all permission checks.

func (*SessionRegistry) SerializeAll ¶

func (r *SessionRegistry) SerializeAll() []serverpb.Session

SerializeAll returns a slice of all sessions in the registry, converted to serverpb.Sessions.

type SessionTracing ¶

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

SessionTracing holds the state used by SET TRACING statements in the context of one SQL session. It holds the current trace being collected (or the last trace collected, if tracing is not currently ongoing).

SessionTracing and its interactions with the connExecutor are thread-safe; tracing can be turned on at any time.

func (*SessionTracing) Enabled ¶

func (st *SessionTracing) Enabled() bool

Enabled checks whether session tracing is currently enabled.

func (*SessionTracing) KVTracingEnabled ¶

func (st *SessionTracing) KVTracingEnabled() bool

KVTracingEnabled checks whether KV tracing is currently enabled.

func (*SessionTracing) StartTracing ¶

func (st *SessionTracing) StartTracing(
	recType tracing.RecordingType, kvTracingEnabled, showResults bool,
) error

StartTracing starts "session tracing". From this moment on, everything happening on both the connection's context and the current txn's context (if any) will be traced. StopTracing() needs to be called to finish this trace.

There's two contexts on which we must record: 1) If we're inside a txn, we start recording on the txn's span. We assume that the txn's ctx has a recordable span on it. 2) Regardless of whether we're in a txn or not, we need to record the connection's context. This context generally does not have a span, so we "hijack" it with one that does. Whatever happens on that context, plus whatever happens in future derived txn contexts, will be recorded.

Args: kvTracingEnabled: If set, the traces will also include "KV trace" messages -

verbose messages around the interaction of SQL with KV. Some of the messages
are per-row.

showResults: If set, result rows are reported in the trace.

func (*SessionTracing) StopTracing ¶

func (st *SessionTracing) StopTracing() error

StopTracing stops the trace that was started with StartTracing().

func (*SessionTracing) TraceExecBatchResult ¶

func (st *SessionTracing) TraceExecBatchResult(ctx context.Context, batch coldata.Batch)

TraceExecBatchResult conditionally emits a trace message for a single batch.

func (*SessionTracing) TraceExecConsume ¶

func (st *SessionTracing) TraceExecConsume(ctx context.Context) (context.Context, func())

TraceExecConsume creates a context for TraceExecRowsResult below.

func (*SessionTracing) TraceExecEnd ¶

func (st *SessionTracing) TraceExecEnd(ctx context.Context, err error, count int)

TraceExecEnd conditionally emits a trace message at the moment plan execution completes.

func (*SessionTracing) TraceExecRowsResult ¶

func (st *SessionTracing) TraceExecRowsResult(ctx context.Context, values tree.Datums)

TraceExecRowsResult conditionally emits a trace message for a single output row.

func (*SessionTracing) TraceExecStart ¶

func (st *SessionTracing) TraceExecStart(ctx context.Context, engine string)

TraceExecStart conditionally emits a trace message at the moment plan execution starts.

func (*SessionTracing) TracePlanCheckEnd ¶

func (st *SessionTracing) TracePlanCheckEnd(ctx context.Context, err error, dist bool)

TracePlanCheckEnd conditionally emits a trace message at the moment the engine check ends.

func (*SessionTracing) TracePlanCheckStart ¶

func (st *SessionTracing) TracePlanCheckStart(ctx context.Context)

TracePlanCheckStart conditionally emits a trace message at the moment the test of which execution engine to use starts.

func (*SessionTracing) TracePlanEnd ¶

func (st *SessionTracing) TracePlanEnd(ctx context.Context, err error)

TracePlanEnd conditionally emits a trace message at the moment logical planning ends.

func (*SessionTracing) TracePlanStart ¶

func (st *SessionTracing) TracePlanStart(ctx context.Context, stmtTag string)

TracePlanStart conditionally emits a trace message at the moment logical planning starts.

func (*SessionTracing) TraceRetryInformation ¶

func (st *SessionTracing) TraceRetryInformation(ctx context.Context, retries int, err error)

TraceRetryInformation conditionally emits a trace message for retry information.

type ShowCreateDisplayOptions ¶

type ShowCreateDisplayOptions struct {
	FKDisplayMode shouldOmitFKClausesFromCreate
	// Comment resolution requires looking up table data from system.comments
	// table. This is sometimes not possible. For example, in the context of a
	// SHOW BACKUP which may resolve the create statement, there is no mechanism
	// to read any table data from the backup (nor is there a guarantee that the
	// system.comments table is included in the backup at all).
	IgnoreComments bool
}

ShowCreateDisplayOptions is a container struct holding the options that ShowCreate uses to determine how much information should be included in the CREATE statement.

type SpanPartition ¶

type SpanPartition struct {
	SQLInstanceID base.SQLInstanceID
	Spans         roachpb.Spans
}

SpanPartition associates a subset of spans with a specific SQL instance, chosen to have the most efficient access to those spans. In the single-tenant case, the instance is the one running on the same node as the leaseholder for those spans.

type Statement ¶

type Statement struct {
	parser.Statement

	StmtNoConstants string
	StmtSummary     string
	QueryID         ClusterWideID

	ExpectedTypes colinfo.ResultColumns

	// Prepared is non-nil during the PREPARE phase, as well as during EXECUTE of
	// a previously prepared statement. The Prepared statement can be modified
	// during either phase; the PREPARE phase sets its initial state, and the
	// EXECUTE phase can re-prepare it. This happens when the original plan has
	// been invalidated by schema changes, session data changes, permission
	// changes, or other changes to the context in which the original plan was
	// prepared.
	//
	// Given that the PreparedStatement can be modified during planning, it is
	// not safe for use on multiple threads.
	Prepared *PreparedStatement
}

Statement contains a statement with optional expected result columns and metadata.

func (Statement) String ¶

func (s Statement) String() string

type StatementCounters ¶

type StatementCounters struct {
	// QueryCount includes all statements and it is therefore the sum of
	// all the below metrics.
	QueryCount telemetry.CounterWithMetric

	// Basic CRUD statements.
	SelectCount telemetry.CounterWithMetric
	UpdateCount telemetry.CounterWithMetric
	InsertCount telemetry.CounterWithMetric
	DeleteCount telemetry.CounterWithMetric

	// Transaction operations.
	TxnBeginCount    telemetry.CounterWithMetric
	TxnCommitCount   telemetry.CounterWithMetric
	TxnRollbackCount telemetry.CounterWithMetric

	// Savepoint operations. SavepointCount is for real SQL savepoints;
	// the RestartSavepoint variants are for the
	// cockroach-specific client-side retry protocol.
	SavepointCount                  telemetry.CounterWithMetric
	ReleaseSavepointCount           telemetry.CounterWithMetric
	RollbackToSavepointCount        telemetry.CounterWithMetric
	RestartSavepointCount           telemetry.CounterWithMetric
	ReleaseRestartSavepointCount    telemetry.CounterWithMetric
	RollbackToRestartSavepointCount telemetry.CounterWithMetric

	// CopyCount counts all COPY statements.
	CopyCount telemetry.CounterWithMetric

	// DdlCount counts all statements whose StatementReturnType is DDL.
	DdlCount telemetry.CounterWithMetric

	// MiscCount counts all statements not covered by a more specific stat above.
	MiscCount telemetry.CounterWithMetric
}

StatementCounters groups metrics for counting different types of statements.

type StatementFilter ¶

type StatementFilter func(context.Context, *sessiondata.SessionData, string, error)

StatementFilter is the type of callback that ExecutorTestingKnobs.StatementFilter takes.

type StatsMetrics ¶

type StatsMetrics struct {
	SQLStatsMemoryMaxBytesHist  *metric.Histogram
	SQLStatsMemoryCurBytesCount *metric.Gauge

	ReportedSQLStatsMemoryMaxBytesHist  *metric.Histogram
	ReportedSQLStatsMemoryCurBytesCount *metric.Gauge

	DiscardedStatsCount *metric.Counter

	SQLStatsFlushStarted  *metric.Counter
	SQLStatsFlushFailure  *metric.Counter
	SQLStatsFlushDuration *metric.Histogram
	SQLStatsRemovedRows   *metric.Counter

	SQLTxnStatsCollectionOverhead *metric.Histogram
}

StatsMetrics groups metrics related to SQL Stats collection.

func (StatsMetrics) MetricStruct ¶

func (StatsMetrics) MetricStruct()

MetricStruct is part of the metric.Struct interface.

type StmtBuf ¶

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

StmtBuf maintains a list of commands that a SQL client has sent for execution over a network connection. The commands are SQL queries to be executed, statements to be prepared, etc. At any point in time the buffer contains outstanding commands that have yet to be executed, and it can also contain some history of commands that we might want to retry - in the case of a retriable error, we'd like to retry all the commands pertaining to the current SQL transaction.

The buffer is supposed to be used by one reader and one writer. The writer adds commands to the buffer using Push(). The reader reads one command at a time using CurCmd(). The consumer is then supposed to create command results (the buffer is not involved in this). The buffer internally maintains a cursor representing the reader's position. The reader has to manually move the cursor using AdvanceOne(), seekToNextBatch() and rewind(). In practice, the writer is a module responsible for communicating with a SQL client (i.e. pgwire.conn) and the reader is a connExecutor.

The StmtBuf supports grouping commands into "batches" delimited by sync commands. A reader can then at any time chose to skip over commands from the current batch. This is used to implement Postgres error semantics: when an error happens during processing of a command, some future commands might need to be skipped. Batches correspond either to multiple queries received in a single query string (when the SQL client sends a semicolon-separated list of queries as part of the "simple" protocol), or to different commands pipelined by the cliend, separated from "sync" messages.

push() can be called concurrently with CurCmd().

The connExecutor will use the buffer to maintain a window around the command it is currently executing. It will maintain enough history for executing commands again in case of an automatic retry. The connExecutor is in charge of trimming completed commands from the buffer when it's done with them.

func NewStmtBuf ¶

func NewStmtBuf() *StmtBuf

NewStmtBuf creates a StmtBuf.

func (*StmtBuf) AdvanceOne ¶

func (buf *StmtBuf) AdvanceOne() CmdPos

AdvanceOne advances the cursor one Command over. The command over which the cursor will be positioned when this returns may not be in the buffer yet. The previous CmdPos is returned.

func (*StmtBuf) Close ¶

func (buf *StmtBuf) Close()

Close marks the buffer as closed. Once Close() is called, no further push()es are allowed. If a reader is blocked on a CurCmd() call, it is unblocked with io.EOF. Any further CurCmd() call also returns io.EOF (even if some commands were already available in the buffer before the Close()).

Close() is idempotent.

func (*StmtBuf) CurCmd ¶

func (buf *StmtBuf) CurCmd() (Command, CmdPos, error)

CurCmd returns the Command currently indicated by the cursor. Besides the Command itself, the command's position is also returned; the position can be used to later rewind() to this Command.

If the cursor is positioned over an empty slot, the call blocks until the next Command is pushed into the buffer.

If the buffer has previously been Close()d, or is closed while this is blocked, io.EOF is returned.

func (*StmtBuf) Init ¶

func (buf *StmtBuf) Init()

Init initializes a StmtBuf. It exists to avoid the allocation imposed by NewStmtBuf.

func (*StmtBuf) Len ¶

func (buf *StmtBuf) Len() int

Len returns the buffer's length.

func (*StmtBuf) Ltrim ¶

func (buf *StmtBuf) Ltrim(ctx context.Context, pos CmdPos)

Ltrim iterates over the buffer forward and removes all commands up to (not including) the command at pos.

It's illegal to Ltrim to a position higher than the current cursor.

func (*StmtBuf) Push ¶

func (buf *StmtBuf) Push(ctx context.Context, cmd Command) error

Push adds a Command to the end of the buffer. If a CurCmd() call was blocked waiting for this command to arrive, it will be woken up.

An error is returned if the buffer has been closed.

func (*StmtBuf) Rewind ¶

func (buf *StmtBuf) Rewind(ctx context.Context, pos CmdPos)

Rewind resets the buffer's position to pos.

type StmtBufReader ¶

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

StmtBufReader is an exported interface for reading a StmtBuf. Normally only the write interface of the buffer is exported, as it is used by the pgwire.

func MakeStmtBufReader ¶

func MakeStmtBufReader(buf *StmtBuf) StmtBufReader

MakeStmtBufReader creates a StmtBufReader.

func (*StmtBufReader) AdvanceOne ¶

func (r *StmtBufReader) AdvanceOne()

AdvanceOne moves the cursor one position over.

func (StmtBufReader) CurCmd ¶

func (r StmtBufReader) CurCmd() (Command, error)

CurCmd returns the current command in the buffer.

type StreamingTestingKnobs ¶

type StreamingTestingKnobs struct {
	// RunAfterReceivingEvent allows blocking the stream ingestion processor after
	// a single event has been received.
	RunAfterReceivingEvent func(ctx context.Context)
}

StreamingTestingKnobs contains knobs for streaming behavior.

func (*StreamingTestingKnobs) ModuleTestingKnobs ¶

func (*StreamingTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs implements the base.ModuleTestingKnobs interface.

type Summary ¶

type Summary struct {
	TotalTables        int
	TotalColumns       int
	MissingTables      int
	MissingColumns     int
	DatatypeMismatches int
}

Summary will keep accountability for any unexpected difference and report it in the log.

type Sync ¶

type Sync struct{}

Sync is a command that serves two purposes: 1) It marks the end of one batch of commands and the beginning of the next. stmtBuf.seekToNextBatch will seek to this marker. 2) It generates a ReadyForQuery protocol message.

A Sync command is generated for both the simple and the extended pgwire protocol variants. So, it doesn't strictly correspond to a pgwire sync message - those are not sent in the simple protocol. We synthesize Sync commands though because their handling matches the simple protocol too.

func (Sync) String ¶

func (Sync) String() string

type SyncResult ¶

type SyncResult interface {
	ResultBase
}

SyncResult represents the result of a Sync command. When closed, a readyForQuery message will be generated and all buffered data will be flushed.

type SynthesizeRegionConfigOption ¶

type SynthesizeRegionConfigOption func(o *synthesizeRegionConfigOptions)

SynthesizeRegionConfigOption is an option to pass into SynthesizeRegionConfig.

var SynthesizeRegionConfigOptionForValidation SynthesizeRegionConfigOption = func(o *synthesizeRegionConfigOptions) {
	o.forValidation = true
}

SynthesizeRegionConfigOptionForValidation includes descriptors which are being dropped as part of the regions field, allowing validation to account for regions in the process of being dropped.

var SynthesizeRegionConfigOptionIncludeOffline SynthesizeRegionConfigOption = func(o *synthesizeRegionConfigOptions) {
	o.includeOffline = true
}

SynthesizeRegionConfigOptionIncludeOffline includes offline descriptors for use in RESTORE.

var SynthesizeRegionConfigOptionUseCache SynthesizeRegionConfigOption = func(o *synthesizeRegionConfigOptions) {
	o.useCache = true
}

SynthesizeRegionConfigOptionUseCache uses a cache for synthesizing the region config.

type TTLTestingKnobs ¶

type TTLTestingKnobs struct {
	// AOSTDuration changes the AOST timestamp duration to add to the
	// current time.
	AOSTDuration *time.Duration
	// OnStatisticsError is a hook that takes in an error if gathering statistics
	// generates an error.
	OnStatisticsError func(err error)
	// MockDescriptorVersionDuringDelete is a version to mock the delete descriptor
	// as during delete.
	MockDescriptorVersionDuringDelete *descpb.DescriptorVersion
	// OnDeleteLoopStart is a hook that executes before the loop for TTL deletes begin.
	OnDeleteLoopStart func() error
}

TTLTestingKnobs contains testing knobs for TTL deletion.

func (*TTLTestingKnobs) ModuleTestingKnobs ¶

func (*TTLTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs implements the base.ModuleTestingKnobs interface.

type TableState ¶

type TableState int

TableState is the state of the referencing table ResolveFK() or ResolveUniqueWithoutIndexConstraint() is called on.

const (
	// NewTable represents a new table, where the constraint is specified in the
	// CREATE TABLE
	NewTable TableState = iota
	// EmptyTable represents an existing table that is empty
	EmptyTable
	// NonEmptyTable represents an existing non-empty table
	NonEmptyTable
)

type TelemetryLoggingMetrics ¶

type TelemetryLoggingMetrics struct {
	Knobs *TelemetryLoggingTestingKnobs
	// contains filtered or unexported fields
}

TelemetryLoggingMetrics keeps track of the last time at which an event was logged to the telemetry channel, and the number of skipped queries since the last logged event.

type TelemetryLoggingTestingKnobs ¶

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

TelemetryLoggingTestingKnobs provides hooks and knobs for unit tests.

func (*TelemetryLoggingTestingKnobs) ModuleTestingKnobs ¶

func (*TelemetryLoggingTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs implements base.ModuleTestingKnobs interface.

type TemporaryObjectCleaner ¶

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

TemporaryObjectCleaner is a background thread job that periodically cleans up orphaned temporary objects by sessions which did not close down cleanly.

func NewTemporaryObjectCleaner ¶

func NewTemporaryObjectCleaner(
	settings *cluster.Settings,
	db *kv.DB,
	codec keys.SQLCodec,
	registry *metric.Registry,
	makeSessionBoundInternalExecutor sqlutil.SessionBoundInternalExecutorFactory,
	statusServer serverpb.SQLStatusServer,
	isMeta1LeaseholderFunc isMeta1LeaseholderFunc,
	testingKnobs ExecutorTestingKnobs,
	cf *descs.CollectionFactory,
) *TemporaryObjectCleaner

NewTemporaryObjectCleaner initializes the TemporaryObjectCleaner with the required arguments, but does not start it.

func (*TemporaryObjectCleaner) Start ¶

func (c *TemporaryObjectCleaner) Start(ctx context.Context, stopper *stop.Stopper)

Start initializes the background thread which periodically cleans up leftover temporary objects.

type TenantTestingKnobs ¶

type TenantTestingKnobs struct {
	// ClusterSettingsUpdater is a field that if set, allows the tenant to set
	// in-memory cluster settings. SQL tenants are otherwise prohibited from
	// setting cluster settings.
	ClusterSettingsUpdater settings.Updater

	// TenantIDCodecOverride overrides the tenant ID used to construct the SQL
	// server's codec, but nothing else (e.g. its certs).
	TenantIDCodecOverride roachpb.TenantID

	// OverrideTokenBucketProvider allows a test-only TokenBucketProvider (which
	// can optionally forward requests to the real provider).
	OverrideTokenBucketProvider func(origProvider kvtenant.TokenBucketProvider) kvtenant.TokenBucketProvider
}

TenantTestingKnobs contains knobs for tenant behavior.

func (*TenantTestingKnobs) ModuleTestingKnobs ¶

func (*TenantTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs implements the base.ModuleTestingKnobs interface.

type TransactionStatusIndicator ¶

type TransactionStatusIndicator byte

TransactionStatusIndicator represents a pg identifier for the transaction state.

const (
	// IdleTxnBlock means the session is outside of a transaction.
	IdleTxnBlock TransactionStatusIndicator = 'I'
	// InTxnBlock means the session is inside a transaction.
	InTxnBlock TransactionStatusIndicator = 'T'
	// InFailedTxnBlock means the session is inside a transaction, but the
	// transaction is in the Aborted state.
	InFailedTxnBlock TransactionStatusIndicator = 'E'
)

type TypeSchemaChangerTestingKnobs ¶

type TypeSchemaChangerTestingKnobs struct {
	// TypeSchemaChangeJobNoOp returning true will cause the job to be a no-op.
	TypeSchemaChangeJobNoOp func() bool
	// RunBeforeExec runs at the start of the typeSchemaChanger.
	RunBeforeExec func() error
	// RunBeforeEnumMemberPromotion runs before enum members are promoted from
	// readable to all permissions in the typeSchemaChanger.
	RunBeforeEnumMemberPromotion func(ctx context.Context) error
	// RunAfterOnFailOrCancel runs after OnFailOrCancel completes, if
	// OnFailOrCancel is triggered.
	RunAfterOnFailOrCancel func() error
	// RunBeforeMultiRegionUpdates is a multi-region specific testing knob which
	// runs after enum promotion and before multi-region updates (such as
	// repartitioning tables, applying zone configs etc.)
	RunBeforeMultiRegionUpdates func() error
}

TypeSchemaChangerTestingKnobs contains testing knobs for the typeSchemaChanger.

func (TypeSchemaChangerTestingKnobs) ModuleTestingKnobs ¶

func (TypeSchemaChangerTestingKnobs) ModuleTestingKnobs()

ModuleTestingKnobs implements the ModuleTestingKnobs interface.

type UpdateVersionSystemSettingHook ¶

type UpdateVersionSystemSettingHook func(
	ctx context.Context,
	version clusterversion.ClusterVersion,
) error

UpdateVersionSystemSettingHook provides a callback that allows us update the cluster version inside the system.settings table. This hook is aimed at mainly updating tenant pods, which will currently skip over the existing migration logic for bumping version numbers (this logic is stubbed out for them). As a result there is a potential danger of migrations partially being completed without the version number being persisted to storage for tenants. This hook allows the version number to bumped and saved at each step.

type VersionUpgradeHook ¶

type VersionUpgradeHook func(
	ctx context.Context,
	user security.SQLUsername,
	from, to clusterversion.ClusterVersion,
	updateSystemVersionSetting UpdateVersionSystemSettingHook,
) error

VersionUpgradeHook is used to run migrations starting in v21.1.

type VirtualSchemaHolder ¶

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

VirtualSchemaHolder is a type used to provide convenient access to virtual database and table descriptors. VirtualSchemaHolder, virtualSchemaEntry, and virtualDefEntry make up the generated data structure which the virtualSchemas slice is mapped to. Because of this, they should not be created directly, but instead will be populated in a post-startup hook on an Executor.

func NewVirtualSchemaHolder ¶

func NewVirtualSchemaHolder(
	ctx context.Context, st *cluster.Settings,
) (*VirtualSchemaHolder, error)

NewVirtualSchemaHolder creates a new VirtualSchemaHolder.

func (*VirtualSchemaHolder) GetVirtualObjectByID ¶

func (vs *VirtualSchemaHolder) GetVirtualObjectByID(id descpb.ID) (catalog.VirtualObject, bool)

GetVirtualObjectByID makes VirtualSchemaHolder implement catalog.VirtualSchemas.

func (*VirtualSchemaHolder) GetVirtualSchema ¶

func (vs *VirtualSchemaHolder) GetVirtualSchema(schemaName string) (catalog.VirtualSchema, bool)

GetVirtualSchema makes VirtualSchemaHolder implement catalog.VirtualSchemas.

func (*VirtualSchemaHolder) GetVirtualSchemaByID ¶

func (vs *VirtualSchemaHolder) GetVirtualSchemaByID(id descpb.ID) (catalog.VirtualSchema, bool)

GetVirtualSchemaByID makes VirtualSchemaHolder implement catalog.VirtualSchemas.

type VirtualTabler ¶

type VirtualTabler interface {
	// contains filtered or unexported methods
}

VirtualTabler is used to fetch descriptors for virtual tables and databases.

Source Files ¶

Directories ¶

Path Synopsis
bootstrap
Package bootstrap contains the metadata required to bootstrap the sql schema for a fresh cockroach cluster.
Package bootstrap contains the metadata required to bootstrap the sql schema for a fresh cockroach cluster.
catpb
Package catpb contains definitions of low-level serializations of catalog concepts which can be shared by descriptors and schema change elements.
Package catpb contains definitions of low-level serializations of catalog concepts which can be shared by descriptors and schema change elements.
colinfo
Package colinfo contains type information and related structures for dealing with columns returned from sql operations.
Package colinfo contains type information and related structures for dealing with columns returned from sql operations.
dbdesc
Package dbdesc contains the concrete implementations of catalog.DatabaseDescriptor.
Package dbdesc contains the concrete implementations of catalog.DatabaseDescriptor.
descs
Package descs provides abstractions for dealing with sets of descriptors.
Package descs provides abstractions for dealing with sets of descriptors.
hydratedtables
Package hydratedtables contains logic to cache table descriptors with user defined types hydrated.
Package hydratedtables contains logic to cache table descriptors with user defined types hydrated.
internal/validate
Package validate contains all the descriptor validation logic.
Package validate contains all the descriptor validation logic.
lease
Package lease provides functionality to create and manage sql schema leases.
Package lease provides functionality to create and manage sql schema leases.
multiregion
Package multiregion provides functions and structs for interacting with the static multi-region state configured by users on their databases.
Package multiregion provides functions and structs for interacting with the static multi-region state configured by users on their databases.
nstree
Package nstree provides a data structure for storing and retrieving descriptors namespace entry-like data.
Package nstree provides a data structure for storing and retrieving descriptors namespace entry-like data.
schemaexpr
Package schemaexpr provides utilities for dealing with expressions with table schemas, such as check constraints, computed columns, and partial index predicates.
Package schemaexpr provides utilities for dealing with expressions with table schemas, such as check constraints, computed columns, and partial index predicates.
seqexpr
Package seqexpr provides functionality to find usages of sequences in expressions.
Package seqexpr provides functionality to find usages of sequences in expressions.
tabledesc
Package tabledesc provides concrete implementations of catalog.TableDesc.
Package tabledesc provides concrete implementations of catalog.TableDesc.
typedesc
Package typedesc contains the concrete implementations of catalog.TypeDescriptor.
Package typedesc contains the concrete implementations of catalog.TypeDescriptor.
Package doctor provides utilities for checking the consistency of cockroach internal persisted metadata.
Package doctor provides utilities for checking the consistency of cockroach internal persisted metadata.
Package faketreeeval provides fake implementations of tree eval interfaces.
Package faketreeeval provides fake implementations of tree eval interfaces.
gcjobnotifier
Package gcjobnotifier provides a mechanism to share a SystemConfigDeltaFilter among all gc jobs.
Package gcjobnotifier provides a mechanism to share a SystemConfigDeltaFilter among all gc jobs.
allkeywords command
all-keywords generates sql/lexbase/keywords.go from sql.y.
all-keywords generates sql/lexbase/keywords.go from sql.y.
Package oidext contains oids that are not in `github.com/lib/pq/oid` as they are not shipped by default with postgres.
Package oidext contains oids that are not in `github.com/lib/pq/oid` as they are not shipped by default with postgres.
opt
Package opt contains the Cockroach SQL optimizer.
Package opt contains the Cockroach SQL optimizer.
bench
Package bench houses benchmarks for the SQL optimizer.
Package bench houses benchmarks for the SQL optimizer.
cat
Package cat contains interfaces that are used by the query optimizer to avoid including specifics of sqlbase structures in the opt code.
Package cat contains interfaces that are used by the query optimizer to avoid including specifics of sqlbase structures in the opt code.
optgen/cmd/optfmt command
optfmt pretty prints .opt files.
optfmt pretty prints .opt files.
optgen/lang
Package lang implements a language called Optgen, short for "optimizer generator".
Package lang implements a language called Optgen, short for "optimizer generator".
ordering
Package ordering contains operator-specific logic related to orderings - whether ops can provide Required orderings, what orderings do they need to require from their children, etc.
Package ordering contains operator-specific logic related to orderings - whether ops can provide Required orderings, what orderings do they need to require from their children, etc.
Package paramparse parses parameters that are set in param lists or session vars.
Package paramparse parses parameters that are set in param lists or session vars.
hba
Package hba implements an hba.conf parser.
Package hba implements an hba.conf parser.
identmap
Package identmap contains the code for parsing a pg_ident.conf file, which allows a database operator to create some number of mappings between system identities (e.g.: GSSAPI or X.509 principals) and database usernames.
Package identmap contains the code for parsing a pg_ident.conf file, which allows a database operator to create some number of mappings between system identities (e.g.: GSSAPI or X.509 principals) and database usernames.
pgcode
Package pgcode defines the PostgreSQL 5-character support codes used throughout the CockroachDB source tree.
Package pgcode defines the PostgreSQL 5-character support codes used throughout the CockroachDB source tree.
pgwirebase
Package pgwirebase contains type definitions and very basic protocol structures to be used by both the pgwire package and by others (particularly by the sql package).
Package pgwirebase contains type definitions and very basic protocol structures to be used by both the pgwire package and by others (particularly by the sql package).
replicaoracle
Package replicaoracle provides functionality for physicalplan to choose a replica for a range.
Package replicaoracle provides functionality for physicalplan to choose a replica for a range.
Package randgen provides utility functions for generating random syntax trees, datums, encoded datums, types, and more.
Package randgen provides utility functions for generating random syntax trees, datums, encoded datums, types, and more.
keyside
Package keyside contains low-level primitives used to encode/decode SQL values into/from KV Keys (see roachpb.Key).
Package keyside contains low-level primitives used to encode/decode SQL values into/from KV Keys (see roachpb.Key).
valueside
Package valueside contains low-level primitives used to encode/decode SQL values into/from KV Values (see roachpb.Value).
Package valueside contains low-level primitives used to encode/decode SQL values into/from KV Values (see roachpb.Value).
Package rowinfra contains constants and types used by the row package that must also be accessible from other packages.
Package rowinfra contains constants and types used by the row package that must also be accessible from other packages.
schemachanger
rel
Package rel provides mechanisms to model and query go structs pointers using a declarative, relational paradigm.
Package rel provides mechanisms to model and query go structs pointers using a declarative, relational paradigm.
rel/reltest
Package reltest provides tools for testing the rel package.
Package reltest provides tools for testing the rel package.
scbackup
Package scbackup contains logic for interacting with schema changer state during backup and restore.
Package scbackup contains logic for interacting with schema changer state during backup and restore.
scplan/internal/rules
Package rules contains rules to: - generate dependency edges for a graph which contains op edges, - mark certain op-edges as no-op.
Package rules contains rules to: - generate dependency edges for a graph which contains op edges, - mark certain op-edges as no-op.
screl
Package screl contains a rel schema for the elements of scpb.
Package screl contains a rel schema for the elements of scpb.
sctest
Package sctest contains tools to run end-to-end datadriven tests in both ccl and non-ccl settings.
Package sctest contains tools to run end-to-end datadriven tests in both ccl and non-ccl settings.
sem
catid
Package catid is a low-level package exporting ID types.
Package catid is a low-level package exporting ID types.
tree/treebin
Package treebin contains the implementation-agnostic information about all binary operators that we support.
Package treebin contains the implementation-agnostic information about all binary operators that we support.
tree/treecmp
Package treecmp contains the implementation-agnostic information about all comparison operators that we support.
Package treecmp contains the implementation-agnostic information about all comparison operators that we support.
tree/treewindow
Package treewindow contains some constants describing window-function specific options.
Package treewindow contains some constants describing window-function specific options.
Package sqlerrors exports errors which can occur in the sql package.
Package sqlerrors exports errors which can occur in the sql package.
Package sqlfsm contains the definitions for the state labels of the conn executor FSM.
Package sqlfsm contains the definitions for the state labels of the conn executor FSM.
Package sqlinstance provides interfaces that will be exposed to interact with the sqlinstance subsystem.
Package sqlinstance provides interfaces that will be exposed to interact with the sqlinstance subsystem.
instanceprovider
Package instanceprovider provides an implementation of the sqlinstance.provider interface.
Package instanceprovider provides an implementation of the sqlinstance.provider interface.
instancestorage
Package instancestorage package provides API to read from and write to the sql_instance system table.
Package instancestorage package provides API to read from and write to the sql_instance system table.
Package sqlliveness provides interfaces to associate resources at the SQL level with tenant SQL processes.
Package sqlliveness provides interfaces to associate resources at the SQL level with tenant SQL processes.
slinstance
Package slinstance provides functionality for acquiring sqlliveness leases via sessions that have a unique id and expiration.
Package slinstance provides functionality for acquiring sqlliveness leases via sessions that have a unique id and expiration.
slprovider
Package slprovider exposes an implementation of the sqlliveness.Provider interface.
Package slprovider exposes an implementation of the sqlliveness.Provider interface.
Package sqltelemetry contains telemetry counter definitions for various SQL features.
Package sqltelemetry contains telemetry counter definitions for various SQL features.
Package sqltestutils provides helper methods for testing sql packages.
Package sqltestutils provides helper methods for testing sql packages.
ttl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL