MCPcopy Create free account
hub / github.com/bytebase/bytebase / classifyQueryType

Function classifyQueryType

backend/plugin/parser/tsql/query_type.go:13–84  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

11// classifyQueryType classifies an omni AST node into a QueryType.
12// allSystems indicates whether all referenced tables are system/info_schema tables.
13func classifyQueryType(node ast.Node, allSystems bool) base.QueryType {
14 if node == nil {
15 return base.QueryTypeUnknown
16 }
17
18 switch n := node.(type) {
19 case *ast.SelectStmt:
20 // SELECT ... INTO new_table creates a table — it is a write (DDL), not a read.
21 // Without this the write would take the SELECT path and execute under read access.
22 // INTO may sit on the first arm of a set operation, not the root. An INTO #temp
23 // (or ##temp) target stays a read: it materialises a session-scoped tempdb table
24 // that the extractor registers in TempTables for follow-up statements.
25 if target := selectIntoTarget(n); target != nil && !strings.HasPrefix(target.Object, "#") {
26 return base.DDL
27 }
28 if allSystems {
29 return base.SelectInfoSchema
30 }
31 return base.Select
32
33 // Safe read-only statements treated as Select (parity with the pre-omni
34 // Another_statement → SET/SETUSER/DECLARE branch).
35 case *ast.SetStmt, *ast.SetOptionStmt, *ast.DeclareStmt:
36 return base.Select
37
38 // DML statements.
39 case *ast.InsertStmt, *ast.UpdateStmt, *ast.DeleteStmt, *ast.MergeStmt,
40 *ast.BulkInsertStmt, *ast.InsertBulkStmt, *ast.CopyIntoStmt,
41 *ast.ReadtextStmt, *ast.WritetextStmt, *ast.UpdatetextStmt,
42 *ast.ExecStmt, *ast.ReceiveStmt, *ast.PredictStmt:
43 return base.DML
44
45 // DDL statements.
46 case *ast.CreateTableStmt, *ast.AlterTableStmt, *ast.DropStmt,
47 *ast.TruncateStmt, *ast.RenameStmt,
48 *ast.CreateIndexStmt, *ast.AlterIndexStmt,
49 *ast.CreateViewStmt,
50 *ast.CreateTriggerStmt, *ast.EnableDisableTriggerStmt,
51 *ast.CreateFunctionStmt, *ast.CreateProcedureStmt,
52 *ast.CreateDatabaseStmt, *ast.AlterDatabaseStmt,
53 *ast.CreateSchemaStmt, *ast.AlterSchemaStmt,
54 *ast.CreateTypeStmt,
55 *ast.CreateSequenceStmt, *ast.AlterSequenceStmt,
56 *ast.CreateSynonymStmt,
57 *ast.GrantStmt, *ast.SecurityStmt, *ast.SecurityKeyStmt, *ast.SecurityPolicyStmt,
58 *ast.SensitivityClassificationStmt, *ast.SignatureStmt,
59 *ast.CreateStatisticsStmt, *ast.UpdateStatisticsStmt, *ast.DropStatisticsStmt,
60 *ast.CreatePartitionFunctionStmt, *ast.AlterPartitionFunctionStmt,
61 *ast.CreatePartitionSchemeStmt, *ast.AlterPartitionSchemeStmt,
62 *ast.CreateFulltextIndexStmt, *ast.AlterFulltextIndexStmt,
63 *ast.CreateFulltextCatalogStmt, *ast.AlterFulltextCatalogStmt,
64 *ast.CreateFulltextStoplistStmt, *ast.AlterFulltextStoplistStmt, *ast.DropFulltextStoplistStmt,
65 *ast.CreateSearchPropertyListStmt, *ast.AlterSearchPropertyListStmt, *ast.DropSearchPropertyListStmt,
66 *ast.CreateXmlSchemaCollectionStmt, *ast.AlterXmlSchemaCollectionStmt,
67 *ast.CreateXmlIndexStmt, *ast.CreateSelectiveXmlIndexStmt,
68 *ast.CreateSpatialIndexStmt, *ast.CreateJsonIndexStmt, *ast.CreateVectorIndexStmt,
69 *ast.CreateAggregateStmt, *ast.DropAggregateStmt,
70 *ast.CreateAssemblyStmt, *ast.AlterAssemblyStmt,

Callers 2

getOmniQuerySpanMethod · 0.70

Calls 1

selectIntoTargetFunction · 0.85

Tested by 1