Skip to content

Commit 7b4ac35

Browse files
author
James Cor
committed
tidyup analyzer rules
1 parent eb9722c commit 7b4ac35

File tree

11 files changed

+127
-246
lines changed

11 files changed

+127
-246
lines changed

sql/analyzer/analyzer.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,6 @@ func (a *Analyzer) PopDebugContext() {
394394
func SelectAllBatches(string) bool { return true }
395395

396396
func DefaultRuleSelector(id RuleId) bool {
397-
switch id {
398-
// prepared statement rules are incompatible with default rules
399-
case reresolveTablesId,
400-
resolvePreparedInsertId:
401-
return false
402-
}
403397
return true
404398
}
405399

@@ -410,7 +404,7 @@ func NewProcRuleSelector(sel RuleSelector) RuleSelector {
410404
unnestInSubqueriesId,
411405

412406
// once after default rules should only be run once
413-
AutocommitId,
407+
addAutoCommitId,
414408
TrackProcessId,
415409
parallelizeId,
416410
clearWarningsId:
@@ -441,13 +435,11 @@ func NewFinalizeSubquerySel(sel RuleSelector) RuleSelector {
441435
switch id {
442436
case
443437
// skip recursive resolve rules
444-
resolveSubqueryExprsId,
445438
resolveSubqueriesId,
446439
resolveUnionsId,
447440
// skip redundant finalize rules
448441
finalizeSubqueriesId,
449442
hoistOutOfScopeFiltersId,
450-
cacheSubqueryResultsId,
451443
TrackProcessId,
452444
assignExecIndexesId:
453445
return false
@@ -461,7 +453,6 @@ func NewFinalizeUnionSel(sel RuleSelector) RuleSelector {
461453
switch id {
462454
case
463455
// skip recursive resolve rules
464-
resolveSubqueryExprsId,
465456
resolveSubqueriesId,
466457
resolveUnionsId,
467458
parallelizeId:

sql/analyzer/assign_update_join.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/dolthub/go-mysql-server/sql/transform"
1010
)
1111

12-
// modifyUpdateExpressionsForJoin searches for a JOIN for UPDATE query and updates the child of the original update
12+
// modifyUpdateExprsForJoin searches for a JOIN for UPDATE query and updates the child of the original update
1313
// node to use a plan.UpdateJoin node as a child.
14-
func modifyUpdateExpressionsForJoin(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
14+
func modifyUpdateExprsForJoin(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
1515
switch n := n.(type) {
1616
case *plan.Update:
1717
us, ok := n.Child.(*plan.UpdateSource)

sql/analyzer/autocommit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/dolthub/go-mysql-server/sql/transform"
2121
)
2222

23-
// addAutocommitNode wraps each query with a TransactionCommittingNode.
24-
func addAutocommitNode(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
23+
// addAutocommit wraps each query with a TransactionCommittingNode.
24+
func addAutocommit(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
2525
// TODO: This is a bit of a hack. Need to figure out better relationship between new transaction node and warnings.
2626
if FlagIsSet(qFlags, sql.QFlagShowWarnings) {
2727
return n, transform.SameTree, nil

sql/analyzer/node_batches.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func getBatchesForNode(n sql.Node, orig []*Batch) ([]*Batch, bool) {
2626
Iterations: 1,
2727
Rules: []Rule{
2828
{
29-
Id: applyFKsId,
29+
Id: applyForeignKeysId,
3030
Apply: applyForeignKeys,
3131
},
3232
{
@@ -71,7 +71,7 @@ func getBatchesForNode(n sql.Node, orig []*Batch) ([]*Batch, bool) {
7171
Apply: validateReadOnlyTransaction,
7272
},
7373
{
74-
Id: applyFKsId,
74+
Id: applyForeignKeysId,
7575
Apply: applyForeignKeys,
7676
},
7777
{
@@ -120,7 +120,7 @@ func getBatchesForNode(n sql.Node, orig []*Batch) ([]*Batch, bool) {
120120
Apply: processTruncate,
121121
},
122122
{
123-
Id: applyFKsId,
123+
Id: applyForeignKeysId,
124124
Apply: applyForeignKeys,
125125
},
126126
{

sql/analyzer/rule_ids.go

Lines changed: 32 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,38 @@ type RuleId int
66

77
const (
88
// once before
9-
applyDefaultSelectLimitId RuleId = iota // applyDefaultSelectLimit
10-
validateOffsetAndLimitId // validateOffsetAndLimit
11-
validateStarExpressionsId // validateStarExpressions
12-
validateCreateTableId // validateCreateTable
13-
validateAlterTableId // validateAlterTable
14-
validateExprSemId // validateExprSem
15-
resolveVariablesId // resolveVariables
16-
resolveNamedWindowsId // resolveNamedWindows
17-
resolveSetVariablesId // resolveSetVariables
18-
resolveViewsId // resolveViews
19-
liftCtesId // liftCtes
20-
resolveCtesId // resolveCtes
21-
liftRecursiveCtesId // liftRecursiveCtes
22-
resolveDatabasesId // resolveDatabases
23-
resolveTablesId // resolveTables
24-
loadStoredProceduresId // loadStoredProcedures
25-
validateDropTablesId // validateDropTables
26-
pruneDropTablesId // pruneDropTables
27-
setTargetSchemasId // setTargetSchemas
28-
resolveCreateLikeId // resolveCreateLike
29-
parseColumnDefaultsId // parseColumnDefaults
30-
resolveDropConstraintId // resolveDropConstraint
31-
validateDropConstraintId // validateDropConstraint
32-
loadCheckConstraintsId // loadCheckConstraints
33-
assignCatalogId // assignCatalog
34-
resolveAnalyzeTablesId // resolveAnalyzeTables
35-
resolveCreateSelectId // resolveCreateSelect
36-
resolveSubqueriesId // resolveSubqueries
37-
setViewTargetSchemaId // setViewTargetSchema
38-
resolveUnionsId // resolveUnions
39-
resolveDescribeQueryId // resolveDescribeQuery
40-
checkUniqueTableNamesId // checkUniqueTableNames
41-
resolveTableFunctionsId // resolveTableFunctions
42-
resolveDeclarationsId // resolveDeclarations
43-
resolveColumnDefaultsId // resolveColumnDefaults
44-
ValidateColumnDefaultsId // validateColumnDefaults
45-
validateCreateTriggerId // validateCreateTrigger
46-
validateCreateProcedureId // validateCreateProcedure
47-
resolveCreateProcedureId // resolveCreateProcedure
48-
loadInfoSchemaId // loadInfoSchema
49-
validateReadOnlyDatabaseId // validateReadOnlyDatabase
50-
validateReadOnlyTransactionId // validateReadOnlyTransaction
51-
validateDatabaseSetId // validateDatabaseSet
52-
validatePrivilegesId // validatePrivileges
53-
reresolveTablesId // reresolveTables
54-
setInsertColumnsId // setInsertColumns
55-
validateJoinComplexityId // validateJoinComplexity
56-
applyBinlogReplicaControllerId // applyBinlogReplicaController
57-
applyEventSchedulerId // applyEventScheduler
9+
applyDefaultSelectLimitId RuleId = iota // applyDefaultSelectLimit
10+
validateOffsetAndLimitId // validateOffsetAndLimit
11+
validateStarExpressionsId // validateStarExpressions
12+
validateCreateTableId // validateCreateTable
13+
validateAlterTableId // validateAlterTable
14+
validateExprSemId // validateExprSem
15+
loadStoredProceduresId // loadStoredProcedures
16+
validateDropTablesId // validateDropTables
17+
resolveDropConstraintId // resolveDropConstraint
18+
validateDropConstraintId // validateDropConstraint
19+
resolveCreateSelectId // resolveCreateSelect
20+
resolveSubqueriesId // resolveSubqueries
21+
resolveUnionsId // resolveUnions
22+
resolveDescribeQueryId // resolveDescribeQuery
23+
validateColumnDefaultsId // validateColumnDefaults
24+
validateCreateTriggerId // validateCreateTrigger
25+
validateCreateProcedureId // validateCreateProcedure
26+
validateReadOnlyDatabaseId // validateReadOnlyDatabase
27+
validateReadOnlyTransactionId // validateReadOnlyTransaction
28+
validateDatabaseSetId // validateDatabaseSet
29+
validatePrivilegesId // validatePrivileges
30+
applyEventSchedulerId // applyEventScheduler
5831

5932
// default
60-
resolveUsingJoinsId // resolveUsingJoins
61-
resolveOrderbyLiteralsId // resolveOrderbyLiterals
62-
resolveFunctionsId // resolveFunctions
6333
flattenTableAliasesId // flattenTableAliases
64-
pushdownSortId // pushdownSort
65-
pushdownGroupbyAliasesId // pushdownGroupbyAliases
6634
pushdownSubqueryAliasFiltersId // pushdownSubqueryAliasFilters
67-
qualifyColumnsId // qualifyColumns
68-
resolveColumnsId // resolveColumns
69-
validateCheckConstraintId // validateCheckConstraint
70-
resolveBarewordSetVariablesId // resolveBarewordSetVariables
35+
validateCheckConstraintId // validateCheckConstraints
7136
replaceCountStarId // replaceCountStar
72-
expandStarsId // expandStars
73-
transposeRightJoinsId // transposeRightJoins
74-
resolveHavingId // resolveHaving
75-
mergeUnionSchemasId // mergeUnionSchemas
76-
flattenAggregationExprsId // flattenAggregationExprs
77-
reorderProjectionId // reorderProjection
78-
resolveSubqueryExprsId // resolveSubqueryExprs
7937
replaceCrossJoinsId // replaceCrossJoins
80-
moveJoinCondsToFilterId // moveJoinCondsToFilter
81-
moveFiltersToJoinCondId // moveFiltersToJoinCond
38+
moveJoinCondsToFilterId // moveJoinConditionsToFilter
8239
simplifyFiltersId // simplifyFilters
8340
pushNotFiltersId // pushNotFilters
84-
optimizeDistinctId // optimizeDistinct
8541

8642
// after default
8743
hoistOutOfScopeFiltersId // hoistOutOfScopeFilters
@@ -90,59 +46,48 @@ const (
9046
finalizeSubqueriesId // finalizeSubqueries
9147
finalizeUnionsId // finalizeUnions
9248
loadTriggersId // loadTriggers
93-
loadEventsId // loadEvents
9449
processTruncateId // processTruncate
9550
resolveAlterColumnId // resolveAlterColumn
96-
resolveGeneratorsId // resolveGenerators
97-
removeUnnecessaryConvertsId // removeUnnecessaryConverts
9851
stripTableNameInDefaultsId // stripTableNamesFromColumnDefaults
99-
foldEmptyJoinsId // foldEmptyJoins
10052
optimizeJoinsId // optimizeJoins
101-
generateIndexScansId // generateIndexScans
102-
matchAgainstId // matchAgainst
10353
pushFiltersId // pushFilters
10454
applyIndexesFromOuterScopeId // applyIndexesFromOuterScope
10555
pruneTablesId // pruneTables
106-
fixupAuxiliaryExprsId // fixupAuxiliaryExprs
10756
assignExecIndexesId // assignExecIndexes
10857
inlineSubqueryAliasRefsId // inlineSubqueryAliasRefs
10958
eraseProjectionId // eraseProjection
110-
flattenDistinctId //flattenDistinct
59+
flattenDistinctId // flattenDistinct
11160
replaceAggId // replaceAgg
11261
replaceIdxSortId // replaceIdxSort
113-
insertTopNId // insertTopN
62+
insertTopNId // insertTopNNodes
11463
replaceIdxOrderByDistanceId // replaceIdxOrderByDistance
11564
applyHashInId // applyHashIn
11665
resolveInsertRowsId // resolveInsertRows
117-
resolvePreparedInsertId // resolvePreparedInsert
11866
applyTriggersId // applyTriggers
11967
applyProceduresId // applyProcedures
12068
assignRoutinesId // assignRoutines
12169
modifyUpdateExprsForJoinId // modifyUpdateExprsForJoin
122-
applyRowUpdateAccumulatorsId // applyRowUpdateAccumulators
123-
wrapWithRollbackId // rollback triggers
124-
applyFKsId // applyFKs
70+
applyUpdateAccumulatorsId // applyUpdateAccumulators
71+
wrapWithRollbackId // wrapWithRollback
72+
applyForeignKeysId // applyForeignKeys
12573

12674
// validate
12775
validateResolvedId // validateResolved
12876
validateOrderById // validateOrderBy
12977
validateGroupById // validateGroupBy
13078
validateSchemaSourceId // validateSchemaSource
13179
validateIndexCreationId // validateIndexCreation
132-
ValidateOperandsId // validateOperands
133-
validateCaseResultTypesId // validateCaseResultTypes
80+
validateOperandsId // validateOperands
13481
validateIntervalUsageId // validateIntervalUsage
135-
validateExplodeUsageId // validateExplodeUsage
13682
validateSubqueryColumnsId // validateSubqueryColumns
13783
validateUnionSchemasMatchId // validateUnionSchemasMatch
13884
validateAggregationsId // validateAggregations
13985
validateDeleteFromId // validateDeleteFrom
14086

14187
// after all
142-
cacheSubqueryResultsId // cacheSubqueryResults
14388
cacheSubqueryAliasesInJoinsId // cacheSubqueryAliasesInJoins
144-
backtickDefaulColumnValueNamesId // backtickDefaulColumnValueNames
145-
AutocommitId // addAutocommitNode
89+
backtickDefaulColumnValueNamesId // backtickDefaultColumnValueNames
90+
addAutoCommitId // addAutocommit
14691
TrackProcessId // trackProcess
14792
parallelizeId // parallelize
14893
clearWarningsId // clearWarnings

0 commit comments

Comments
 (0)