classifyQueryType classifies an omni AST node into a QueryType. allSystems indicates whether all referenced tables are system/info_schema tables.
(node ast.Node, allSystems bool)
| 11 | // classifyQueryType classifies an omni AST node into a QueryType. |
| 12 | // allSystems indicates whether all referenced tables are system/info_schema tables. |
| 13 | func classifyQueryType(node ast.Node, allSystems bool) (queryType base.QueryType, isExplainAnalyze bool) { |
| 14 | if node == nil { |
| 15 | return base.QueryTypeUnknown, false |
| 16 | } |
| 17 | |
| 18 | switch n := node.(type) { |
| 19 | // DML statements |
| 20 | case *ast.InsertStmt, *ast.UpdateStmt, *ast.DeleteStmt, *ast.MergeStmt, *ast.CopyStmt: |
| 21 | return base.DML, false |
| 22 | |
| 23 | // SELECT: check for INTO clause (becomes DDL) |
| 24 | case *ast.SelectStmt: |
| 25 | if hasOmniIntoClause(n) { |
| 26 | return base.DDL, false |
| 27 | } |
| 28 | if allSystems { |
| 29 | return base.SelectInfoSchema, false |
| 30 | } |
| 31 | return base.Select, false |
| 32 | |
| 33 | // SET is treated as safe (Select) |
| 34 | case *ast.VariableSetStmt: |
| 35 | return base.Select, false |
| 36 | |
| 37 | // SHOW → info schema |
| 38 | case *ast.VariableShowStmt: |
| 39 | return base.SelectInfoSchema, false |
| 40 | |
| 41 | // EXPLAIN: check for ANALYZE option |
| 42 | case *ast.ExplainStmt: |
| 43 | if isExplainAnalyzeOmni(n) { |
| 44 | qt := classifyExplainedQuery(n.Query) |
| 45 | return qt, true |
| 46 | } |
| 47 | return base.Explain, false |
| 48 | |
| 49 | // REFRESH MATERIALIZED VIEW is DML |
| 50 | case *ast.RefreshMatViewStmt: |
| 51 | return base.DML, false |
| 52 | |
| 53 | // CALL stored procedure is DML |
| 54 | case *ast.CallStmt: |
| 55 | return base.DML, false |
| 56 | |
| 57 | // All DDL statements |
| 58 | case *ast.CreateStmt, *ast.DropStmt, *ast.AlterTableStmt, |
| 59 | *ast.CreateTableAsStmt, *ast.CreateSeqStmt, *ast.CreateSchemaStmt, |
| 60 | *ast.CreatedbStmt, *ast.CreateFunctionStmt, *ast.CreateRoleStmt, |
| 61 | *ast.IndexStmt, *ast.CreateExtensionStmt, *ast.CreateTrigStmt, |
| 62 | *ast.CreateEventTrigStmt, *ast.CreateDomainStmt, *ast.CreateConversionStmt, |
| 63 | *ast.CreateCastStmt, *ast.CreateOpClassStmt, *ast.CreateOpFamilyStmt, |
| 64 | *ast.CreatePolicyStmt, *ast.CreateAmStmt, *ast.CreateTransformStmt, |
| 65 | *ast.CreateStatsStmt, *ast.CreateTableSpaceStmt, |
| 66 | *ast.CreateFdwStmt, *ast.CreateForeignServerStmt, |
| 67 | *ast.CreateForeignTableStmt, *ast.CreatePLangStmt, |
| 68 | *ast.CreatePublicationStmt, *ast.CreateSubscriptionStmt, |
| 69 | *ast.CreateUserMappingStmt, |
| 70 | *ast.ViewStmt, |
no test coverage detected