github.com/dolthub/go-mysql-server@v0.18.0/sql/analyzer/rules.go (about)

     1  // Copyright 2020-2021 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package analyzer
    16  
    17  // OnceBeforeDefault contains the rules to be applied just once before the
    18  // DefaultRules.
    19  var OnceBeforeDefault = []Rule{
    20  	{applyDefaultSelectLimitId, applyDefaultSelectLimit},
    21  	{replaceCountStarId, replaceCountStar},
    22  	{applyEventSchedulerId, applyEventScheduler},
    23  	{validateOffsetAndLimitId, validateLimitAndOffset},
    24  	{validateCreateTableId, validateCreateTable},
    25  	{validateAlterTableId, validateAlterTable},
    26  	{validateExprSemId, validateExprSem},
    27  	{validateCreateProcedureId, validateCreateProcedure},
    28  	{resolveDropConstraintId, resolveDropConstraint},
    29  	{resolveAlterColumnId, resolveAlterColumn},
    30  	{validateDropTablesId, validateDropTables},
    31  	{resolveCreateSelectId, resolveCreateSelect},
    32  	{validateDropConstraintId, validateDropConstraint},
    33  	{resolveUnionsId, resolveUnions},
    34  	{resolveDescribeQueryId, resolveDescribeQuery}, //TODO
    35  	{validateCreateTriggerId, validateCreateTrigger},
    36  	{validateColumnDefaultsId, validateColumnDefaults},
    37  	{validateReadOnlyDatabaseId, validateReadOnlyDatabase},
    38  	{validateReadOnlyTransactionId, validateReadOnlyTransaction},
    39  	{validateDatabaseSetId, validateDatabaseSet},
    40  	{validateDeleteFromId, validateDeleteFrom},
    41  	{validatePrivilegesId, validatePrivileges}, // Ensure that checking privileges happens after db, table  & table function resolution
    42  	{simplifyFiltersId, simplifyFilters},       //TODO inline?
    43  	{pushNotFiltersId, pushNotFilters},         //TODO inline?
    44  	{hoistOutOfScopeFiltersId, hoistOutOfScopeFilters},
    45  }
    46  
    47  // DefaultRules to apply when analyzing nodes.
    48  var DefaultRules = []Rule{
    49  	{validateStarExpressionsId, validateStarExpressions}, //TODO
    50  	{pushdownSubqueryAliasFiltersId, pushdownSubqueryAliasFilters},
    51  	{pruneTablesId, pruneTables},
    52  	{validateCheckConstraintId, validateCheckConstraints},
    53  	{unnestInSubqueriesId, unnestInSubqueries},
    54  	{resolveSubqueriesId, resolveSubqueries},
    55  	{replaceCrossJoinsId, replaceCrossJoins},
    56  }
    57  
    58  var OnceAfterDefault = []Rule{
    59  	{unnestExistsSubqueriesId, unnestExistsSubqueries},
    60  	{moveJoinCondsToFilterId, moveJoinConditionsToFilter},
    61  	{finalizeUnionsId, finalizeUnions},
    62  	{loadTriggersId, loadTriggers},
    63  	{processTruncateId, processTruncate},
    64  	{stripTableNameInDefaultsId, stripTableNamesFromColumnDefaults},
    65  	{pushFiltersId, pushFilters},
    66  	{optimizeJoinsId, optimizeJoins},
    67  	{finalizeSubqueriesId, finalizeSubqueries},
    68  	{applyIndexesFromOuterScopeId, applyIndexesFromOuterScope},
    69  	{replaceAggId, replaceAgg},
    70  	{replaceIdxSortId, replaceIdxSort},
    71  	{eraseProjectionId, eraseProjection},
    72  	{flattenDistinctId, flattenDistinct},
    73  	{insertTopNId, insertTopNNodes},
    74  	{applyHashInId, applyHashIn},
    75  	{assignRoutinesId, assignRoutines},
    76  	{modifyUpdateExprsForJoinId, modifyUpdateExpressionsForJoin},
    77  	{applyFKsId, applyForeignKeys},
    78  }
    79  
    80  // DefaultValidationRules to apply while analyzing nodes.
    81  var DefaultValidationRules = []Rule{
    82  	{validateResolvedId, validateIsResolved},
    83  	{validateOrderById, validateOrderBy},
    84  	{validateGroupById, validateGroupBy},
    85  	{validateSchemaSourceId, validateSchemaSource},
    86  	{validateIndexCreationId, validateIndexCreation},
    87  	{validateOperandsId, validateOperands},
    88  	{validateIntervalUsageId, validateIntervalUsage},
    89  	{validateSubqueryColumnsId, validateSubqueryColumns},
    90  	{validateUnionSchemasMatchId, validateUnionSchemasMatch},
    91  	{validateAggregationsId, validateAggregations},
    92  }
    93  
    94  var OnceAfterAll = []Rule{
    95  	{assignExecIndexesId, assignExecIndexes},
    96  	// resolveInsertRows inserts a projection wrapping values that cannot be seen by fixup
    97  	{resolveInsertRowsId, resolveInsertRows},
    98  	{applyTriggersId, applyTriggers},
    99  	{applyProceduresId, applyProcedures},
   100  	{applyRowUpdateAccumulatorsId, applyUpdateAccumulators},
   101  	{wrapWithRollbackId, wrapWritesWithRollback},
   102  	{inlineSubqueryAliasRefsId, inlineSubqueryAliasRefs},
   103  	{cacheSubqueryAliasesInJoinsId, cacheSubqueryAliasesInJoins},
   104  
   105  	{backtickDefaulColumnValueNamesId, backtickDefaultColumnValueNames},
   106  
   107  	{AutocommitId, addAutocommitNode},
   108  	{TrackProcessId, trackProcess},
   109  	{parallelizeId, parallelize},
   110  	{clearWarningsId, clearWarnings},
   111  }