Skip to content

Commit f5b3d05

Browse files
author
James Cor
committed
removing now unused code
1 parent afe6195 commit f5b3d05

File tree

11 files changed

+60
-195
lines changed

11 files changed

+60
-195
lines changed

engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ func findCreateEventNode(planTree sql.Node) (*plan.CreateEvent, error) {
866866

867867
// finalizeIters applies the final transformations on sql.RowIter before execution.
868868
func finalizeIters(ctx *sql.Context, analyzed sql.Node, qFlags *sql.QueryFlags, iter sql.RowIter) sql.RowIter {
869+
iter = rowexec.AddTriggerRollbackIter(ctx, analyzed, iter)
869870
iter = rowexec.AddTransactionCommittingIter(qFlags, iter)
870871
iter = plan.AddTrackedRowIter(ctx, analyzed, iter)
871872
iter = rowexec.AddExpressionCloser(analyzed, iter)

sql/analyzer/rule_ids.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const (
6868
assignRoutinesId // assignRoutines
6969
modifyUpdateExprsForJoinId // modifyUpdateExprsForJoin
7070
applyUpdateAccumulatorsId // applyUpdateAccumulators
71-
wrapWithRollbackId // wrapWithRollback
7271
applyForeignKeysId // applyForeignKeys
7372

7473
// validate

sql/analyzer/ruleid_string.go

Lines changed: 17 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sql/analyzer/rules.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func init() {
2222
{applyTriggersId, applyTriggers},
2323
{applyProceduresId, applyProcedures},
2424
{applyUpdateAccumulatorsId, applyUpdateAccumulators},
25-
{wrapWithRollbackId, wrapWithRollback},
2625
{inlineSubqueryAliasRefsId, inlineSubqueryAliasRefs},
2726
{cacheSubqueryAliasesInJoinsId, cacheSubqueryAliasesInJoins},
2827
{BacktickDefaulColumnValueNamesId, backtickDefaultColumnValueNames},

sql/analyzer/triggers.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -517,41 +517,3 @@ func orderTriggersAndReverseAfter(triggers []*plan.CreateTrigger) []*plan.Create
517517
func triggerEventsMatch(event plan.TriggerEvent, event2 string) bool {
518518
return strings.ToLower((string)(event)) == strings.ToLower(event2)
519519
}
520-
521-
// wrapWithRollback wraps the entire tree iff it contains a trigger, allowing rollback when a trigger errors
522-
func wrapWithRollback(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
523-
// Check if tree contains a TriggerExecutor
524-
containsTrigger := false
525-
transform.Inspect(n, func(n sql.Node) bool {
526-
// After Triggers wrap nodes
527-
if _, ok := n.(*plan.TriggerExecutor); ok {
528-
containsTrigger = true
529-
return false // done, don't bother to recurse
530-
}
531-
532-
// Before Triggers on Inserts are inside Source
533-
if n, ok := n.(*plan.InsertInto); ok {
534-
if _, ok := n.Source.(*plan.TriggerExecutor); ok {
535-
containsTrigger = true
536-
return false
537-
}
538-
}
539-
540-
// Before Triggers on Delete and Update should be in children
541-
return true
542-
})
543-
544-
// No TriggerExecutor, so return same tree
545-
if !containsTrigger {
546-
return n, transform.SameTree, nil
547-
}
548-
549-
// If we don't have a transaction session we can't do rollbacks
550-
_, ok := ctx.Session.(sql.TransactionSession)
551-
if !ok {
552-
return plan.NewNoopTriggerRollback(n), transform.NewTree, nil
553-
}
554-
555-
// Wrap tree with new node
556-
return plan.NewTriggerRollback(n), transform.NewTree, nil
557-
}

sql/plan/trigger.go

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -102,104 +102,4 @@ func (t *TriggerExecutor) CheckPrivileges(ctx *sql.Context, opChecker sql.Privil
102102
// CollationCoercibility implements the interface sql.CollationCoercible.
103103
func (t *TriggerExecutor) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
104104
return sql.GetCoercibility(ctx, t.left)
105-
}
106-
107-
// TriggerRollback is a node that wraps the entire tree iff it contains a trigger, creates a savepoint, and performs a
108-
// rollback if something went wrong during execution
109-
type TriggerRollback struct {
110-
UnaryNode
111-
}
112-
113-
var _ sql.Node = (*TriggerRollback)(nil)
114-
var _ sql.CollationCoercible = (*TriggerRollback)(nil)
115-
116-
func NewTriggerRollback(child sql.Node) *TriggerRollback {
117-
return &TriggerRollback{
118-
UnaryNode: UnaryNode{Child: child},
119-
}
120-
}
121-
122-
func (t *TriggerRollback) WithChildren(children ...sql.Node) (sql.Node, error) {
123-
if len(children) != 1 {
124-
return nil, sql.ErrInvalidChildrenNumber.New(t, len(children), 1)
125-
}
126-
127-
return NewTriggerRollback(children[0]), nil
128-
}
129-
130-
// CheckPrivileges implements the interface sql.Node.
131-
func (t *TriggerRollback) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
132-
return t.Child.CheckPrivileges(ctx, opChecker)
133-
}
134-
135-
// CollationCoercibility implements the interface sql.CollationCoercible.
136-
func (t *TriggerRollback) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
137-
return sql.GetCoercibility(ctx, t.Child)
138-
}
139-
140-
func (t *TriggerRollback) IsReadOnly() bool {
141-
return t.Child.IsReadOnly()
142-
}
143-
144-
func (t *TriggerRollback) String() string {
145-
pr := sql.NewTreePrinter()
146-
_ = pr.WriteNode("TriggerRollback()")
147-
_ = pr.WriteChildren(t.Child.String())
148-
return pr.String()
149-
}
150-
151-
func (t *TriggerRollback) DebugString() string {
152-
pr := sql.NewTreePrinter()
153-
_ = pr.WriteNode("TriggerRollback")
154-
_ = pr.WriteChildren(sql.DebugString(t.Child))
155-
return pr.String()
156-
}
157-
158-
type NoopTriggerRollback struct {
159-
UnaryNode
160-
}
161-
162-
var _ sql.Node = (*NoopTriggerRollback)(nil)
163-
var _ sql.CollationCoercible = (*NoopTriggerRollback)(nil)
164-
165-
func NewNoopTriggerRollback(child sql.Node) *NoopTriggerRollback {
166-
return &NoopTriggerRollback{
167-
UnaryNode: UnaryNode{Child: child},
168-
}
169-
}
170-
171-
func (t *NoopTriggerRollback) WithChildren(children ...sql.Node) (sql.Node, error) {
172-
if len(children) != 1 {
173-
return nil, sql.ErrInvalidChildrenNumber.New(t, len(children), 1)
174-
}
175-
176-
return NewNoopTriggerRollback(children[0]), nil
177-
}
178-
179-
// CheckPrivileges implements the interface sql.Node.
180-
func (t *NoopTriggerRollback) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
181-
return t.Child.CheckPrivileges(ctx, opChecker)
182-
}
183-
184-
// CollationCoercibility implements the interface sql.CollationCoercible.
185-
func (t *NoopTriggerRollback) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
186-
return sql.GetCoercibility(ctx, t.Child)
187-
}
188-
189-
func (t *NoopTriggerRollback) IsReadOnly() bool {
190-
return true
191-
}
192-
193-
func (t *NoopTriggerRollback) String() string {
194-
pr := sql.NewTreePrinter()
195-
_ = pr.WriteNode("TriggerRollback()")
196-
_ = pr.WriteChildren(t.Child.String())
197-
return pr.String()
198-
}
199-
200-
func (t *NoopTriggerRollback) DebugString() string {
201-
pr := sql.NewTreePrinter()
202-
_ = pr.WriteNode("TriggerRollback")
203-
_ = pr.WriteChildren(sql.DebugString(t.Child))
204-
return pr.String()
205-
}
105+
}

sql/rowexec/builder.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type ExecBuilderFunc func(ctx *sql.Context, n sql.Node, r sql.Row) (sql.RowIter,
3232
type BaseBuilder struct {
3333
// if override is provided, we try to build executor with this first
3434
override sql.NodeExecBuilder
35-
triggerSavePointCounter int // tracks the number of save points that have been created by triggers
3635
}
3736

3837
func (b *BaseBuilder) Build(ctx *sql.Context, n sql.Node, r sql.Row) (sql.RowIter, error) {

sql/rowexec/dml.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -256,32 +256,6 @@ func (b *BaseBuilder) buildDropTable(ctx *sql.Context, n *plan.DropTable, row sq
256256
return rowIterWithOkResultWithZeroRowsAffected(), nil
257257
}
258258

259-
func (b *BaseBuilder) buildTriggerRollback(ctx *sql.Context, n *plan.TriggerRollback, row sql.Row) (sql.RowIter, error) {
260-
childIter, err := b.buildNodeExec(ctx, n.Child, row)
261-
if err != nil {
262-
return nil, err
263-
}
264-
265-
savePointCounter := b.triggerSavePointCounter + 1
266-
savePointName := fmt.Sprintf("%s%v", TriggerSavePointPrefix, savePointCounter)
267-
ctx.GetLogger().Tracef("TriggerRollback creating savepoint: %s", savePointName)
268-
269-
ts, ok := ctx.Session.(sql.TransactionSession)
270-
if !ok {
271-
return nil, fmt.Errorf("expected a sql.TransactionSession, but got %T", ctx.Session)
272-
}
273-
274-
if err := ts.CreateSavepoint(ctx, ctx.GetTransaction(), savePointName); err != nil {
275-
ctx.GetLogger().WithError(err).Errorf("CreateSavepoint failed")
276-
}
277-
b.triggerSavePointCounter = savePointCounter
278-
279-
return &triggerRollbackIter{
280-
child: childIter,
281-
savePointName: savePointName,
282-
}, nil
283-
}
284-
285259
func (b *BaseBuilder) buildAlterIndex(ctx *sql.Context, n *plan.AlterIndex, row sql.Row) (sql.RowIter, error) {
286260
err := b.executeAlterIndex(ctx, n)
287261
if err != nil {

sql/rowexec/dml_iters.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,47 @@ type triggerRollbackIter struct {
3333
savePointName string
3434
}
3535

36+
func containsTrigger(node sql.Node) bool {
37+
// Check if tree contains a TriggerExecutor
38+
hasTrigger := false
39+
transform.Inspect(node, func(n sql.Node) bool {
40+
switch nn := n.(type) {
41+
case *plan.TriggerExecutor:
42+
hasTrigger = true
43+
return false
44+
case *plan.InsertInto:
45+
// Before Triggers on Inserts are inside Source
46+
if _, ok := nn.Source.(*plan.TriggerExecutor); ok {
47+
hasTrigger = true
48+
return false
49+
}
50+
}
51+
return true
52+
})
53+
return hasTrigger
54+
}
55+
56+
func AddTriggerRollbackIter(ctx *sql.Context, node sql.Node, iter sql.RowIter) sql.RowIter {
57+
if !containsTrigger(node) {
58+
return iter
59+
}
60+
61+
transSess, isTransSess := ctx.Session.(sql.TransactionSession)
62+
if !isTransSess {
63+
return iter
64+
}
65+
66+
ctx.GetLogger().Tracef("TriggerRollback creating savepoint: %s", TriggerSavePointPrefix)
67+
if err := transSess.CreateSavepoint(ctx, ctx.GetTransaction(), TriggerSavePointPrefix); err != nil {
68+
ctx.GetLogger().WithError(err).Errorf("CreateSavepoint failed")
69+
}
70+
71+
return &triggerRollbackIter{
72+
child: iter,
73+
savePointName: TriggerSavePointPrefix,
74+
}
75+
}
76+
3677
func (t *triggerRollbackIter) Next(ctx *sql.Context) (row sql.Row, returnErr error) {
3778
childRow, err := t.child.Next(ctx)
3879

sql/rowexec/node_builder.gen.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ func (b *BaseBuilder) buildNodeExecNoAnalyze(ctx *sql.Context, n sql.Node, row s
150150
return b.buildHaving(ctx, n, row)
151151
case *plan.Signal:
152152
return b.buildSignal(ctx, n, row)
153-
case *plan.TriggerRollback:
154-
return b.buildTriggerRollback(ctx, n, row)
155153
case *plan.ExternalProcedure:
156154
return b.buildExternalProcedure(ctx, n, row)
157155
case *plan.Into:
@@ -246,8 +244,6 @@ func (b *BaseBuilder) buildNodeExecNoAnalyze(ctx *sql.Context, n sql.Node, row s
246244
return b.buildCreateIndex(ctx, n, row)
247245
case *plan.Procedure:
248246
return b.buildProcedure(ctx, n, row)
249-
case *plan.NoopTriggerRollback:
250-
return b.buildNoopTriggerRollback(ctx, n, row)
251247
case *plan.With:
252248
return b.buildWith(ctx, n, row)
253249
case *plan.Project:

0 commit comments

Comments
 (0)