vtexplain

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 44 Imported by: 1

Documentation

Overview

Package vtexplain analyzes a set of sql statements and returns the corresponding vtgate and vttablet query plans that will be executed on the given statements

Package vtexplain analyzes a set of sql statements and returns the corresponding vtgate and vttablet query plans that will be executed on the given statements

Index

Constants

View Source
const (
	Cell = "explainCell"

	// ModeMulti is the default mode with autocommit implemented at vtgate
	ModeMulti = "multi"

	// ModeTwoPC enables the twopc feature
	ModeTwoPC = "twopc"
)

Variables

This section is empty.

Functions

func ExplainsAsJSON

func ExplainsAsJSON(explains []*Explain) string

ExplainsAsJSON returns a json representation of the explains

Types

type ExecutorMode

type ExecutorMode string

ExecutorMode controls the mode of operation for the vtexplain simulator

type Explain

type Explain struct {
	// original sql statement
	SQL string

	// the vtgate plan(s)
	Plans []*engine.Plan

	// list of queries / bind vars sent to each tablet
	TabletActions map[string]*TabletActions
}

Explain defines how vitess will execute a given sql query, including the vtgate query plans and all queries run on each tablet.

type ExplainTopo

type ExplainTopo struct {
	// Map of keyspace name to vschema
	Keyspaces map[string]*vschemapb.Keyspace

	// Map of ks/shard to test tablet connection
	TabletConns map[string]*explainTablet

	KeyspaceShards map[string]map[string]*topodatapb.ShardReference

	// Synchronization lock
	Lock sync.Mutex

	// Number of shards for sharded keyspaces
	NumShards int

	TopoServer *topo.Server
}

ExplainTopo satisfies the srvtopo.Server interface. Modeled after the vtgate test sandboxTopo

func (*ExplainTopo) GetSrvKeyspace

func (et *ExplainTopo) GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodatapb.SrvKeyspace, error)

GetSrvKeyspace is part of the srvtopo.Server interface.

func (*ExplainTopo) GetSrvKeyspaceNames

func (et *ExplainTopo) GetSrvKeyspaceNames(ctx context.Context, cell string, staleOK bool) ([]string, error)

GetSrvKeyspaceNames is part of the srvtopo.Server interface.

func (*ExplainTopo) GetTopoServer

func (et *ExplainTopo) GetTopoServer() (*topo.Server, error)

GetTopoServer is part of the srvtopo.Server interface

func (*ExplainTopo) WatchSrvKeyspace added in v0.12.0

func (et *ExplainTopo) WatchSrvKeyspace(ctx context.Context, cell, keyspace string, callback func(*topodatapb.SrvKeyspace, error) bool)

func (*ExplainTopo) WatchSrvVSchema

func (et *ExplainTopo) WatchSrvVSchema(ctx context.Context, cell string, callback func(*vschemapb.SrvVSchema, error) bool)

WatchSrvVSchema is part of the srvtopo.Server interface.

type MysqlQuery

type MysqlQuery struct {
	// Sequence number of the query
	Time int

	// SQL command sent to the given tablet
	SQL string
}

MysqlQuery defines a query that was sent to a given tablet and how it was processed in mysql

type Options

type Options struct {
	// NumShards indicates the number of shards in the topology
	NumShards int

	// PlannerVersion indicates whether or not we should use the Gen4 planner
	PlannerVersion querypb.ExecuteOptions_PlannerVersion

	// ReplicationMode must be set to either "ROW" or "STATEMENT" before
	// initialization
	ReplicationMode string

	// Normalize controls whether or not vtgate does query normalization
	Normalize bool

	// ExecutionMode must be set to one of the modes above
	ExecutionMode string

	// StrictDDL is used in unit tests only to verify that the schema
	// is parsed properly.
	StrictDDL bool

	// Target is used to override the "database" target in the
	// vtgate session to simulate `USE <target>`
	Target string
}

Options to control the explain process

type TabletActions

type TabletActions struct {
	// Queries sent from vtgate to the tablet
	TabletQueries []*TabletQuery

	// Queries that were run on mysql
	MysqlQueries []*MysqlQuery
}

TabletActions contains the set of operations done by a given tablet

type TabletQuery

type TabletQuery struct {
	// Logical time of the query
	Time int

	// SQL command sent to the given tablet
	SQL string

	// BindVars sent with the command
	BindVars map[string]*querypb.BindVariable
}

TabletQuery defines a query that was sent to a given tablet and how it was processed in mysql

func (*TabletQuery) MarshalJSON

func (tq *TabletQuery) MarshalJSON() ([]byte, error)

MarshalJSON renders the json structure

type VTExplain added in v0.14.0

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

func Init

func Init(ctx context.Context, env *vtenv.Environment, ts *topo.Server, vSchemaStr, sqlSchema, ksShardMapStr string, opts *Options) (*VTExplain, error)

Init sets up the fake execution environment

func (*VTExplain) ExplainsAsText added in v0.14.0

func (vte *VTExplain) ExplainsAsText(explains []*Explain) (string, error)

ExplainsAsText returns a text representation of the explains in logical time order

func (*VTExplain) Run added in v0.14.0

func (vte *VTExplain) Run(sql string) ([]*Explain, error)

Run the explain analysis on the given queries

func (*VTExplain) Stop added in v0.14.0

func (vte *VTExplain) Stop()

Stop and cleans up fake execution environment

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL