This repository was archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathassign_catalog.go
75 lines (71 loc) · 1.71 KB
/
assign_catalog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package analyzer
import (
"github.com/src-d/go-mysql-server/sql"
"github.com/src-d/go-mysql-server/sql/plan"
)
// assignCatalog sets the catalog in the required nodes.
func assignCatalog(ctx *sql.Context, a *Analyzer, n sql.Node) (sql.Node, error) {
span, _ := ctx.Span("assign_catalog")
defer span.Finish()
return plan.TransformUp(n, func(n sql.Node) (sql.Node, error) {
if !n.Resolved() {
return n, nil
}
switch node := n.(type) {
case *plan.CreateIndex:
nc := *node
nc.Catalog = a.Catalog
nc.CurrentDatabase = a.Catalog.CurrentDatabase()
return &nc, nil
case *plan.DropIndex:
nc := *node
nc.Catalog = a.Catalog
nc.CurrentDatabase = a.Catalog.CurrentDatabase()
return &nc, nil
case *plan.ShowIndexes:
nc := *node
nc.Registry = a.Catalog.IndexRegistry
return &nc, nil
case *plan.ShowDatabases:
nc := *node
nc.Catalog = a.Catalog
return &nc, nil
case *plan.ShowCreateTable:
nc := *node
nc.Catalog = a.Catalog
nc.CurrentDatabase = a.Catalog.CurrentDatabase()
return &nc, nil
case *plan.ShowProcessList:
nc := *node
nc.Database = a.Catalog.CurrentDatabase()
nc.ProcessList = a.Catalog.ProcessList
return &nc, nil
case *plan.ShowTableStatus:
nc := *node
nc.Catalog = a.Catalog
return &nc, nil
case *plan.Use:
nc := *node
nc.Catalog = a.Catalog
return &nc, nil
case *plan.LockTables:
nc := *node
nc.Catalog = a.Catalog
return &nc, nil
case *plan.UnlockTables:
nc := *node
nc.Catalog = a.Catalog
return &nc, nil
case *plan.CreateView:
nc := *node
nc.Catalog = a.Catalog
return &nc, nil
case *plan.DropView:
nc := *node
nc.Catalog = a.Catalog
return &nc, nil
default:
return n, nil
}
})
}