Skip to content

Commit baa759c

Browse files
authored
removing transaction committing node (#2708)
1 parent c43dfa9 commit baa759c

16 files changed

+56
-197
lines changed

engine.go

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ func (e *Engine) QueryWithBindings(ctx *sql.Context, query string, parsed sqlpar
446446

447447
return nil, nil, nil, err
448448
}
449-
iter = rowexec.AddExpressionCloser(analyzed, iter)
449+
450+
iter = finalizeIters(analyzed, qFlags, iter)
450451

451452
return analyzed.Schema(), iter, qFlags, nil
452453
}
@@ -480,7 +481,8 @@ func (e *Engine) PrepQueryPlanForExecution(ctx *sql.Context, _ string, plan sql.
480481

481482
return nil, nil, nil, err
482483
}
483-
iter = rowexec.AddExpressionCloser(plan, iter)
484+
485+
iter = finalizeIters(plan, nil, iter)
484486

485487
return plan.Schema(), iter, nil, nil
486488
}
@@ -722,31 +724,6 @@ func (e *Engine) CloseSession(connID uint32) {
722724
e.PreparedDataCache.DeleteSessionData(connID)
723725
}
724726

725-
// Count number of BindVars in given tree
726-
func countBindVars(node sql.Node) int {
727-
var bindVars map[string]bool
728-
bindCntFunc := func(e sql.Expression) bool {
729-
if bv, ok := e.(*expression.BindVar); ok {
730-
if bindVars == nil {
731-
bindVars = make(map[string]bool)
732-
}
733-
bindVars[bv.Name] = true
734-
}
735-
return true
736-
}
737-
transform.InspectExpressions(node, bindCntFunc)
738-
739-
// InsertInto.Source not a child of InsertInto, so also need to traverse those
740-
transform.Inspect(node, func(n sql.Node) bool {
741-
if in, ok := n.(*plan.InsertInto); ok {
742-
transform.InspectExpressions(in.Source, bindCntFunc)
743-
return false
744-
}
745-
return true
746-
})
747-
return len(bindVars)
748-
}
749-
750727
func (e *Engine) beginTransaction(ctx *sql.Context) error {
751728
beginNewTransaction := ctx.GetTransaction() == nil || plan.ReadCommitted(ctx)
752729
if beginNewTransaction {
@@ -852,7 +829,8 @@ func (e *Engine) executeEvent(ctx *sql.Context, dbName, createEventStatement, us
852829
}
853830
return err
854831
}
855-
iter = rowexec.AddExpressionCloser(definitionNode, iter)
832+
833+
iter = finalizeIters(definitionNode, nil, iter)
856834

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

886864
return createEventNode, nil
887865
}
866+
867+
// finalizeIters applies the final transformations on sql.RowIter before execution.
868+
func finalizeIters(analyzed sql.Node, qFlags *sql.QueryFlags, iter sql.RowIter) sql.RowIter {
869+
iter = rowexec.AddTransactionCommittingIter(iter, qFlags)
870+
iter = rowexec.AddExpressionCloser(analyzed, iter)
871+
return iter
872+
}

enginetest/memory_engine_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/dolthub/go-mysql-server/memory"
3131
"github.com/dolthub/go-mysql-server/sql"
3232
"github.com/dolthub/go-mysql-server/sql/expression"
33-
"github.com/dolthub/go-mysql-server/sql/plan"
3433
"github.com/dolthub/go-mysql-server/sql/types"
3534
_ "github.com/dolthub/go-mysql-server/sql/variables"
3635
)
@@ -196,13 +195,6 @@ func TestSingleQueryPrepared(t *testing.T) {
196195
enginetest.TestScriptWithEnginePrepared(t, engine, harness, test)
197196
}
198197

199-
func newUpdateResult(matched, updated int) types.OkResult {
200-
return types.OkResult{
201-
RowsAffected: uint64(updated),
202-
Info: plan.UpdateInfo{Matched: matched, Updated: updated},
203-
}
204-
}
205-
206198
// Convenience test for debugging a single query. Unskip and set to the desired query.
207199
func TestSingleScript(t *testing.T) {
208200
t.Skip()
@@ -1065,14 +1057,6 @@ func findTable(dbs []sql.Database, tableName string) (sql.Database, sql.Table) {
10651057
return nil, nil
10661058
}
10671059

1068-
func mergeSetupScripts(scripts ...setup.SetupScript) []string {
1069-
var all []string
1070-
for _, s := range scripts {
1071-
all = append(all, s...)
1072-
}
1073-
return all
1074-
}
1075-
10761060
func TestSQLLogicTests(t *testing.T) {
10771061
enginetest.TestSQLLogicTests(t, enginetest.NewMemoryHarness("default", 1, testNumPartitions, true, mergableIndexDriver))
10781062
}

server/handler.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -519,28 +519,26 @@ func resultForEmptyIter(ctx *sql.Context, iter sql.RowIter, resultFields []*quer
519519
func GetDeferredProjections(iter sql.RowIter) (sql.RowIter, []sql.Expression) {
520520
switch i := iter.(type) {
521521
case *rowexec.ExprCloserIter:
522-
_, projs := GetDeferredProjections(i.GetIter())
523-
return i, projs
522+
if newChild, projs := GetDeferredProjections(i.GetIter()); projs != nil {
523+
return i.WithChildIter(newChild), projs
524+
}
524525
case *plan.TrackedRowIter:
525-
_, projs := GetDeferredProjections(i.GetIter())
526-
return i, projs
526+
if newChild, projs := GetDeferredProjections(i.GetIter()); projs != nil {
527+
return i.WithChildIter(newChild), projs
528+
}
527529
case *rowexec.TransactionCommittingIter:
528-
newChild, projs := GetDeferredProjections(i.GetIter())
529-
if projs != nil {
530-
i.WithChildIter(newChild)
530+
if newChild, projs := GetDeferredProjections(i.GetIter()); projs != nil {
531+
return i.WithChildIter(newChild), projs
531532
}
532-
return i, projs
533533
case *iters.LimitIter:
534-
newChild, projs := GetDeferredProjections(i.ChildIter)
535-
if projs != nil {
534+
if newChild, projs := GetDeferredProjections(i.ChildIter); projs != nil {
536535
i.ChildIter = newChild
536+
return i, projs
537537
}
538-
return i, projs
539538
case *rowexec.ProjectIter:
540539
if i.CanDefer() {
541540
return i.GetChildIter(), i.GetProjections()
542541
}
543-
return i, nil
544542
}
545543
return iter, nil
546544
}

sql/analyzer/analyzer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ func NewProcRuleSelector(sel RuleSelector) RuleSelector {
404404
unnestInSubqueriesId,
405405

406406
// once after default rules should only be run once
407-
AutocommitId,
408407
TrackProcessId,
409408
parallelizeId:
410409
return false

sql/analyzer/autocommit.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

sql/analyzer/parallelize.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ func shouldParallelize(node sql.Node, scope *plan.Scope) bool {
5454
return false
5555
}
5656

57-
if tc, ok := node.(*plan.TransactionCommittingNode); ok {
58-
return shouldParallelize(tc.Child(), scope)
59-
}
60-
6157
// Do not try to parallelize DDL or descriptive operations
6258
return !plan.IsNoRowNode(node)
6359
}

sql/analyzer/resolve_subqueries.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ func StripPassthroughNodes(n sql.Node) sql.Node {
296296
switch tn := n.(type) {
297297
case *plan.QueryProcess:
298298
n = tn.Child()
299-
case *plan.TransactionCommittingNode:
300-
n = tn.Child()
301299
default:
302300
nodeIsPassthrough = false
303301
}

sql/analyzer/rule_ids.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ const (
8686

8787
// after all
8888
cacheSubqueryAliasesInJoinsId // cacheSubqueryAliasesInJoins
89-
backtickDefaulColumnValueNamesId // backtickDefaultColumnValueNames
90-
AutocommitId // addAutocommit
89+
BacktickDefaulColumnValueNamesId // backtickDefaultColumnValueNames
9190
TrackProcessId // trackProcess
9291
parallelizeId // parallelize
9392
)

sql/analyzer/ruleid_string.go

Lines changed: 5 additions & 6 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ func init() {
2525
{wrapWithRollbackId, wrapWithRollback},
2626
{inlineSubqueryAliasRefsId, inlineSubqueryAliasRefs},
2727
{cacheSubqueryAliasesInJoinsId, cacheSubqueryAliasesInJoins},
28-
{backtickDefaulColumnValueNamesId, backtickDefaultColumnValueNames},
29-
{AutocommitId, addAutocommit},
28+
{BacktickDefaulColumnValueNamesId, backtickDefaultColumnValueNames},
3029
{TrackProcessId, trackProcess},
3130
{parallelizeId, parallelize},
3231
}

0 commit comments

Comments
 (0)