From 0f1c40e1f022d23c5e464fd35af91f5b0ff73523 Mon Sep 17 00:00:00 2001 From: BugsGuru Date: Fri, 1 Nov 2024 11:14:57 +0800 Subject: [PATCH] disable optimization when ce --- sqle/server/optimization/rule/rule.go | 99 +-- sqle/server/optimization/rule/rule_ce.go | 4 +- sqle/server/optimization/rule/rule_list.go | 645 ------------------ .../optimization/rule/rule_list_trial.go | 7 - sqle/server/support_checker.go | 5 +- sqle/sqled.go | 5 + 6 files changed, 11 insertions(+), 754 deletions(-) delete mode 100644 sqle/server/optimization/rule/rule_list.go delete mode 100644 sqle/server/optimization/rule/rule_list_trial.go diff --git a/sqle/server/optimization/rule/rule.go b/sqle/server/optimization/rule/rule.go index f1c662a896..b8729d0a7f 100644 --- a/sqle/server/optimization/rule/rule.go +++ b/sqle/server/optimization/rule/rule.go @@ -1,111 +1,18 @@ package optimization import ( - "github.com/actiontech/dms/pkg/dms-common/i18nPkg" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" - "github.com/actiontech/sqle/sqle/log" ) -var OptimizationRuleMap map[string][]OptimizationRuleHandler // ruleCode与plugin重写规则的映射关系 - -// DML规则 -const ( - DMLRuleNPERewrite = "dml_rule_npe_rewrite" - DMLRuleAllSubqueryRewrite = "dml_rule_all_subquery_rewrite" - DMLRuleDiffOrderingSpecTypeWarning = "dml_rule_diff_ordering_spec_type_warning" - DMLRuleDistinctEliminationRewrite = "dml_rule_distinct_elimination_rewrite" - DMLRuleExists2JoinRewrite = "dml_rule_exists_2_join_rewrite" - DMLRuleFilterPredicatePushDownRewrite = "dml_rule_filter_predicate_push_down_rewrite" - DMLRuleGroupingFromDiffTablesRewrite = "dml_rule_grouping_from_diff_tables_rewrite" - DMLRuleJoinEliminationRewrite = "dml_rule_join_elimination_rewrite" - DMLRuleLimitClausePushDownRewrite = "dml_rule_limit_clause_push_down_rewrite" - DMLRuleMaxMinAggRewrite = "dml_rule_max_min_agg_rewrite" - DMLRuleMoveOrder2LeadingRewrite = "dml_rule_move_order_2_leading_rewrite" - DMLRuleOrCond4SelectRewrite = "dml_rule_or_cond_4_select_rewrite" - DMLRuleOrCond4UpDeleteRewrite = "dml_rule_or_cond_4_up_delete_rewrite" - DMLRuleOrderEliminationInSubqueryRewrite = "dml_rule_order_elimination_in_subquery_rewrite" - DMLRuleOrderingFromDiffTablesRewrite = "dml_rule_ordering_from_diff_tables_rewrite" - DMLRuleOuter2InnerConversionRewrite = "dml_rule_outer_2_inner_conversion_rewrite" - DMLRuleProjectionPushdownRewrite = "dml_rule_projection_pushdown_rewrite" - DMLRuleQualifierSubQueryRewrite = "dml_rule_qualifier_sub_query_rewrite" - DMLRuleQueryFoldingRewrite = "dml_rule_query_folding_rewrite" - DMLRuleSATTCRewrite = "dml_rule_sattc_rewrite" -) - -// SQL优化规则的ruleCode -const ( - RuleAddOrderByNullRewrite = "RuleAddOrderByNullRewrite" - RuleAllQualifierSubQueryRewrite = "RuleAllQualifierSubQueryRewrite" - RuleCntGtThanZeroRewrite = "RuleCntGtThanZeroRewrite" - RuleDelete2TruncateRewrite = "RuleDelete2TruncateRewrite" - RuleDiffDataTypeInPredicateWrite = "RuleDiffDataTypeInPredicateWrite" - RuleDiffOrderingSpecTypeWarning = "RuleDiffOrderingSpecTypeWarning" - RuleFuncWithColumnInPredicate = "RuleFuncWithColumnInPredicate" - RuleHavingCond2WhereCondRewrite = "RuleHavingCond2WhereCondRewrite" - RuleUseEqual4NullRewrite = "RuleUseEqual4NullRewrite" - RuleInSubqueryRewrite = "RuleInSubqueryRewrite" - RuleNotInNullableSubQueryRewrite = "RuleNotInNullableSubQueryRewrite" - RuleNoWildcardInPredicateLikeWarning = "RuleNoWildcardInPredicateLikeWarning" - RuleNPERewrite = "RuleNPERewrite" - RuleUseNonstandardNotEqualOperator = "RuleUseNonstandardNotEqualOperator" - RuleLargeOffset = "RuleLargeOffset" - RuleDistinctEliminationRewrite = "RuleDistinctEliminationRewrite" - RuleExists2JoinRewrite = "RuleExists2JoinRewrite" - RuleFilterPredicatePushDownRewrite = "RuleFilterPredicatePushDownRewrite" - RuleGroupingFromDiffTablesRewrite = "RuleGroupingFromDiffTablesRewrite" - RuleJoinEliminationRewrite = "RuleJoinEliminationRewrite" - RuleLimitClausePushDownRewrite = "RuleLimitClausePushDownRewrite" - RuleMaxMinAggRewrite = "RuleMaxMinAggRewrite" - RuleMoveOrder2LeadingRewrite = "RuleMoveOrder2LeadingRewrite" - RuleOrCond4SelectRewrite = "RuleOrCond4SelectRewrite" - RuleOrCond4UpDeleteRewrite = "RuleOrCond4UpDeleteRewrite" - RuleOrderEliminationInSubqueryRewrite = "RuleOrderEliminationInSubqueryRewrite" - RuleOrderingFromDiffTablesRewrite = "RuleOrderingFromDiffTablesRewrite" - RuleOuter2InnerConversionRewrite = "RuleOuter2InnerConversionRewrite" - RuleProjectionPushdownRewrite = "RuleProjectionPushdownRewrite" - RuleQualifierSubQueryRewrite = "RuleQualifierSubQueryRewrite" - RuleQueryFoldingRewrite = "RuleQueryFoldingRewrite" - RuleSATTCRewrite = "RuleSATTCRewrite" -) +var OptimizationRuleMap = map[string][]OptimizationRuleHandler{} // ruleCode与plugin重写规则的映射关系 type OptimizationRuleHandler struct { Rule driverV2.Rule RuleCode string // SQL优化规则的ruleCode } -func init() { - OptimizationRuleMap = make(map[string][]OptimizationRuleHandler) - OptimizationRuleMap["MySQL"] = MySQLOptimizationRuleHandler - OptimizationRuleMap["Oracle"] = OracleOptimizationRuleHandler - - // SQL优化规则知识库 - defaultRulesKnowledge, err := getDefaultRulesKnowledge() - if err != nil { - log.NewEntry().Errorf("get default rules knowledge failed: %v", err) - return - } - for _, optimizationRule := range OptimizationRuleMap { - for i, rule := range optimizationRule { - if knowledge, ok := defaultRulesKnowledge[rule.RuleCode]; ok { - // todo i18n rewrite rule Knowledge - rule.Rule.I18nRuleInfo[i18nPkg.DefaultLang].Knowledge = driverV2.RuleKnowledge{Content: knowledge} - optimizationRule[i] = rule - } - } - } -} - -// GetOptimizationRuleByRuleCode 通过pawsql的ruleCode和dbType获取重写规则 -func GetOptimizationRuleByRuleCode(ruleCode string, dbType string) (*driverV2.Rule, bool) { - rules := OptimizationRuleMap[dbType] - if len(rules) > 0 { - for _, rule := range rules { - if rule.RuleCode == ruleCode { - return &rule.Rule, true - } - } - } - return nil, false +func InitOptimizationRule() { + initOptimizationRule() } // CanOptimizeDbType SQL优化是否支持该数据源类型 diff --git a/sqle/server/optimization/rule/rule_ce.go b/sqle/server/optimization/rule/rule_ce.go index 7780123719..dee46dad2c 100644 --- a/sqle/server/optimization/rule/rule_ce.go +++ b/sqle/server/optimization/rule/rule_ce.go @@ -3,6 +3,4 @@ package optimization -func getDefaultRulesKnowledge() (map[string]string, error) { - return nil, nil -} +func initOptimizationRule() {} diff --git a/sqle/server/optimization/rule/rule_list.go b/sqle/server/optimization/rule/rule_list.go deleted file mode 100644 index 86184b5668..0000000000 --- a/sqle/server/optimization/rule/rule_list.go +++ /dev/null @@ -1,645 +0,0 @@ -//go:build !trial -// +build !trial - -package optimization - -import ( - "github.com/actiontech/sqle/sqle/driver/mysql/plocale" - rulepkg "github.com/actiontech/sqle/sqle/driver/mysql/rule" - driverV2 "github.com/actiontech/sqle/sqle/driver/v2" - "github.com/actiontech/sqle/sqle/pkg/params" -) - -type SourceOptimizationRuleHandler struct { - Rule rulepkg.SourceRule - RuleCode string -} - -var MySQLOptimizationRuleHandler = generateOptimizationRuleHandlers(mySQLOptimizationRuleHandlerSource) - -var OracleOptimizationRuleHandler = generateOptimizationRuleHandlers(oracleOptimizationRuleHandlerSource) - -func generateOptimizationRuleHandlers(sources []SourceOptimizationRuleHandler) []OptimizationRuleHandler { - result := make([]OptimizationRuleHandler, len(sources)) - for k, v := range sources { - result[k] = OptimizationRuleHandler{ - Rule: *rulepkg.ConvertSourceRule(&v.Rule), - RuleCode: v.RuleCode, - } - } - return result -} - -var mySQLOptimizationRuleHandlerSource = []SourceOptimizationRuleHandler{ - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLHintGroupByRequiresConditions, - Desc: plocale.OptDMLHintGroupByRequiresConditionsDesc, - Annotation: plocale.OptDMLHintGroupByRequiresConditionsAnnotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleAddOrderByNullRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLCheckWhereExistScalarSubquery, - Desc: plocale.OptDMLCheckWhereExistScalarSubqueryDesc, - Annotation: plocale.OptDMLCheckWhereExistScalarSubqueryAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleCntGtThanZeroRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLHintUseTruncateInsteadOfDelete, - Desc: plocale.OptDMLHintUseTruncateInsteadOfDeleteDesc, - Annotation: plocale.OptDMLHintUseTruncateInsteadOfDeleteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleDelete2TruncateRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLCheckWhereExistImplicitConversion, - Desc: plocale.OptDMLCheckWhereExistImplicitConversionDesc, - Annotation: plocale.OptDMLCheckWhereExistImplicitConversionAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleDiffDataTypeInPredicateWrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLCheckMathComputationOrFuncOnIndex, - Desc: plocale.OptDMLCheckMathComputationOrFuncOnIndexDesc, - Annotation: plocale.OptDMLCheckMathComputationOrFuncOnIndexAnnotation, - Level: driverV2.RuleLevelError, - Category: plocale.RuleTypeIndexInvalidation, - }, - RuleCode: RuleFuncWithColumnInPredicate, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLNotRecommendHaving, - Desc: plocale.OptDMLNotRecommendHavingDesc, - Annotation: plocale.OptDMLNotRecommendHavingAnnotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleHavingCond2WhereCondRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLWhereExistNull, - Desc: plocale.OptDMLWhereExistNullDesc, - Annotation: plocale.OptDMLWhereExistNullAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleUseEqual4NullRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLNotRecommendIn, - Desc: plocale.OptDMLNotRecommendInDesc, - Annotation: plocale.OptDMLNotRecommendInAnnotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleInSubqueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLHintInNullOnlyFalse, - Desc: plocale.OptDMLHintInNullOnlyFalseDesc, - Annotation: plocale.OptDMLHintInNullOnlyFalseAnnotation, - Level: driverV2.RuleLevelError, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleNotInNullableSubQueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLNotRecommendNotWildcardLike, - Desc: plocale.OptDMLNotRecommendNotWildcardLikeDesc, - Annotation: plocale.OptDMLNotRecommendNotWildcardLikeAnnotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleNoWildcardInPredicateLikeWarning, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLCheckNotEqualSymbol, - Desc: plocale.OptDMLCheckNotEqualSymbolDesc, - Annotation: plocale.OptDMLCheckNotEqualSymbolAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleUseNonstandardNotEqualOperator, - }, - { - Rule: rulepkg.SourceRule{ - Name: rulepkg.DMLCheckLimitOffsetNum, - Desc: plocale.OptDMLCheckLimitOffsetNumDesc, - Annotation: plocale.OptDMLCheckLimitOffsetNumAnnotation, - Level: driverV2.RuleLevelError, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleLargeOffset, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleNPERewrite, - Desc: plocale.OptDMLRuleNPERewriteDesc, - Annotation: plocale.OptDMLRuleNPERewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleNPERewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleAllSubqueryRewrite, - Desc: plocale.OptDMLRuleAllSubqueryRewriteDesc, - Annotation: plocale.OptDMLRuleAllSubqueryRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleAllQualifierSubQueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleDiffOrderingSpecTypeWarning, - Desc: plocale.OptDMLRuleDiffOrderingSpecTypeWarningDesc, - Annotation: plocale.OptDMLRuleDiffOrderingSpecTypeWarningAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleDiffOrderingSpecTypeWarning, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleDistinctEliminationRewrite, - Desc: plocale.OptDMLRuleDistinctEliminationRewriteDesc, - Annotation: plocale.OptDMLRuleDistinctEliminationRewriteAnnotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleDistinctEliminationRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleExists2JoinRewrite, - Desc: plocale.OptDMLRuleExists2JoinRewriteDesc, - Annotation: plocale.OptDMLRuleExists2JoinRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleExists2JoinRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleFilterPredicatePushDownRewrite, - Desc: plocale.OptDMLRuleFilterPredicatePushDownRewriteDesc, - Annotation: plocale.OptDMLRuleFilterPredicatePushDownRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleFilterPredicatePushDownRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleGroupingFromDiffTablesRewrite, - Desc: plocale.OptDMLRuleGroupingFromDiffTablesRewriteDesc, - Annotation: plocale.OptDMLRuleGroupingFromDiffTablesRewriteAnnotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleGroupingFromDiffTablesRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleJoinEliminationRewrite, - Desc: plocale.OptDMLRuleJoinEliminationRewriteDesc, - Annotation: plocale.OptDMLRuleJoinEliminationRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleJoinEliminationRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleLimitClausePushDownRewrite, - Desc: plocale.OptDMLRuleLimitClausePushDownRewriteDesc, - Annotation: plocale.OptDMLRuleLimitClausePushDownRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - Params: []*rulepkg.SourceParam{ - { - Key: rulepkg.DefaultSingleParamKeyName, - Value: "1000", - Desc: plocale.OptDMLRuleLimitClausePushDownRewriteParams1, - Type: params.ParamTypeInt, - }, - }, - }, - RuleCode: RuleLimitClausePushDownRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleMaxMinAggRewrite, - Desc: plocale.OptDMLRuleMaxMinAggRewriteDesc, - Annotation: plocale.OptDMLRuleMaxMinAggRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleMaxMinAggRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleMoveOrder2LeadingRewrite, - Desc: plocale.OptDMLRuleMoveOrder2LeadingRewriteDesc, - Annotation: plocale.OptDMLRuleMoveOrder2LeadingRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleMoveOrder2LeadingRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleOrCond4SelectRewrite, - Desc: plocale.OptDMLRuleOrCond4SelectRewriteDesc, - Annotation: plocale.OptDMLRuleOrCond4SelectRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOrCond4SelectRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleOrCond4UpDeleteRewrite, - Desc: plocale.OptDMLRuleOrCond4UpDeleteRewriteDesc, - Annotation: plocale.OptDMLRuleOrCond4UpDeleteRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOrCond4UpDeleteRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleOrderEliminationInSubqueryRewrite, - Desc: plocale.OptDMLRuleOrderEliminationInSubqueryRewriteDesc, - Annotation: plocale.OptDMLRuleOrderEliminationInSubqueryRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOrderEliminationInSubqueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleOrderingFromDiffTablesRewrite, - Desc: plocale.OptDMLRuleOrderingFromDiffTablesRewriteDesc, - Annotation: plocale.OptDMLRuleOrderingFromDiffTablesRewriteAnnotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOrderingFromDiffTablesRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleOuter2InnerConversionRewrite, - Desc: plocale.OptDMLRuleOuter2InnerConversionRewriteDesc, - Annotation: plocale.OptDMLRuleOuter2InnerConversionRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOuter2InnerConversionRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleProjectionPushdownRewrite, - Desc: plocale.OptDMLRuleProjectionPushdownRewriteDesc, - Annotation: plocale.OptDMLRuleProjectionPushdownRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleProjectionPushdownRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleQualifierSubQueryRewrite, - Desc: plocale.OptDMLRuleQualifierSubQueryRewriteDesc, - Annotation: plocale.OptDMLRuleQualifierSubQueryRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleQualifierSubQueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleQueryFoldingRewrite, - Desc: plocale.OptDMLRuleQueryFoldingRewriteDesc, - Annotation: plocale.OptDMLRuleQueryFoldingRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleQueryFoldingRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: DMLRuleSATTCRewrite, - Desc: plocale.OptDMLRuleSATTCRewriteDesc, - Annotation: plocale.OptDMLRuleSATTCRewriteAnnotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleSATTCRewrite, - }, -} - -var oracleOptimizationRuleHandlerSource = []SourceOptimizationRuleHandler{ - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_500", - Desc: plocale.OptOracle500Desc, - Annotation: plocale.OptOracle500Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleNPERewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_501", - Desc: plocale.OptOracle501Desc, - Annotation: plocale.OptOracle501Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleAllQualifierSubQueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_502", - Desc: plocale.OptOracle502Desc, - Annotation: plocale.OptOracle502Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleCntGtThanZeroRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_503", - Desc: plocale.OptOracle503Desc, - Annotation: plocale.OptOracle503Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleDelete2TruncateRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_504", - Desc: plocale.OptOracle504Desc, - Annotation: plocale.OptOracle504Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleDiffDataTypeInPredicateWrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_505", - Desc: plocale.OptOracle505Desc, - Annotation: plocale.OptOracle505Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDDLConvention, - }, - RuleCode: RuleDiffOrderingSpecTypeWarning, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_506", - Desc: plocale.OptOracle506Desc, - Annotation: plocale.OptOracle506Annotation, - Level: driverV2.RuleLevelError, - Category: plocale.RuleTypeIndexInvalidation, - }, - RuleCode: RuleFuncWithColumnInPredicate, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_507", - Desc: plocale.OptOracle507Desc, - Annotation: plocale.OptOracle507Annotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleHavingCond2WhereCondRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_508", - Desc: plocale.OptOracle508Desc, - Annotation: plocale.OptOracle508Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleUseEqual4NullRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_509", - Desc: plocale.OptOracle509Desc, - Annotation: plocale.OptOracle509Annotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleInSubqueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_510", - Desc: plocale.OptOracle510Desc, - Annotation: plocale.OptOracle510Annotation, - Level: driverV2.RuleLevelError, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleNotInNullableSubQueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_511", - Desc: plocale.OptOracle511Desc, - Annotation: plocale.OptOracle511Annotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleNoWildcardInPredicateLikeWarning, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_512", - Desc: plocale.OptOracle512Desc, - Annotation: plocale.OptOracle512Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleUseNonstandardNotEqualOperator, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_513", - Desc: plocale.OptOracle513Desc, - Annotation: plocale.OptOracle513Annotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleDistinctEliminationRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_514", - Desc: plocale.OptOracle514Desc, - Annotation: plocale.OptOracle514Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleExists2JoinRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_515", - Desc: plocale.OptOracle515Desc, - Annotation: plocale.OptOracle515Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleFilterPredicatePushDownRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_516", - Desc: plocale.OptOracle516Desc, - Annotation: plocale.OptOracle516Annotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleGroupingFromDiffTablesRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_517", - Desc: plocale.OptOracle517Desc, - Annotation: plocale.OptOracle517Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleJoinEliminationRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_518", - Desc: plocale.OptOracle518Desc, - Annotation: plocale.OptOracle518Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleMaxMinAggRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_519", - Desc: plocale.OptOracle519Desc, - Annotation: plocale.OptOracle519Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleMoveOrder2LeadingRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_520", - Desc: plocale.OptOracle520Desc, - Annotation: plocale.OptOracle520Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOrCond4SelectRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_521", - Desc: plocale.OptOracle521Desc, - Annotation: plocale.OptOracle521Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOrCond4UpDeleteRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_522", - Desc: plocale.OptOracle522Desc, - Annotation: plocale.OptOracle522Annotation, - Level: driverV2.RuleLevelWarn, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOrderingFromDiffTablesRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_523", - Desc: plocale.OptOracle523Desc, - Annotation: plocale.OptOracle523Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleOuter2InnerConversionRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_524", - Desc: plocale.OptOracle524Desc, - Annotation: plocale.OptOracle524Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleProjectionPushdownRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_525", - Desc: plocale.OptOracle525Desc, - Annotation: plocale.OptOracle525Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleQualifierSubQueryRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_526", - Desc: plocale.OptOracle526Desc, - Annotation: plocale.OptOracle526Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleQueryFoldingRewrite, - }, - { - Rule: rulepkg.SourceRule{ - Name: "Oracle_527", - Desc: plocale.OptOracle527Desc, - Annotation: plocale.OptOracle527Annotation, - Level: driverV2.RuleLevelNotice, - Category: plocale.RuleTypeDMLConvention, - }, - RuleCode: RuleSATTCRewrite, - }, -} diff --git a/sqle/server/optimization/rule/rule_list_trial.go b/sqle/server/optimization/rule/rule_list_trial.go deleted file mode 100644 index 15b5bc3312..0000000000 --- a/sqle/server/optimization/rule/rule_list_trial.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build trial -// +build trial - -package optimization - -var MySQLOptimizationRuleHandler = make([]OptimizationRuleHandler, 0) -var OracleOptimizationRuleHandler = make([]OptimizationRuleHandler, 0) diff --git a/sqle/server/support_checker.go b/sqle/server/support_checker.go index 43043c6635..b9ee10ed18 100644 --- a/sqle/server/support_checker.go +++ b/sqle/server/support_checker.go @@ -3,9 +3,9 @@ package server import ( "fmt" - "github.com/actiontech/sqle/sqle/config" "github.com/actiontech/sqle/sqle/driver" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" + optimization "github.com/actiontech/sqle/sqle/server/optimization/rule" ) const ( @@ -39,6 +39,5 @@ func (checker executeSqlFileChecker) CheckIsSupport() bool { type sqlOptimizationChecker struct{} func (s sqlOptimizationChecker) CheckIsSupport() bool { - return config.GetOptions().SqleOptions.OptimizationConfig.OptimizationKey != "" && - config.GetOptions().SqleOptions.OptimizationConfig.OptimizationURL != "" + return len(optimization.OptimizationRuleMap) > 0 } diff --git a/sqle/sqled.go b/sqle/sqled.go index c78a11ec0c..465fbc5c56 100644 --- a/sqle/sqled.go +++ b/sqle/sqled.go @@ -11,6 +11,7 @@ import ( "github.com/actiontech/dms/pkg/dms-common/pkg/http" "github.com/actiontech/sqle/sqle/api" "github.com/actiontech/sqle/sqle/dms" + optimizationRule "github.com/actiontech/sqle/sqle/server/optimization/rule" // "github.com/actiontech/sqle/sqle/api/cloudbeaver_wrapper/service" "github.com/actiontech/sqle/sqle/config" @@ -90,6 +91,10 @@ func Run(options *config.SqleOptions) error { return fmt.Errorf("register to dms failed :%v", err) } + if options.OptimizationConfig.OptimizationKey != "" && options.OptimizationConfig.OptimizationURL != "" { + // 配置了pawsql才会去初始化重写规则 + optimizationRule.InitOptimizationRule() + } if sqleCnf.AutoMigrateTable { if err := s.AutoMigrate(); err != nil { return fmt.Errorf("auto migrate table failed: %v", err)