Skip to content

Commit f3be1d2

Browse files
authored
move applyUpdateAccumulators (#2719)
1 parent 1fde9d5 commit f3be1d2

26 files changed

+3800
-4003
lines changed

engine.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,24 @@ func (e *Engine) QueryWithBindings(ctx *sql.Context, query string, parsed sqlpar
443443
if err2 != nil {
444444
return nil, nil, nil, errors.Wrap(err, "unable to clear autocommit transaction: "+err2.Error())
445445
}
446+
return nil, nil, nil, err
447+
}
446448

449+
var schema sql.Schema
450+
iter, schema = rowexec.FinalizeIters(ctx, analyzed, qFlags, iter)
451+
if err != nil {
452+
clearAutocommitErr := clearAutocommitTransaction(ctx)
453+
if clearAutocommitErr != nil {
454+
return nil, nil, nil, errors.Wrap(err, "unable to clear autocommit transaction: "+clearAutocommitErr.Error())
455+
}
447456
return nil, nil, nil, err
448457
}
449458

450-
iter = finalizeIters(ctx, analyzed, qFlags, iter)
459+
if schema == nil {
460+
schema = analyzed.Schema()
461+
}
451462

452-
return analyzed.Schema(), iter, qFlags, nil
463+
return schema, iter, qFlags, nil
453464
}
454465

455466
// PrepQueryPlanForExecution prepares a query plan for execution and returns the result schema with a row iterator to
@@ -478,13 +489,24 @@ func (e *Engine) PrepQueryPlanForExecution(ctx *sql.Context, _ string, plan sql.
478489
if err2 != nil {
479490
return nil, nil, nil, errors.Wrap(err, "unable to clear autocommit transaction: "+err2.Error())
480491
}
492+
return nil, nil, nil, err
493+
}
481494

495+
var schema sql.Schema
496+
iter, schema = rowexec.FinalizeIters(ctx, plan, qFlags, iter)
497+
if err != nil {
498+
clearAutocommitErr := clearAutocommitTransaction(ctx)
499+
if clearAutocommitErr != nil {
500+
return nil, nil, nil, errors.Wrap(err, "unable to clear autocommit transaction: "+clearAutocommitErr.Error())
501+
}
482502
return nil, nil, nil, err
483503
}
484504

485-
iter = finalizeIters(ctx, plan, qFlags, iter)
505+
if schema == nil {
506+
schema = plan.Schema()
507+
}
486508

487-
return plan.Schema(), iter, qFlags, nil
509+
return schema, iter, qFlags, nil
488510
}
489511

490512
// BoundQueryPlan returns query plan for the given statement with the given bindings applied
@@ -830,7 +852,7 @@ func (e *Engine) executeEvent(ctx *sql.Context, dbName, createEventStatement, us
830852
return err
831853
}
832854

833-
iter = finalizeIters(ctx, definitionNode, nil, iter)
855+
iter, _ = rowexec.FinalizeIters(ctx, definitionNode, nil, iter)
834856

835857
// Drain the iterate to execute the event body/definition
836858
// NOTE: No row data is returned for an event; we just need to execute the statements
@@ -863,12 +885,3 @@ func findCreateEventNode(planTree sql.Node) (*plan.CreateEvent, error) {
863885

864886
return createEventNode, nil
865887
}
866-
867-
// finalizeIters applies the final transformations on sql.RowIter before execution.
868-
func finalizeIters(ctx *sql.Context, analyzed sql.Node, qFlags *sql.QueryFlags, iter sql.RowIter) sql.RowIter {
869-
iter = rowexec.AddTriggerRollbackIter(ctx, qFlags, iter)
870-
iter = rowexec.AddTransactionCommittingIter(qFlags, iter)
871-
iter = plan.AddTrackedRowIter(ctx, analyzed, iter)
872-
iter = rowexec.AddExpressionCloser(analyzed, iter)
873-
return iter
874-
}

engine_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ func TestTrackProcess(t *testing.T) {
231231
require.True(ok)
232232

233233
iter, err := rowexec.DefaultBuilder.Build(ctx, result, nil)
234-
iter = finalizeIters(ctx, result, nil, iter)
234+
require.NoError(err)
235+
iter, _ = rowexec.FinalizeIters(ctx, result, nil, iter)
235236
require.NoError(err)
236237
_, err = sql.RowIterToRows(ctx, iter)
237238
require.NoError(err)

enginetest/enginetests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,12 +1710,12 @@ func TestInsertScriptsPrepared(t *testing.T, harness Harness) {
17101710
func TestGeneratedColumns(t *testing.T, harness Harness) {
17111711
harness.Setup(setup.MydbData)
17121712
for _, script := range queries.GeneratedColumnTests {
1713-
TestScriptPrepared(t, harness, script)
1713+
TestScript(t, harness, script)
17141714
}
17151715
for _, script := range queries.BrokenGeneratedColumnTests {
17161716
t.Run(script.Name, func(t *testing.T) {
17171717
t.Skip(script.Name)
1718-
TestScriptPrepared(t, harness, script)
1718+
TestScript(t, harness, script)
17191719
})
17201720
}
17211721
}

enginetest/queries/generated_column_plans.go

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

0 commit comments

Comments
 (0)