Skip to content

Commit 0f00d09

Browse files
author
James Cor
committed
restore a bunch of comments
1 parent 6aca10b commit 0f00d09

File tree

16 files changed

+209
-80
lines changed

16 files changed

+209
-80
lines changed

sql/column.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,35 @@ import (
2626
// A column is a named component of a table. It has a data type, a default,
2727
// and a nullability characteristic.
2828
type Column struct {
29-
Type Type
30-
Generated *ColumnDefaultValue
31-
Default *ColumnDefaultValue
32-
OnUpdate *ColumnDefaultValue
33-
Name string
34-
Source string
29+
// Type is the data type of the column.
30+
Type Type
31+
// Default contains the default value of the column or nil if it was not explicitly defined.
32+
Default *ColumnDefaultValue
33+
// Generated is non-nil if the column is defined with a generated value. Mutually exclusive with Default
34+
Generated *ColumnDefaultValue
35+
// OnUpdate contains the on update value of the column or nil if it was not explicitly defined.
36+
OnUpdate *ColumnDefaultValue
37+
// Name is the name of the column.
38+
Name string
39+
// Source is the name of the table this column came from.
40+
Source string
41+
// DatabaseSource is the name of the database this column came from.
3542
DatabaseSource string
36-
Comment string
37-
Extra string
38-
PrimaryKey bool
39-
Nullable bool
40-
Virtual bool
41-
AutoIncrement bool
43+
// Comment contains the string comment for this column.
44+
Comment string
45+
// Extra contains any additional information to put in the `extra` column under `information_schema.columns`.
46+
Extra string
47+
// PrimaryKey is true if the column is part of the primary key for its table.
48+
PrimaryKey bool
49+
// Nullable is true if the column can contain NULL values, or false
50+
// otherwise.
51+
Nullable bool
52+
// Virtual is true if the column is defined as a virtual column. Generated must be non-nil in this case.
53+
// Virtual column values will be provided for write operations, in case integrators need to use them to update
54+
// indexes, but must not be returned in rows from tables that include them.
55+
Virtual bool
56+
// AutoIncrement is true if the column auto-increments.
57+
AutoIncrement bool
4258
}
4359

4460
// Check ensures the value is correct for this column.

sql/constraints.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,30 @@ func (f ForeignKeyReferentialAction) IsEquivalentToRestrict() bool {
4545

4646
// ForeignKeyConstraint declares a constraint between the columns of two tables.
4747
type ForeignKeyConstraint struct {
48-
Name string
49-
Database string
50-
SchemaName string
51-
Table string
48+
// Name is the name of the foreign key constraint
49+
Name string
50+
// Database is the name of the database of the table with the constraint
51+
Database string
52+
// SchemaName is the name of the schema of the table, for databases that support schemas.
53+
SchemaName string
54+
// Table is the name of the table with the constraint
55+
Table string
56+
// ParentDatabase is the name of the database of the parent table
5257
ParentDatabase string
53-
ParentSchema string
54-
ParentTable string
55-
OnUpdate ForeignKeyReferentialAction
56-
OnDelete ForeignKeyReferentialAction
57-
Columns []string
58-
ParentColumns []string
59-
IsResolved bool
58+
// ParentSchema is the name of the schema of the parent table, for databases that support schemas.
59+
ParentSchema string
60+
// ParentTable is the name of the parent table
61+
ParentTable string
62+
// OnUpdate is the action to take when the constraint is violated when a row in the parent table is updated
63+
OnUpdate ForeignKeyReferentialAction
64+
// OnDelete is the action to take when the constraint is violated when a row in the parent table is deleted
65+
OnDelete ForeignKeyReferentialAction
66+
// Columns is the list of columns in the table that are part of the foreign key
67+
Columns []string
68+
// ParentColumns is the list of columns in the parent table that are part of the foreign key
69+
ParentColumns []string
70+
// IsResolved is true if the foreign key has been resolved, false otherwise
71+
IsResolved bool
6072
}
6173

6274
// IsSelfReferential returns whether this foreign key represents a self-referential foreign key.

sql/core.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,36 @@ var _ SystemVariable = (*MysqlSystemVariable)(nil)
479479

480480
// MysqlSystemVariable represents a mysql system variable.
481481
type MysqlSystemVariable struct {
482-
Type Type
483-
Default interface{}
484-
Scope *MysqlScope
485-
NotifyChanged func(*Context, SystemVariableScope, SystemVarValue) error
486-
ValueFunction func() (interface{}, error)
487-
Name string
488-
Dynamic bool
482+
// Type defines the type of the system variable. This may be a special type not accessible to standard MySQL operations.
483+
Type Type
484+
// Default defines the default value of the system variable.
485+
Default interface{}
486+
// Scope defines the scope of the system variable, which is either Global, Session, or Both.
487+
Scope *MysqlScope
488+
// NotifyChanged is called by the engine if the value of this variable
489+
// changes during runtime. It is typically |nil|, but can be used for
490+
// system variables which control the behavior of the running server.
491+
// For example, replication threads might need to be started or stopped
492+
// when replication is enabled or disabled. This provides a scalable
493+
// alternative to polling.
494+
//
495+
// Calls to NotifyChanged are serialized for a given system variable in
496+
// the global context and in a particular session. They should never
497+
// block. NotifyChanged is not called when a new system variable is
498+
// registered.
499+
NotifyChanged func(*Context, SystemVariableScope, SystemVarValue) error
500+
// ValueFunction defines an optional function that is executed to provide
501+
// the value of this system variable whenever it is requested. System variables
502+
// that provide a ValueFunction should also set Dynamic to false, since they
503+
// cannot be assigned a value and will return a read-only error if tried.
504+
ValueFunction func() (interface{}, error)
505+
// Name is the name of the system variable.
506+
Name string
507+
// Dynamic defines whether the variable may be written to during runtime. Variables with this set to `false` will
508+
// return an error if a user attempts to set a value.
509+
Dynamic bool
510+
// SetVarHintApplies defines if the variable may be set for a single query using SET_VAR().
511+
// https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html#optimizer-hints-set-var
489512
SetVarHintApplies bool
490513
}
491514

sql/expression/function/aggregation/unary_agg_buffers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (a *anyValueBuffer) Dispose() {
5252
}
5353

5454
type sumBuffer struct {
55-
sum interface{}
55+
sum interface{} // sum is either decimal.Decimal or float64
5656
expr sql.Expression
5757
isnil bool
5858
}

sql/expression/function/aggregation/window_functions.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ func (a *AnyValueAgg) Compute(ctx *sql.Context, interval sql.WindowInterval, buf
9393
}
9494

9595
type SumAgg struct {
96-
expr sql.Expression
97-
framer sql.WindowFramer
98-
prefixSum []float64 // use prefix sums to quickly calculate arbitrary frame sum within partition
96+
expr sql.Expression
97+
framer sql.WindowFramer
98+
// use prefix sums to quickly calculate arbitrary frame sum within partition
99+
prefixSum []float64
99100
partitionStart int
100101
partitionEnd int
101102
}

sql/fast_int_set.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ import (
4848
// allocations when the values are small. It is not thread-safe.
4949
type FastIntSet struct {
5050
large *intsets.Sparse
51+
// We use a uint64 as long as all elements are between 0 and 63. If we add an
52+
// element outside of this range, we switch to Sparse. We don't just use the
53+
// latter directly because it's larger and can't be passed around by value.
5154
small uint64
5255
}
5356

sql/index_registry.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ type IndexRegistry struct {
3232
refCounts map[indexKey]int
3333
deleteIndexQueue map[indexKey]chan<- struct{}
3434
indexLoaders map[dbTableTuple][]func(ctx *Context) error
35-
Root string
36-
indexOrder []indexKey
37-
mut sync.RWMutex
38-
driversMut sync.RWMutex
39-
rcmut sync.RWMutex
35+
// Root path where all the data of the indexes is stored on disk.
36+
Root string
37+
indexOrder []indexKey
38+
mut sync.RWMutex
39+
driversMut sync.RWMutex
40+
rcmut sync.RWMutex
4041
}
4142

4243
// NewIndexRegistry returns a new Index Registry.

sql/memo/join_order_builder.go

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ import (
122122
//
123123
// TODO: null rejecting tables
124124
type joinOrderBuilder struct {
125+
// plans maps from a set of base relations to the memo group for the join tree
126+
// that contains those relations (and only those relations). As an example,
127+
// the group for [xy, ab, uv] might contain the join trees (xy, (ab, uv)),
128+
// ((xy, ab), uv), (ab, (xy, uv)), etc.
129+
//
130+
// The group for a single base relation is the base relation itself.
125131
m *Memo
126132
innerEdges edgeSet
127133
nonInnerEdges edgeSet
@@ -362,7 +368,7 @@ func (j *joinOrderBuilder) ensureClosure(grp *ExprGroup) {
362368

363369
// hasEqEdge returns true if the inner edges include a direct equality between
364370
// the two given columns (e.g. x = a).
365-
func (j joinOrderBuilder) hasEqEdge(leftCol, rightCol sql.ColumnId) bool {
371+
func (j *joinOrderBuilder) hasEqEdge(leftCol, rightCol sql.ColumnId) bool {
366372
for idx, ok := j.innerEdges.Next(0); ok; idx, ok = j.innerEdges.Next(idx + 1) {
367373
for _, f := range j.edges[idx].filters {
368374
var l *expression.GetField
@@ -839,24 +845,49 @@ func (j *joinOrderBuilder) allEdges() edgeSet {
839845
// tree. It is used in calculating the total eligibility sets for edges from any
840846
// 'parent' joins which were originally above this one in the tree.
841847
type operator struct {
842-
leftEdges edgeSet
843-
rightEdges edgeSet
844-
leftVertices vertexSet
848+
// leftEdges is the set of edges that were constructed from join operators
849+
// that were in the left input of the original join operator.
850+
leftEdges edgeSet
851+
// rightEdgers is the set of edges that were constructed from join operators
852+
// that were in the right input of the original join operator.
853+
rightEdges edgeSet
854+
// leftVertices is the set of vertexes (base relations) that were in the left
855+
// input of the original join operator.
856+
leftVertices vertexSet
857+
// rightVertices is the set of vertexes (base relations) that were in the
858+
// right input of the original join operator.
845859
rightVertices vertexSet
846-
joinType plan.JoinType
860+
// joinType is the operator type of the original join operator.
861+
joinType plan.JoinType
847862
}
848863

849864
// edge is a generalization of a join edge that embeds rules for
850865
// determining the applicability of arbitrary subtrees. An edge is added to the
851866
// join graph when a new plan can be constructed between two vertexSet.
852867
type edge struct {
853-
freeVars sql.ColSet
854-
op *operator
855-
filters []sql.Expression
856-
rules []conflictRule
868+
freeVars sql.ColSet
869+
// op is the original join node source for the edge. there are multiple edges
870+
// per op for inner joins with conjunct-predicate join conditions. Different predicates
871+
// will have different conflict rules.
872+
op *operator
873+
// filters is the set of join filters that will be used to construct new join
874+
// ON conditions.
875+
filters []sql.Expression
876+
// rules is a set of conflict rules which must evaluate to true in order for
877+
// a join between two sets of vertexes to be valid.
878+
rules []conflictRule
879+
// nullRejectedRels is the set of vertexes on which nulls are rejected by the
880+
// filters. We do not set any nullRejectedRels currently, which is not accurate
881+
// but prevents potentially invalid transformations.
857882
nullRejectedRels vertexSet
858-
ses vertexSet
859-
tes vertexSet
883+
// ses is the syntactic eligibility set of the edge; in other words, it is the
884+
// set of base relations (tables) referenced by the filters field.
885+
ses vertexSet
886+
// tes is the total eligibility set of the edge. The TES gives the set of base
887+
// relations (vertexes) that must be in the input of any join that uses the
888+
// filters from this edge in its ON condition. The TES is initialized with the
889+
// SES, and then expanded by the conflict detection algorithm.
890+
tes vertexSet
860891
}
861892

862893
func (e *edge) populateEdgeProps(tableIds []sql.TableId, edges []edge) {

sql/plan/alter_index.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,35 @@ const (
4242
)
4343

4444
type AlterIndex struct {
45-
Db sql.Database
45+
// ddlNode references to the database that is being operated on
46+
Db sql.Database
47+
// Table is the table that is being referenced
4648
Table sql.TableNode
4749

48-
IndexName string
50+
// IndexName is the index name, and in the case of a RENAME it represents the new name
51+
IndexName string
52+
// PreviousIndexName states the old name when renaming an index
4953
PreviousIndexName string
50-
Comment string
54+
// Comment is the comment that was left at index creation, if any
55+
Comment string
5156

57+
// TargetSchema Analyzer state.
5258
targetSchema sql.Schema
53-
Columns []sql.IndexColumn
54-
Using sql.IndexUsing
55-
Constraint sql.IndexConstraint
56-
57-
Action IndexAction
58-
IfExists bool
59+
// Columns contains the column names (and possibly lengths) when creating an index
60+
Columns []sql.IndexColumn
61+
// TODO: This should just use sql.IndexDef
62+
// Using states whether you're using BTREE, HASH, or non
63+
Using sql.IndexUsing
64+
// Constraint specifies whether this is UNIQUE, FULLTEXT, SPATIAL, or none
65+
Constraint sql.IndexConstraint
66+
67+
// Action states whether it's a CREATE, DROP, or RENAME
68+
Action IndexAction
69+
// IfExists indicates if we should error when deleting an index that doesn't exist
70+
IfExists bool
71+
// IfNotExists indicates if we should error when creating a duplicate index
5972
IfNotExists bool
73+
// DisableKeys determines whether to DISABLE KEYS if true or ENABLE KEYS if false
6074
DisableKeys bool
6175
}
6276

sql/plan/delete.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ var ErrDeleteFromNotSupported = errors.NewKind("table doesn't support DELETE FRO
2828
// DeleteFrom is a node describing a deletion from some table.
2929
type DeleteFrom struct {
3030
UnaryNode
31+
// targets are the explicitly specified table nodes from which rows should be deleted. For simple DELETES against a
32+
// single source table, targets do NOT need to be explicitly specified and will not be set here. For DELETE FROM JOIN
33+
// statements, targets MUST be explicitly specified by the user and will be populated here.
3134
explicitTargets []sql.Node
32-
Returning []sql.Expression
33-
RefsSingleRel bool
34-
IsProcNested bool
35+
// Returning is a list of expressions to return after the delete operation. This feature is not
36+
// supported in MySQL's syntax, but is exposed through PostgreSQL's syntax.
37+
Returning []sql.Expression
38+
RefsSingleRel bool
39+
IsProcNested bool
3540
}
3641

3742
var _ sql.Databaseable = (*DeleteFrom)(nil)

0 commit comments

Comments
 (0)