diff --git a/sql/analyzer/analyzer.go b/sql/analyzer/analyzer.go index 8a2834ecbb..c33f426ee5 100644 --- a/sql/analyzer/analyzer.go +++ b/sql/analyzer/analyzer.go @@ -394,12 +394,6 @@ func (a *Analyzer) PopDebugContext() { func SelectAllBatches(string) bool { return true } func DefaultRuleSelector(id RuleId) bool { - switch id { - // prepared statement rules are incompatible with default rules - case reresolveTablesId, - resolvePreparedInsertId: - return false - } return true } @@ -441,13 +435,11 @@ func NewFinalizeSubquerySel(sel RuleSelector) RuleSelector { switch id { case // skip recursive resolve rules - resolveSubqueryExprsId, resolveSubqueriesId, resolveUnionsId, // skip redundant finalize rules finalizeSubqueriesId, hoistOutOfScopeFiltersId, - cacheSubqueryResultsId, TrackProcessId, assignExecIndexesId: return false @@ -461,7 +453,6 @@ func NewFinalizeUnionSel(sel RuleSelector) RuleSelector { switch id { case // skip recursive resolve rules - resolveSubqueryExprsId, resolveSubqueriesId, resolveUnionsId, parallelizeId: diff --git a/sql/analyzer/assign_update_join.go b/sql/analyzer/assign_update_join.go index b16ab07193..982fee825e 100644 --- a/sql/analyzer/assign_update_join.go +++ b/sql/analyzer/assign_update_join.go @@ -9,9 +9,9 @@ import ( "github.com/dolthub/go-mysql-server/sql/transform" ) -// modifyUpdateExpressionsForJoin searches for a JOIN for UPDATE query and updates the child of the original update +// modifyUpdateExprsForJoin searches for a JOIN for UPDATE query and updates the child of the original update // node to use a plan.UpdateJoin node as a child. -func modifyUpdateExpressionsForJoin(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { +func modifyUpdateExprsForJoin(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { switch n := n.(type) { case *plan.Update: us, ok := n.Child.(*plan.UpdateSource) diff --git a/sql/analyzer/autocommit.go b/sql/analyzer/autocommit.go index 022d09105a..f720736be9 100644 --- a/sql/analyzer/autocommit.go +++ b/sql/analyzer/autocommit.go @@ -20,8 +20,8 @@ import ( "github.com/dolthub/go-mysql-server/sql/transform" ) -// addAutocommitNode wraps each query with a TransactionCommittingNode. -func addAutocommitNode(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { +// addAutocommit wraps each query with a TransactionCommittingNode. +func addAutocommit(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { // TODO: This is a bit of a hack. Need to figure out better relationship between new transaction node and warnings. if FlagIsSet(qFlags, sql.QFlagShowWarnings) { return n, transform.SameTree, nil diff --git a/sql/analyzer/node_batches.go b/sql/analyzer/node_batches.go index 50fd8f2505..d824d58dfd 100644 --- a/sql/analyzer/node_batches.go +++ b/sql/analyzer/node_batches.go @@ -26,7 +26,7 @@ func getBatchesForNode(n sql.Node, orig []*Batch) ([]*Batch, bool) { Iterations: 1, Rules: []Rule{ { - Id: applyFKsId, + Id: applyForeignKeysId, Apply: applyForeignKeys, }, { @@ -71,7 +71,7 @@ func getBatchesForNode(n sql.Node, orig []*Batch) ([]*Batch, bool) { Apply: validateReadOnlyTransaction, }, { - Id: applyFKsId, + Id: applyForeignKeysId, Apply: applyForeignKeys, }, { @@ -120,7 +120,7 @@ func getBatchesForNode(n sql.Node, orig []*Batch) ([]*Batch, bool) { Apply: processTruncate, }, { - Id: applyFKsId, + Id: applyForeignKeysId, Apply: applyForeignKeys, }, { diff --git a/sql/analyzer/rule_ids.go b/sql/analyzer/rule_ids.go index a99404d087..5c5d01b173 100644 --- a/sql/analyzer/rule_ids.go +++ b/sql/analyzer/rule_ids.go @@ -6,82 +6,38 @@ type RuleId int const ( // once before - applyDefaultSelectLimitId RuleId = iota // applyDefaultSelectLimit - validateOffsetAndLimitId // validateOffsetAndLimit - validateStarExpressionsId // validateStarExpressions - validateCreateTableId // validateCreateTable - validateAlterTableId // validateAlterTable - validateExprSemId // validateExprSem - resolveVariablesId // resolveVariables - resolveNamedWindowsId // resolveNamedWindows - resolveSetVariablesId // resolveSetVariables - resolveViewsId // resolveViews - liftCtesId // liftCtes - resolveCtesId // resolveCtes - liftRecursiveCtesId // liftRecursiveCtes - resolveDatabasesId // resolveDatabases - resolveTablesId // resolveTables - loadStoredProceduresId // loadStoredProcedures - validateDropTablesId // validateDropTables - pruneDropTablesId // pruneDropTables - setTargetSchemasId // setTargetSchemas - resolveCreateLikeId // resolveCreateLike - parseColumnDefaultsId // parseColumnDefaults - resolveDropConstraintId // resolveDropConstraint - validateDropConstraintId // validateDropConstraint - loadCheckConstraintsId // loadCheckConstraints - assignCatalogId // assignCatalog - resolveAnalyzeTablesId // resolveAnalyzeTables - resolveCreateSelectId // resolveCreateSelect - resolveSubqueriesId // resolveSubqueries - setViewTargetSchemaId // setViewTargetSchema - resolveUnionsId // resolveUnions - resolveDescribeQueryId // resolveDescribeQuery - checkUniqueTableNamesId // checkUniqueTableNames - resolveTableFunctionsId // resolveTableFunctions - resolveDeclarationsId // resolveDeclarations - resolveColumnDefaultsId // resolveColumnDefaults - ValidateColumnDefaultsId // validateColumnDefaults - validateCreateTriggerId // validateCreateTrigger - validateCreateProcedureId // validateCreateProcedure - resolveCreateProcedureId // resolveCreateProcedure - loadInfoSchemaId // loadInfoSchema - validateReadOnlyDatabaseId // validateReadOnlyDatabase - validateReadOnlyTransactionId // validateReadOnlyTransaction - validateDatabaseSetId // validateDatabaseSet - validatePrivilegesId // validatePrivileges - reresolveTablesId // reresolveTables - setInsertColumnsId // setInsertColumns - validateJoinComplexityId // validateJoinComplexity - applyBinlogReplicaControllerId // applyBinlogReplicaController - applyEventSchedulerId // applyEventScheduler + applyDefaultSelectLimitId RuleId = iota // applyDefaultSelectLimit + validateOffsetAndLimitId // validateOffsetAndLimit + validateStarExpressionsId // validateStarExpressions + validateCreateTableId // validateCreateTable + validateAlterTableId // validateAlterTable + validateExprSemId // validateExprSem + loadStoredProceduresId // loadStoredProcedures + validateDropTablesId // validateDropTables + resolveDropConstraintId // resolveDropConstraint + validateDropConstraintId // validateDropConstraint + resolveCreateSelectId // resolveCreateSelect + resolveSubqueriesId // resolveSubqueries + resolveUnionsId // resolveUnions + resolveDescribeQueryId // resolveDescribeQuery + ValidateColumnDefaultsId // validateColumnDefaults + validateCreateTriggerId // validateCreateTrigger + validateCreateProcedureId // validateCreateProcedure + validateReadOnlyDatabaseId // validateReadOnlyDatabase + validateReadOnlyTransactionId // validateReadOnlyTransaction + validateDatabaseSetId // validateDatabaseSet + validatePrivilegesId // validatePrivileges + applyEventSchedulerId // applyEventScheduler // default - resolveUsingJoinsId // resolveUsingJoins - resolveOrderbyLiteralsId // resolveOrderbyLiterals - resolveFunctionsId // resolveFunctions flattenTableAliasesId // flattenTableAliases - pushdownSortId // pushdownSort - pushdownGroupbyAliasesId // pushdownGroupbyAliases pushdownSubqueryAliasFiltersId // pushdownSubqueryAliasFilters - qualifyColumnsId // qualifyColumns - resolveColumnsId // resolveColumns - validateCheckConstraintId // validateCheckConstraint - resolveBarewordSetVariablesId // resolveBarewordSetVariables + validateCheckConstraintId // validateCheckConstraints replaceCountStarId // replaceCountStar - expandStarsId // expandStars - transposeRightJoinsId // transposeRightJoins - resolveHavingId // resolveHaving - mergeUnionSchemasId // mergeUnionSchemas - flattenAggregationExprsId // flattenAggregationExprs - reorderProjectionId // reorderProjection - resolveSubqueryExprsId // resolveSubqueryExprs replaceCrossJoinsId // replaceCrossJoins - moveJoinCondsToFilterId // moveJoinCondsToFilter - moveFiltersToJoinCondId // moveFiltersToJoinCond + moveJoinCondsToFilterId // moveJoinConditionsToFilter simplifyFiltersId // simplifyFilters pushNotFiltersId // pushNotFilters - optimizeDistinctId // optimizeDistinct // after default hoistOutOfScopeFiltersId // hoistOutOfScopeFilters @@ -90,38 +46,30 @@ const ( finalizeSubqueriesId // finalizeSubqueries finalizeUnionsId // finalizeUnions loadTriggersId // loadTriggers - loadEventsId // loadEvents processTruncateId // processTruncate resolveAlterColumnId // resolveAlterColumn - resolveGeneratorsId // resolveGenerators - removeUnnecessaryConvertsId // removeUnnecessaryConverts stripTableNameInDefaultsId // stripTableNamesFromColumnDefaults - foldEmptyJoinsId // foldEmptyJoins optimizeJoinsId // optimizeJoins - generateIndexScansId // generateIndexScans - matchAgainstId // matchAgainst pushFiltersId // pushFilters applyIndexesFromOuterScopeId // applyIndexesFromOuterScope pruneTablesId // pruneTables - fixupAuxiliaryExprsId // fixupAuxiliaryExprs assignExecIndexesId // assignExecIndexes inlineSubqueryAliasRefsId // inlineSubqueryAliasRefs eraseProjectionId // eraseProjection - flattenDistinctId //flattenDistinct + flattenDistinctId // flattenDistinct replaceAggId // replaceAgg replaceIdxSortId // replaceIdxSort - insertTopNId // insertTopN + insertTopNId // insertTopNNodes replaceIdxOrderByDistanceId // replaceIdxOrderByDistance applyHashInId // applyHashIn resolveInsertRowsId // resolveInsertRows - resolvePreparedInsertId // resolvePreparedInsert applyTriggersId // applyTriggers applyProceduresId // applyProcedures assignRoutinesId // assignRoutines modifyUpdateExprsForJoinId // modifyUpdateExprsForJoin - applyRowUpdateAccumulatorsId // applyRowUpdateAccumulators - wrapWithRollbackId // rollback triggers - applyFKsId // applyFKs + applyUpdateAccumulatorsId // applyUpdateAccumulators + wrapWithRollbackId // wrapWithRollback + applyForeignKeysId // applyForeignKeys // validate validateResolvedId // validateResolved @@ -130,19 +78,16 @@ const ( validateSchemaSourceId // validateSchemaSource validateIndexCreationId // validateIndexCreation ValidateOperandsId // validateOperands - validateCaseResultTypesId // validateCaseResultTypes validateIntervalUsageId // validateIntervalUsage - validateExplodeUsageId // validateExplodeUsage validateSubqueryColumnsId // validateSubqueryColumns validateUnionSchemasMatchId // validateUnionSchemasMatch validateAggregationsId // validateAggregations validateDeleteFromId // validateDeleteFrom // after all - cacheSubqueryResultsId // cacheSubqueryResults cacheSubqueryAliasesInJoinsId // cacheSubqueryAliasesInJoins - backtickDefaulColumnValueNamesId // backtickDefaulColumnValueNames - AutocommitId // addAutocommitNode + backtickDefaulColumnValueNamesId // backtickDefaultColumnValueNames + AutocommitId // addAutocommit TrackProcessId // trackProcess parallelizeId // parallelize clearWarningsId // clearWarnings diff --git a/sql/analyzer/ruleid_string.go b/sql/analyzer/ruleid_string.go index af9abbb3ae..0d12dd8320 100755 --- a/sql/analyzer/ruleid_string.go +++ b/sql/analyzer/ruleid_string.go @@ -14,137 +14,82 @@ func _() { _ = x[validateCreateTableId-3] _ = x[validateAlterTableId-4] _ = x[validateExprSemId-5] - _ = x[resolveVariablesId-6] - _ = x[resolveNamedWindowsId-7] - _ = x[resolveSetVariablesId-8] - _ = x[resolveViewsId-9] - _ = x[liftCtesId-10] - _ = x[resolveCtesId-11] - _ = x[liftRecursiveCtesId-12] - _ = x[resolveDatabasesId-13] - _ = x[resolveTablesId-14] - _ = x[loadStoredProceduresId-15] - _ = x[validateDropTablesId-16] - _ = x[pruneDropTablesId-17] - _ = x[setTargetSchemasId-18] - _ = x[resolveCreateLikeId-19] - _ = x[parseColumnDefaultsId-20] - _ = x[resolveDropConstraintId-21] - _ = x[validateDropConstraintId-22] - _ = x[loadCheckConstraintsId-23] - _ = x[assignCatalogId-24] - _ = x[resolveAnalyzeTablesId-25] - _ = x[resolveCreateSelectId-26] - _ = x[resolveSubqueriesId-27] - _ = x[setViewTargetSchemaId-28] - _ = x[resolveUnionsId-29] - _ = x[resolveDescribeQueryId-30] - _ = x[checkUniqueTableNamesId-31] - _ = x[resolveTableFunctionsId-32] - _ = x[resolveDeclarationsId-33] - _ = x[resolveColumnDefaultsId-34] - _ = x[ValidateColumnDefaultsId-35] - _ = x[validateCreateTriggerId-36] - _ = x[validateCreateProcedureId-37] - _ = x[resolveCreateProcedureId-38] - _ = x[loadInfoSchemaId-39] - _ = x[validateReadOnlyDatabaseId-40] - _ = x[validateReadOnlyTransactionId-41] - _ = x[validateDatabaseSetId-42] - _ = x[validatePrivilegesId-43] - _ = x[reresolveTablesId-44] - _ = x[setInsertColumnsId-45] - _ = x[validateJoinComplexityId-46] - _ = x[applyBinlogReplicaControllerId-47] - _ = x[applyEventSchedulerId-48] - _ = x[resolveUsingJoinsId-49] - _ = x[resolveOrderbyLiteralsId-50] - _ = x[resolveFunctionsId-51] - _ = x[flattenTableAliasesId-52] - _ = x[pushdownSortId-53] - _ = x[pushdownGroupbyAliasesId-54] - _ = x[pushdownSubqueryAliasFiltersId-55] - _ = x[qualifyColumnsId-56] - _ = x[resolveColumnsId-57] - _ = x[validateCheckConstraintId-58] - _ = x[resolveBarewordSetVariablesId-59] - _ = x[replaceCountStarId-60] - _ = x[expandStarsId-61] - _ = x[transposeRightJoinsId-62] - _ = x[resolveHavingId-63] - _ = x[mergeUnionSchemasId-64] - _ = x[flattenAggregationExprsId-65] - _ = x[reorderProjectionId-66] - _ = x[resolveSubqueryExprsId-67] - _ = x[replaceCrossJoinsId-68] - _ = x[moveJoinCondsToFilterId-69] - _ = x[moveFiltersToJoinCondId-70] - _ = x[simplifyFiltersId-71] - _ = x[pushNotFiltersId-72] - _ = x[optimizeDistinctId-73] - _ = x[hoistOutOfScopeFiltersId-74] - _ = x[unnestInSubqueriesId-75] - _ = x[unnestExistsSubqueriesId-76] - _ = x[finalizeSubqueriesId-77] - _ = x[finalizeUnionsId-78] - _ = x[loadTriggersId-79] - _ = x[loadEventsId-80] - _ = x[processTruncateId-81] - _ = x[resolveAlterColumnId-82] - _ = x[resolveGeneratorsId-83] - _ = x[removeUnnecessaryConvertsId-84] - _ = x[stripTableNameInDefaultsId-85] - _ = x[foldEmptyJoinsId-86] - _ = x[optimizeJoinsId-87] - _ = x[generateIndexScansId-88] - _ = x[matchAgainstId-89] - _ = x[pushFiltersId-90] - _ = x[applyIndexesFromOuterScopeId-91] - _ = x[pruneTablesId-92] - _ = x[fixupAuxiliaryExprsId-93] - _ = x[assignExecIndexesId-94] - _ = x[inlineSubqueryAliasRefsId-95] - _ = x[eraseProjectionId-96] - _ = x[flattenDistinctId-97] - _ = x[replaceAggId-98] - _ = x[replaceIdxSortId-99] - _ = x[insertTopNId-100] - _ = x[replaceIdxOrderByDistanceId-101] - _ = x[applyHashInId-102] - _ = x[resolveInsertRowsId-103] - _ = x[resolvePreparedInsertId-104] - _ = x[applyTriggersId-105] - _ = x[applyProceduresId-106] - _ = x[assignRoutinesId-107] - _ = x[modifyUpdateExprsForJoinId-108] - _ = x[applyRowUpdateAccumulatorsId-109] - _ = x[wrapWithRollbackId-110] - _ = x[applyFKsId-111] - _ = x[validateResolvedId-112] - _ = x[validateOrderById-113] - _ = x[validateGroupById-114] - _ = x[validateSchemaSourceId-115] - _ = x[validateIndexCreationId-116] - _ = x[ValidateOperandsId-117] - _ = x[validateCaseResultTypesId-118] - _ = x[validateIntervalUsageId-119] - _ = x[validateExplodeUsageId-120] - _ = x[validateSubqueryColumnsId-121] - _ = x[validateUnionSchemasMatchId-122] - _ = x[validateAggregationsId-123] - _ = x[validateDeleteFromId-124] - _ = x[cacheSubqueryResultsId-125] - _ = x[cacheSubqueryAliasesInJoinsId-126] - _ = x[backtickDefaulColumnValueNamesId-127] - _ = x[AutocommitId-128] - _ = x[TrackProcessId-129] - _ = x[parallelizeId-130] - _ = x[clearWarningsId-131] + _ = x[loadStoredProceduresId-6] + _ = x[validateDropTablesId-7] + _ = x[resolveDropConstraintId-8] + _ = x[validateDropConstraintId-9] + _ = x[resolveCreateSelectId-10] + _ = x[resolveSubqueriesId-11] + _ = x[resolveUnionsId-12] + _ = x[resolveDescribeQueryId-13] + _ = x[ValidateColumnDefaultsId-14] + _ = x[validateCreateTriggerId-15] + _ = x[validateCreateProcedureId-16] + _ = x[validateReadOnlyDatabaseId-17] + _ = x[validateReadOnlyTransactionId-18] + _ = x[validateDatabaseSetId-19] + _ = x[validatePrivilegesId-20] + _ = x[applyEventSchedulerId-21] + _ = x[flattenTableAliasesId-22] + _ = x[pushdownSubqueryAliasFiltersId-23] + _ = x[validateCheckConstraintId-24] + _ = x[replaceCountStarId-25] + _ = x[replaceCrossJoinsId-26] + _ = x[moveJoinCondsToFilterId-27] + _ = x[simplifyFiltersId-28] + _ = x[pushNotFiltersId-29] + _ = x[hoistOutOfScopeFiltersId-30] + _ = x[unnestInSubqueriesId-31] + _ = x[unnestExistsSubqueriesId-32] + _ = x[finalizeSubqueriesId-33] + _ = x[finalizeUnionsId-34] + _ = x[loadTriggersId-35] + _ = x[processTruncateId-36] + _ = x[resolveAlterColumnId-37] + _ = x[stripTableNameInDefaultsId-38] + _ = x[optimizeJoinsId-39] + _ = x[pushFiltersId-40] + _ = x[applyIndexesFromOuterScopeId-41] + _ = x[pruneTablesId-42] + _ = x[assignExecIndexesId-43] + _ = x[inlineSubqueryAliasRefsId-44] + _ = x[eraseProjectionId-45] + _ = x[flattenDistinctId-46] + _ = x[replaceAggId-47] + _ = x[replaceIdxSortId-48] + _ = x[insertTopNId-49] + _ = x[replaceIdxOrderByDistanceId-50] + _ = x[applyHashInId-51] + _ = x[resolveInsertRowsId-52] + _ = x[applyTriggersId-53] + _ = x[applyProceduresId-54] + _ = x[assignRoutinesId-55] + _ = x[modifyUpdateExprsForJoinId-56] + _ = x[applyUpdateAccumulatorsId-57] + _ = x[wrapWithRollbackId-58] + _ = x[applyForeignKeysId-59] + _ = x[validateResolvedId-60] + _ = x[validateOrderById-61] + _ = x[validateGroupById-62] + _ = x[validateSchemaSourceId-63] + _ = x[validateIndexCreationId-64] + _ = x[ValidateOperandsId-65] + _ = x[validateIntervalUsageId-66] + _ = x[validateSubqueryColumnsId-67] + _ = x[validateUnionSchemasMatchId-68] + _ = x[validateAggregationsId-69] + _ = x[validateDeleteFromId-70] + _ = x[cacheSubqueryAliasesInJoinsId-71] + _ = x[backtickDefaulColumnValueNamesId-72] + _ = x[AutocommitId-73] + _ = x[TrackProcessId-74] + _ = x[parallelizeId-75] + _ = x[clearWarningsId-76] } -const _RuleId_name = "applyDefaultSelectLimitvalidateOffsetAndLimitvalidateStarExpressionsvalidateCreateTablevalidateAlterTablevalidateExprSemresolveVariablesresolveNamedWindowsresolveSetVariablesresolveViewsliftCtesresolveCtesliftRecursiveCtesresolveDatabasesresolveTablesloadStoredProceduresvalidateDropTablespruneDropTablessetTargetSchemasresolveCreateLikeparseColumnDefaultsresolveDropConstraintvalidateDropConstraintloadCheckConstraintsassignCatalogresolveAnalyzeTablesresolveCreateSelectresolveSubqueriessetViewTargetSchemaresolveUnionsresolveDescribeQuerycheckUniqueTableNamesresolveTableFunctionsresolveDeclarationsresolveColumnDefaultsvalidateColumnDefaultsvalidateCreateTriggervalidateCreateProcedureresolveCreateProcedureloadInfoSchemavalidateReadOnlyDatabasevalidateReadOnlyTransactionvalidateDatabaseSetvalidatePrivilegesreresolveTablessetInsertColumnsvalidateJoinComplexityapplyBinlogReplicaControllerapplyEventSchedulerresolveUsingJoinsresolveOrderbyLiteralsresolveFunctionsflattenTableAliasespushdownSortpushdownGroupbyAliasespushdownSubqueryAliasFiltersqualifyColumnsresolveColumnsvalidateCheckConstraintresolveBarewordSetVariablesreplaceCountStarexpandStarstransposeRightJoinsresolveHavingmergeUnionSchemasflattenAggregationExprsreorderProjectionresolveSubqueryExprsreplaceCrossJoinsmoveJoinCondsToFiltermoveFiltersToJoinCondsimplifyFilterspushNotFiltersoptimizeDistincthoistOutOfScopeFiltersunnestInSubqueriesunnestExistsSubqueriesfinalizeSubqueriesfinalizeUnionsloadTriggersloadEventsprocessTruncateresolveAlterColumnresolveGeneratorsremoveUnnecessaryConvertsstripTableNamesFromColumnDefaultsfoldEmptyJoinsoptimizeJoinsgenerateIndexScansmatchAgainstpushFiltersapplyIndexesFromOuterScopepruneTablesfixupAuxiliaryExprsassignExecIndexesinlineSubqueryAliasRefseraseProjectionflattenDistinctreplaceAggreplaceIdxSortinsertTopNreplaceIdxOrderByDistanceapplyHashInresolveInsertRowsresolvePreparedInsertapplyTriggersapplyProceduresassignRoutinesmodifyUpdateExprsForJoinapplyRowUpdateAccumulatorsrollback triggersapplyFKsvalidateResolvedvalidateOrderByvalidateGroupByvalidateSchemaSourcevalidateIndexCreationvalidateOperandsvalidateCaseResultTypesvalidateIntervalUsagevalidateExplodeUsagevalidateSubqueryColumnsvalidateUnionSchemasMatchvalidateAggregationsvalidateDeleteFromcacheSubqueryResultscacheSubqueryAliasesInJoinsbacktickDefaulColumnValueNamesaddAutocommitNodetrackProcessparallelizeclearWarnings" +const _RuleId_name = "applyDefaultSelectLimitvalidateOffsetAndLimitvalidateStarExpressionsvalidateCreateTablevalidateAlterTablevalidateExprSemloadStoredProceduresvalidateDropTablesresolveDropConstraintvalidateDropConstraintresolveCreateSelectresolveSubqueriesresolveUnionsresolveDescribeQueryvalidateColumnDefaultsvalidateCreateTriggervalidateCreateProcedurevalidateReadOnlyDatabasevalidateReadOnlyTransactionvalidateDatabaseSetvalidatePrivilegesapplyEventSchedulerflattenTableAliasespushdownSubqueryAliasFiltersvalidateCheckConstraintsreplaceCountStarreplaceCrossJoinsmoveJoinConditionsToFiltersimplifyFilterspushNotFiltershoistOutOfScopeFiltersunnestInSubqueriesunnestExistsSubqueriesfinalizeSubqueriesfinalizeUnionsloadTriggersprocessTruncateresolveAlterColumnstripTableNamesFromColumnDefaultsoptimizeJoinspushFiltersapplyIndexesFromOuterScopepruneTablesassignExecIndexesinlineSubqueryAliasRefseraseProjectionflattenDistinctreplaceAggreplaceIdxSortinsertTopNNodesreplaceIdxOrderByDistanceapplyHashInresolveInsertRowsapplyTriggersapplyProceduresassignRoutinesmodifyUpdateExprsForJoinapplyUpdateAccumulatorswrapWithRollbackapplyForeignKeysvalidateResolvedvalidateOrderByvalidateGroupByvalidateSchemaSourcevalidateIndexCreationvalidateOperandsvalidateIntervalUsagevalidateSubqueryColumnsvalidateUnionSchemasMatchvalidateAggregationsvalidateDeleteFromcacheSubqueryAliasesInJoinsbacktickDefaultColumnValueNamesaddAutocommittrackProcessparallelizeclearWarnings" -var _RuleId_index = [...]uint16{0, 23, 45, 68, 87, 105, 120, 136, 155, 174, 186, 194, 205, 222, 238, 251, 271, 289, 304, 320, 337, 356, 377, 399, 419, 432, 452, 471, 488, 507, 520, 540, 561, 582, 601, 622, 644, 665, 688, 710, 724, 748, 775, 794, 812, 827, 843, 865, 893, 912, 929, 951, 967, 986, 998, 1020, 1048, 1062, 1076, 1099, 1126, 1142, 1153, 1172, 1185, 1202, 1225, 1242, 1262, 1279, 1300, 1321, 1336, 1350, 1366, 1388, 1406, 1428, 1446, 1460, 1472, 1482, 1497, 1515, 1532, 1557, 1590, 1604, 1617, 1635, 1647, 1658, 1684, 1695, 1714, 1731, 1754, 1769, 1784, 1794, 1808, 1818, 1843, 1854, 1871, 1892, 1905, 1920, 1934, 1958, 1984, 2001, 2009, 2025, 2040, 2055, 2075, 2096, 2112, 2135, 2156, 2176, 2199, 2224, 2244, 2262, 2282, 2309, 2339, 2356, 2368, 2379, 2392} +var _RuleId_index = [...]uint16{0, 23, 45, 68, 87, 105, 120, 140, 158, 179, 201, 220, 237, 250, 270, 292, 313, 336, 360, 387, 406, 424, 443, 462, 490, 514, 530, 547, 573, 588, 602, 624, 642, 664, 682, 696, 708, 723, 741, 774, 787, 798, 824, 835, 852, 875, 890, 905, 915, 929, 944, 969, 980, 997, 1010, 1025, 1039, 1063, 1086, 1102, 1118, 1134, 1149, 1164, 1184, 1205, 1221, 1242, 1265, 1290, 1310, 1328, 1355, 1386, 1399, 1411, 1422, 1435} func (i RuleId) String() string { if i < 0 || i >= RuleId(len(_RuleId_index)-1) { diff --git a/sql/analyzer/rules.go b/sql/analyzer/rules.go index dbfd801e5a..85cd895a34 100644 --- a/sql/analyzer/rules.go +++ b/sql/analyzer/rules.go @@ -21,12 +21,12 @@ func init() { {resolveInsertRowsId, resolveInsertRows}, {applyTriggersId, applyTriggers}, {applyProceduresId, applyProcedures}, - {applyRowUpdateAccumulatorsId, applyUpdateAccumulators}, - {wrapWithRollbackId, wrapWritesWithRollback}, + {applyUpdateAccumulatorsId, applyUpdateAccumulators}, + {wrapWithRollbackId, wrapWithRollback}, {inlineSubqueryAliasRefsId, inlineSubqueryAliasRefs}, {cacheSubqueryAliasesInJoinsId, cacheSubqueryAliasesInJoins}, {backtickDefaulColumnValueNamesId, backtickDefaultColumnValueNames}, - {AutocommitId, addAutocommitNode}, + {AutocommitId, addAutocommit}, {TrackProcessId, trackProcess}, {parallelizeId, parallelize}, {clearWarningsId, clearWarnings}, @@ -99,13 +99,13 @@ var OnceAfterDefault = []Rule{ {replaceIdxOrderByDistanceId, replaceIdxOrderByDistance}, {applyHashInId, applyHashIn}, {assignRoutinesId, assignRoutines}, - {modifyUpdateExprsForJoinId, modifyUpdateExpressionsForJoin}, - {applyFKsId, applyForeignKeys}, + {modifyUpdateExprsForJoinId, modifyUpdateExprsForJoin}, + {applyForeignKeysId, applyForeignKeys}, } // DefaultValidationRules to apply while analyzing nodes. var DefaultValidationRules = []Rule{ - {validateResolvedId, validateIsResolved}, + {validateResolvedId, validateResolved}, {validateOrderById, validateOrderBy}, {validateGroupById, validateGroupBy}, {validateSchemaSourceId, validateSchemaSource}, diff --git a/sql/analyzer/stored_procedures.go b/sql/analyzer/stored_procedures.go index d1b1575b80..26f1584711 100644 --- a/sql/analyzer/stored_procedures.go +++ b/sql/analyzer/stored_procedures.go @@ -133,10 +133,9 @@ func analyzeProcedureBodies(ctx *sql.Context, a *Analyzer, node sql.Node, skipCa if err != nil { return nil, transform.SameTree, err } - // Blocks may have expressions declared directly on them, so we explicitly analyze the block node for variables - rulesToRun := []RuleId{resolveVariablesId} // If a block node also has expressions (e.g. IfConditional), then we need to run the // finalizeSubqueries analyzer rule in case the expressions contain any subqueries. + var rulesToRun []RuleId if _, ok := child.(sql.Expressioner); ok { rulesToRun = append(rulesToRun, finalizeSubqueriesId, assignExecIndexesId) } diff --git a/sql/analyzer/triggers.go b/sql/analyzer/triggers.go index 4fe8d89db1..e60ced633b 100644 --- a/sql/analyzer/triggers.go +++ b/sql/analyzer/triggers.go @@ -424,7 +424,7 @@ func getTriggerLogic(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop // statements, we need the raw output from them. var noRowUpdateAccumulators RuleSelector noRowUpdateAccumulators = func(id RuleId) bool { - return DefaultRuleSelector(id) && id != applyRowUpdateAccumulatorsId + return DefaultRuleSelector(id) && id != applyUpdateAccumulatorsId } // For the reference to the row in the trigger table, we use the scope mechanism. This is a little strange because @@ -518,8 +518,8 @@ func triggerEventsMatch(event plan.TriggerEvent, event2 string) bool { return strings.ToLower((string)(event)) == strings.ToLower(event2) } -// wrapWritesWithRollback wraps the entire tree iff it contains a trigger, allowing rollback when a trigger errors -func wrapWritesWithRollback(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { +// wrapWithRollback wraps the entire tree iff it contains a trigger, allowing rollback when a trigger errors +func wrapWithRollback(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { // Check if tree contains a TriggerExecutor containsTrigger := false transform.Inspect(n, func(n sql.Node) bool { diff --git a/sql/analyzer/validation_rules.go b/sql/analyzer/validation_rules.go index 54cf51637d..224cf6c89d 100644 --- a/sql/analyzer/validation_rules.go +++ b/sql/analyzer/validation_rules.go @@ -95,7 +95,7 @@ func validateOffsetAndLimit(ctx *sql.Context, a *Analyzer, n sql.Node, scope *pl return n, transform.SameTree, err } -func validateIsResolved(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { +func validateResolved(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { span, ctx := ctx.Span("validate_is_resolved") defer span.End()