@@ -304,7 +304,7 @@ func (s *session) doCommitWithRetry() error {
304304 // We make larger transactions retry less times to prevent cluster resource outage.
305305 txnSizeRate := float64 (txnSize ) / float64 (kv .TxnTotalSizeLimit )
306306 maxRetryCount := commitRetryLimit - int (float64 (commitRetryLimit - 1 )* txnSizeRate )
307- err = s .retry (maxRetryCount , domain . ErrInfoSchemaChanged . Equal ( err ) )
307+ err = s .retry (maxRetryCount )
308308 }
309309 }
310310 s .cleanRetryInfo ()
@@ -387,7 +387,7 @@ func (s *session) isRetryableError(err error) bool {
387387 return kv .IsRetryableError (err ) || domain .ErrInfoSchemaChanged .Equal (err )
388388}
389389
390- func (s * session ) retry (maxCnt int , infoSchemaChanged bool ) error {
390+ func (s * session ) retry (maxCnt int ) error {
391391 connID := s .sessionVars .ConnectionID
392392 if s .sessionVars .TxnCtx .ForUpdate {
393393 return errors .Errorf ("[%d] can not retry select for update statement" , connID )
@@ -411,19 +411,15 @@ func (s *session) retry(maxCnt int, infoSchemaChanged bool) error {
411411 if st .IsReadOnly () {
412412 continue
413413 }
414- txt := st .OriginText ()
415- if infoSchemaChanged {
416- st , err = updateStatement (st , s , txt )
417- if err != nil {
418- return errors .Trace (err )
419- }
420- nh .history [i ].st = st
414+ err = st .RebuildPlan ()
415+ if err != nil {
416+ return errors .Trace (err )
421417 }
422418
423419 if retryCnt == 0 {
424420 // We do not have to log the query every time.
425421 // We print the queries at the first try only.
426- log .Warnf ("[%d] Retry [%d] query [%d] %s" , connID , retryCnt , i , sqlForLog (txt ))
422+ log .Warnf ("[%d] Retry [%d] query [%d] %s" , connID , retryCnt , i , sqlForLog (st . OriginText () ))
427423 } else {
428424 log .Warnf ("[%d] Retry [%d] query [%d]" , connID , retryCnt , i )
429425 }
@@ -449,7 +445,6 @@ func (s *session) retry(maxCnt int, infoSchemaChanged bool) error {
449445 return errors .Trace (err )
450446 }
451447 retryCnt ++
452- infoSchemaChanged = domain .ErrInfoSchemaChanged .Equal (err )
453448 if retryCnt >= maxCnt {
454449 log .Warnf ("[%d] Retry reached max count %d" , connID , retryCnt )
455450 return errors .Trace (err )
@@ -462,27 +457,6 @@ func (s *session) retry(maxCnt int, infoSchemaChanged bool) error {
462457 return err
463458}
464459
465- func updateStatement (st ast.Statement , s * session , txt string ) (ast.Statement , error ) {
466- // statement maybe stale because of infoschema changed, this function will return the updated one.
467- if st .IsPrepared () {
468- // TODO: Rebuild plan if infoschema changed, reuse the statement otherwise.
469- } else {
470- // Rebuild plan if infoschema changed, reuse the statement otherwise.
471- charset , collation := s .sessionVars .GetCharsetInfo ()
472- stmt , err := s .parser .ParseOneStmt (txt , charset , collation )
473- if err != nil {
474- return st , errors .Trace (err )
475- }
476- st , err = Compile (s , stmt )
477- if err != nil {
478- // If a txn is inserting data when DDL is dropping column,
479- // it would fail to commit and retry, and run here then.
480- return st , errors .Trace (err )
481- }
482- }
483- return st , nil
484- }
485-
486460func sqlForLog (sql string ) string {
487461 if len (sql ) > sqlLogMaxLen {
488462 return sql [:sqlLogMaxLen ] + fmt .Sprintf ("(len:%d)" , len (sql ))
@@ -709,6 +683,8 @@ func (s *session) Execute(sql string) (recordSets []ast.RecordSet, err error) {
709683 Expensive : cacheValue .(* cache.SQLCacheValue ).Expensive ,
710684 Text : stmtNode .Text (),
711685 ReadOnly : ast .IsReadOnly (stmtNode ),
686+ Ctx : s ,
687+ StmtNode : stmtNode ,
712688 }
713689
714690 s .PrepareTxnCtx ()
0 commit comments