Skip to content

Commit 95d4b27

Browse files
author
James Cor
committed
restore comments
1 parent 0f00d09 commit 95d4b27

File tree

14 files changed

+154
-61
lines changed

14 files changed

+154
-61
lines changed

sql/plan/subquery.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,34 @@ import (
2929
// the outer result set. It's in the plan package instead of the expression package because it functions more like a
3030
// plan Node than an expression.
3131
type Subquery struct {
32-
Query sql.Node
33-
correlated sql.ColSet
34-
hashCache sql.KeyValueCache
35-
b sql.NodeExecBuilder
32+
// The subquery to execute for each row in the outer result set
33+
Query sql.Node
34+
// correlated is a set of the field references in this subquery from out-of-scope
35+
correlated sql.ColSet
36+
// Cached hash results, if any
37+
hashCache sql.KeyValueCache
38+
39+
// TODO: convert subquery expressions into apply joins
40+
// TODO: move expression.Eval into an execution package
41+
// TODO: analyzer rule to connect builder access
42+
b sql.NodeExecBuilder
43+
44+
// Dispose function for the cache, if any. This would appear to violate the rule that nodes must be comparable by
45+
// reflect.DeepEquals, but it's safe in practice because the function is always nil until execution.
3646
disposeFunc sql.DisposeFunc
3747

48+
// The original verbatim select statement for this subquery
3849
QueryString string
3950

40-
cache []interface{}
51+
// Cached results, if any
52+
cache []interface{}
53+
// Mutex to guard the caches
4154
cacheMu sync.Mutex
42-
43-
volatile bool
55+
// Whether results have been cached
4456
resultsCached bool
57+
58+
// volatile indicates that the expression contains a non-deterministic function
59+
volatile bool
4560
}
4661

4762
// NewSubquery returns a new subquery expression.

sql/plan/subqueryalias.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type SubqueryAlias struct {
3333

3434
id sql.TableId
3535

36+
// expression and is eligible to have visibility to outer scopes of the query.
3637
OuterScopeVisibility bool
3738
Volatile bool
3839
CacheableCTESource bool

sql/plan/update.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ var ErrUpdateUnexpectedSetResult = errors.NewKind("attempted to set field but ex
3131
// Update is a node for updating rows on tables.
3232
type Update struct {
3333
UnaryNode
34-
checks sql.CheckConstraints
35-
Returning []sql.Expression
36-
Ignore bool
34+
checks sql.CheckConstraints
35+
// supported in MySQL's syntax, but is exposed through PostgreSQL's syntax.
36+
Returning []sql.Expression
37+
// IsJoin is true only for explicit UPDATE JOIN queries. It's possible for Update.IsJoin to be false and
38+
// Update.Child to be an UpdateJoin since subqueries are optimized as Joins
3739
IsJoin bool
3840
HasSingleRel bool
3941
IsProcNested bool
42+
Ignore bool
4043
}
4144

4245
var _ sql.Node = (*Update)(nil)

sql/planbuilder/builder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var BinderFactory = &sync.Pool{New: func() interface{} {
3333
}}
3434

3535
type Builder struct {
36+
// EventScheduler is used to communicate with the event scheduler
37+
// for any EVENT related statements. It can be nil if EventScheduler is not defined.
3638
scheduler sql.EventScheduler
3739
cat sql.Catalog
3840
authQueryState sql.AuthorizationQueryState

sql/planbuilder/scope.go

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,45 @@ import (
2828
// scope tracks relational dependencies necessary to type check expressions,
2929
// resolve name definitions, and build relational nodes.
3030
type scope struct {
31-
node sql.Node
32-
colset sql.ColSet
33-
ast ast.SQLNode
34-
exprs map[string]columnId
35-
proc *procCtx
36-
selectAliases map[string]sql.Expression
37-
insertColumnAliases map[string]string
38-
parent *scope
39-
activeSubquery *subquery
40-
redirectCol map[string]scopeColumn
31+
node sql.Node
32+
colset sql.ColSet
33+
ast ast.SQLNode
34+
35+
// exprs collects unique expression ids for reference
36+
exprs map[string]columnId
37+
38+
// tables are the list of table definitions in this scope
4139
tables map[string]sql.TableId
42-
ctes map[string]*scope
43-
groupBy *groupBy
44-
b *Builder
4540
windowDefs map[string]*sql.WindowDefinition
46-
insertTableAlias string
47-
windowFuncs []scopeColumn
48-
extraCols []scopeColumn
49-
cols []scopeColumn
50-
refsSubquery bool
41+
selectAliases map[string]sql.Expression
42+
insertColumnAliases map[string]string
43+
44+
// redirectCol is used for using and natural joins right-table
45+
// attributes that redirect to the left table intersection
46+
redirectCol map[string]scopeColumn
47+
48+
// ctes are common table expressions defined in this scope
49+
// TODO: these should be case-sensitive
50+
ctes map[string]*scope
51+
52+
b *Builder
53+
proc *procCtx
54+
parent *scope
55+
activeSubquery *subquery
56+
57+
// groupBy collects aggregation functions and inputs
58+
groupBy *groupBy
59+
60+
insertTableAlias string
61+
62+
// cols are definitions provided by this scope
63+
cols []scopeColumn
64+
// extraCols are auxillary output columns required for sorting or grouping
65+
extraCols []scopeColumn
66+
// windowFuncs is a list of window functions in the current scope
67+
windowFuncs []scopeColumn
68+
69+
refsSubquery bool
5170
}
5271

5372
// resolveColumn matches a variable use to a column definition with a unique

sql/privileges.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type PrivilegedOperation struct {
2020
Table string
2121
Column string
2222
Routine string
23-
StaticPrivileges []PrivilegeType
2423
DynamicPrivileges []string
25-
IsProcedure bool
24+
StaticPrivileges []PrivilegeType
25+
IsProcedure bool // true if the routine is a procedure, false if it's a function
2626
}
2727

2828
// PrivilegeCheckSubject is a struct that contains the entity information for an access check. It's specifically what

sql/procedures.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,41 @@ type StoredProcedureDetails struct {
4444
// or deleted by a user. In addition, they're implemented as a function taking standard parameters, compared to stored
4545
// procedures being implemented as expressions.
4646
type ExternalStoredProcedureDetails struct {
47-
Function interface{}
48-
Name string
49-
Schema Schema
50-
ReadOnly bool
47+
// Function is the implementation of the external stored procedure. All functions should have the following definition:
48+
// `func(*Context, <PARAMETERS>) (RowIter, error)`. The <PARAMETERS> may be any of the following types: `bool`,
49+
// `string`, `[]byte`, `int8`-`int64`, `uint8`-`uint64`, `float32`, `float64`, `time.Time`, or `Decimal`
50+
// (shopspring/decimal). The architecture-dependent types `int` and `uint` (without a number) are also supported.
51+
// It is valid to return a nil RowIter if there are no rows to be returned.
52+
//
53+
// Each parameter, by default, is an IN parameter. If the parameter type is a pointer, e.g. `*int32`, then it
54+
// becomes an INOUT parameter. INOUT parameters will be given their zero value if the parameter's value is nil.
55+
// There is no way to set a parameter as an OUT parameter.
56+
//
57+
// Values are converted to their nearest type before being passed in, following the conversion rules of their
58+
// related SQL types. The exceptions are `time.Time` (treated as a `DATETIME`), string (treated as a `LONGTEXT` with
59+
// the default collation) and Decimal (treated with a larger precision and scale). Take extra care when using decimal
60+
// for an INOUT parameter, to ensure that the returned value fits the original's precision and scale, else an error
61+
// will occur.
62+
//
63+
// As functions support overloading, each variant must have a completely unique function signature to prevent
64+
// ambiguity. Uniqueness is determined by the number of parameters. If two functions are returned that have the same
65+
// name and same number of parameters, then an error is thrown. If the last parameter is variadic, then the stored
66+
// procedure functions as though it has the integer-max number of parameters. When an exact match is not found for
67+
// overloaded functions, the largest function is used (which in this case will be the variadic function). Also, due
68+
// to the usage of the integer-max for the parameter count, only one variadic function is allowed per function name.
69+
// The type of the variadic parameter may not have a pointer type.
70+
Function interface{}
71+
// Name is the name of the external stored procedure. If two external stored procedures share a name, then they're
72+
// considered overloaded. Standard stored procedures do not support overloading.
73+
Name string
74+
// Schema describes the row layout of the RowIter returned from Function.
75+
Schema Schema
76+
// If true, the procedure is ReadOnly and can be run against a locked or read-only server.
77+
ReadOnly bool
78+
// If true, then this procedure's access control requires that the user must have explicit Execute permissions
79+
// on the procedure in question. If false, then the user will be granted access to the procedure if they have Execute
80+
// permissions on the DB. MySQL does not support anything like this, but it is useful for Dolt procedures which
81+
// grant elevated access.
5182
AdminOnly bool
5283
}
5384

sql/procedures/interpreter_stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type InterpreterHandler struct {
102102
Statement ast.Statement
103103
Condition ast.DeclareHandlerConditionValue
104104
Action ast.DeclareHandlerAction
105-
Counter int
105+
Counter int // This is used to track the current position in the stack for the handler
106106
}
107107

108108
// InterpreterVariable is a variable that lives on the stack.

sql/processlist.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const (
9292

9393
// Process represents a process in the SQL server.
9494
type Process struct {
95+
// The time of the last Command transition
9596
StartedAt time.Time
9697
Progress map[string]TableProgress
9798
Kill context.CancelFunc

sql/rowexec/agg.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ type groupByGroupingIter struct {
116116
selectedExprs []sql.Expression
117117
groupByExprs []sql.Expression
118118
keys []uint64
119-
keyRow sql.Row
120-
keySch sql.Schema
121-
pos int
119+
// buffers to reduce slice allocations
120+
keyRow sql.Row
121+
keySch sql.Schema
122+
pos int
122123
}
123124

124125
func newGroupByGroupingIter(

0 commit comments

Comments
 (0)