From 96fa7e63db30180486d9ec3370ac115070383721 Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 29 Oct 2024 12:25:22 -0700 Subject: [PATCH 1/2] remove resolveDescribeQuery rule --- sql/analyzer/analyzer.go | 11 ++++++++--- sql/analyzer/describe.go | 36 ------------------------------------ sql/analyzer/rule_ids.go | 1 - sql/analyzer/rules.go | 1 - 4 files changed, 8 insertions(+), 41 deletions(-) delete mode 100644 sql/analyzer/describe.go diff --git a/sql/analyzer/analyzer.go b/sql/analyzer/analyzer.go index 79dc70f382..6cf28e49b9 100644 --- a/sql/analyzer/analyzer.go +++ b/sql/analyzer/analyzer.go @@ -463,9 +463,14 @@ func newInsertSourceSelector(sel RuleSelector) RuleSelector { // Analyze applies the transformation rules to the node given. In the case of an error, the last successfully // transformed node is returned along with the error. -func (a *Analyzer) Analyze(ctx *sql.Context, n sql.Node, scope *plan.Scope, qFlags *sql.QueryFlags) (sql.Node, error) { - n, _, err := a.analyzeWithSelector(ctx, n, scope, SelectAllBatches, DefaultRuleSelector, qFlags) - return n, err +func (a *Analyzer) Analyze(ctx *sql.Context, node sql.Node, scope *plan.Scope, qFlags *sql.QueryFlags) (sql.Node, error) { + switch n := node.(type) { + case *plan.DescribeQuery: + child, _, err := a.analyzeWithSelector(ctx, n.Query(), scope, SelectAllBatches, DefaultRuleSelector, qFlags) + return n.WithQuery(child), err + } + node, _, err := a.analyzeWithSelector(ctx, node, scope, SelectAllBatches, DefaultRuleSelector, qFlags) + return node, err } func (a *Analyzer) analyzeThroughBatch(ctx *sql.Context, n sql.Node, scope *plan.Scope, until string, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { diff --git a/sql/analyzer/describe.go b/sql/analyzer/describe.go deleted file mode 100644 index 1e85ff84db..0000000000 --- a/sql/analyzer/describe.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2020-2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package analyzer - -import ( - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/plan" - "github.com/dolthub/go-mysql-server/sql/transform" -) - -// resolveDescribeQuery resolves any DescribeQuery nodes by analyzing their child and assigning it back. -func resolveDescribeQuery(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) { - d, ok := n.(*plan.DescribeQuery) - if !ok { - return n, transform.SameTree, nil - } - - q, _, err := a.analyzeWithSelector(ctx, d.Query(), scope, SelectAllBatches, sel, qFlags) - if err != nil { - return nil, transform.SameTree, err - } - - return d.WithQuery(q), transform.NewTree, nil -} diff --git a/sql/analyzer/rule_ids.go b/sql/analyzer/rule_ids.go index fd6e183945..9067489e1b 100644 --- a/sql/analyzer/rule_ids.go +++ b/sql/analyzer/rule_ids.go @@ -19,7 +19,6 @@ const ( resolveCreateSelectId // resolveCreateSelect resolveSubqueriesId // resolveSubqueries resolveUnionsId // resolveUnions - resolveDescribeQueryId // resolveDescribeQuery ValidateColumnDefaultsId // validateColumnDefaults validateCreateTriggerId // validateCreateTrigger validateCreateProcedureId // validateCreateProcedure diff --git a/sql/analyzer/rules.go b/sql/analyzer/rules.go index 26438d7487..6a5ae05626 100644 --- a/sql/analyzer/rules.go +++ b/sql/analyzer/rules.go @@ -46,7 +46,6 @@ var OnceBeforeDefault = []Rule{ {resolveCreateSelectId, resolveCreateSelect}, {validateDropConstraintId, validateDropConstraint}, {resolveUnionsId, resolveUnions}, - {resolveDescribeQueryId, resolveDescribeQuery}, //TODO {validateCreateTriggerId, validateCreateTrigger}, {ValidateColumnDefaultsId, validateColumnDefaults}, {validateReadOnlyDatabaseId, validateReadOnlyDatabase}, From 8b2ba0a9271a8ec8255a3c47f318d87312852557 Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 29 Oct 2024 12:36:37 -0700 Subject: [PATCH 2/2] ruleids --- sql/analyzer/ruleid_string.go | 123 +++++++++++++++++----------------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/sql/analyzer/ruleid_string.go b/sql/analyzer/ruleid_string.go index 8b2855696f..ca205402ba 100755 --- a/sql/analyzer/ruleid_string.go +++ b/sql/analyzer/ruleid_string.go @@ -21,71 +21,70 @@ func _() { _ = 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[applyForeignKeysId-58] - _ = x[validateResolvedId-59] - _ = x[validateOrderById-60] - _ = x[validateGroupById-61] - _ = x[validateSchemaSourceId-62] - _ = x[validateIndexCreationId-63] - _ = x[ValidateOperandsId-64] - _ = x[validateIntervalUsageId-65] - _ = x[validateSubqueryColumnsId-66] - _ = x[validateUnionSchemasMatchId-67] - _ = x[validateAggregationsId-68] - _ = x[validateDeleteFromId-69] - _ = x[cacheSubqueryAliasesInJoinsId-70] - _ = x[BacktickDefaulColumnValueNamesId-71] - _ = x[TrackProcessId-72] + _ = x[ValidateColumnDefaultsId-13] + _ = x[validateCreateTriggerId-14] + _ = x[validateCreateProcedureId-15] + _ = x[validateReadOnlyDatabaseId-16] + _ = x[validateReadOnlyTransactionId-17] + _ = x[validateDatabaseSetId-18] + _ = x[validatePrivilegesId-19] + _ = x[applyEventSchedulerId-20] + _ = x[flattenTableAliasesId-21] + _ = x[pushdownSubqueryAliasFiltersId-22] + _ = x[validateCheckConstraintId-23] + _ = x[replaceCountStarId-24] + _ = x[replaceCrossJoinsId-25] + _ = x[moveJoinCondsToFilterId-26] + _ = x[simplifyFiltersId-27] + _ = x[pushNotFiltersId-28] + _ = x[hoistOutOfScopeFiltersId-29] + _ = x[unnestInSubqueriesId-30] + _ = x[unnestExistsSubqueriesId-31] + _ = x[finalizeSubqueriesId-32] + _ = x[finalizeUnionsId-33] + _ = x[loadTriggersId-34] + _ = x[processTruncateId-35] + _ = x[resolveAlterColumnId-36] + _ = x[stripTableNameInDefaultsId-37] + _ = x[optimizeJoinsId-38] + _ = x[pushFiltersId-39] + _ = x[applyIndexesFromOuterScopeId-40] + _ = x[pruneTablesId-41] + _ = x[assignExecIndexesId-42] + _ = x[inlineSubqueryAliasRefsId-43] + _ = x[eraseProjectionId-44] + _ = x[flattenDistinctId-45] + _ = x[replaceAggId-46] + _ = x[replaceIdxSortId-47] + _ = x[insertTopNId-48] + _ = x[replaceIdxOrderByDistanceId-49] + _ = x[applyHashInId-50] + _ = x[resolveInsertRowsId-51] + _ = x[applyTriggersId-52] + _ = x[applyProceduresId-53] + _ = x[assignRoutinesId-54] + _ = x[modifyUpdateExprsForJoinId-55] + _ = x[applyUpdateAccumulatorsId-56] + _ = x[applyForeignKeysId-57] + _ = x[validateResolvedId-58] + _ = x[validateOrderById-59] + _ = x[validateGroupById-60] + _ = x[validateSchemaSourceId-61] + _ = x[validateIndexCreationId-62] + _ = x[ValidateOperandsId-63] + _ = x[validateIntervalUsageId-64] + _ = x[validateSubqueryColumnsId-65] + _ = x[validateUnionSchemasMatchId-66] + _ = x[validateAggregationsId-67] + _ = x[validateDeleteFromId-68] + _ = x[cacheSubqueryAliasesInJoinsId-69] + _ = x[BacktickDefaulColumnValueNamesId-70] + _ = x[TrackProcessId-71] } -const _RuleId_name = "applyDefaultSelectLimitvalidateOffsetAndLimitvalidateStarExpressionsvalidateCreateTablevalidateAlterTablevalidateExprSemloadStoredProceduresvalidateDropTablesresolveDropConstraintvalidateDropConstraintresolveCreateSelectresolveSubqueriesresolveUnionsresolveDescribeQueryvalidateColumnDefaultsvalidateCreateTriggervalidateCreateProcedurevalidateReadOnlyDatabasevalidateReadOnlyTransactionvalidateDatabaseSetvalidatePrivilegesapplyEventSchedulerflattenTableAliasespushdownSubqueryAliasFiltersvalidateCheckConstraintsreplaceCountStarreplaceCrossJoinsmoveJoinConditionsToFiltersimplifyFilterspushNotFiltershoistOutOfScopeFiltersunnestInSubqueriesunnestExistsSubqueriesfinalizeSubqueriesfinalizeUnionsloadTriggersprocessTruncateresolveAlterColumnstripTableNamesFromColumnDefaultsoptimizeJoinspushFiltersapplyIndexesFromOuterScopepruneTablesassignExecIndexesinlineSubqueryAliasRefseraseProjectionflattenDistinctreplaceAggreplaceIdxSortinsertTopNNodesreplaceIdxOrderByDistanceapplyHashInresolveInsertRowsapplyTriggersapplyProceduresassignRoutinesmodifyUpdateExprsForJoinapplyUpdateAccumulatorsapplyForeignKeysvalidateResolvedvalidateOrderByvalidateGroupByvalidateSchemaSourcevalidateIndexCreationvalidateOperandsvalidateIntervalUsagevalidateSubqueryColumnsvalidateUnionSchemasMatchvalidateAggregationsvalidateDeleteFromcacheSubqueryAliasesInJoinsbacktickDefaultColumnValueNamestrackProcess" +const _RuleId_name = "applyDefaultSelectLimitvalidateOffsetAndLimitvalidateStarExpressionsvalidateCreateTablevalidateAlterTablevalidateExprSemloadStoredProceduresvalidateDropTablesresolveDropConstraintvalidateDropConstraintresolveCreateSelectresolveSubqueriesresolveUnionsvalidateColumnDefaultsvalidateCreateTriggervalidateCreateProcedurevalidateReadOnlyDatabasevalidateReadOnlyTransactionvalidateDatabaseSetvalidatePrivilegesapplyEventSchedulerflattenTableAliasespushdownSubqueryAliasFiltersvalidateCheckConstraintsreplaceCountStarreplaceCrossJoinsmoveJoinConditionsToFiltersimplifyFilterspushNotFiltershoistOutOfScopeFiltersunnestInSubqueriesunnestExistsSubqueriesfinalizeSubqueriesfinalizeUnionsloadTriggersprocessTruncateresolveAlterColumnstripTableNamesFromColumnDefaultsoptimizeJoinspushFiltersapplyIndexesFromOuterScopepruneTablesassignExecIndexesinlineSubqueryAliasRefseraseProjectionflattenDistinctreplaceAggreplaceIdxSortinsertTopNNodesreplaceIdxOrderByDistanceapplyHashInresolveInsertRowsapplyTriggersapplyProceduresassignRoutinesmodifyUpdateExprsForJoinapplyUpdateAccumulatorsapplyForeignKeysvalidateResolvedvalidateOrderByvalidateGroupByvalidateSchemaSourcevalidateIndexCreationvalidateOperandsvalidateIntervalUsagevalidateSubqueryColumnsvalidateUnionSchemasMatchvalidateAggregationsvalidateDeleteFromcacheSubqueryAliasesInJoinsbacktickDefaultColumnValueNamestrackProcess" -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, 1133, 1148, 1168, 1189, 1205, 1226, 1249, 1274, 1294, 1312, 1339, 1370, 1382} +var _RuleId_index = [...]uint16{0, 23, 45, 68, 87, 105, 120, 140, 158, 179, 201, 220, 237, 250, 272, 293, 316, 340, 367, 386, 404, 423, 442, 470, 494, 510, 527, 553, 568, 582, 604, 622, 644, 662, 676, 688, 703, 721, 754, 767, 778, 804, 815, 832, 855, 870, 885, 895, 909, 924, 949, 960, 977, 990, 1005, 1019, 1043, 1066, 1082, 1098, 1113, 1128, 1148, 1169, 1185, 1206, 1229, 1254, 1274, 1292, 1319, 1350, 1362} func (i RuleId) String() string { if i < 0 || i >= RuleId(len(_RuleId_index)-1) {