@@ -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-
750727func (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+ }
0 commit comments