@@ -100,6 +100,7 @@ const (
100100 outputFlag = "output"
101101 binaryAsHexFlag = "binary-as-hex"
102102 skipBinaryAsHexFlag = "skip-binary-as-hex"
103+ disableAutoGCFlag = "disable-auto-gc"
103104 // TODO: Consider simplifying to use MySQL's skip pattern with single flag definition
104105 // MySQL handles both --binary-as-hex and --skip-binary-as-hex with one option definition
105106 // and uses disabled_my_option to distinguish between enable/disable
@@ -155,6 +156,7 @@ func (cmd SqlCmd) ArgParser() *argparser.ArgParser {
155156 ap .SupportsFlag (binaryAsHexFlag , "" , "Print binary data as hex. Enabled by default for interactive terminals." )
156157 // TODO: MySQL uses a skip- pattern for negating flags and doesn't show them in help
157158 ap .SupportsFlag (skipBinaryAsHexFlag , "" , "Disable binary data as hex output." )
159+ ap .SupportsFlag (disableAutoGCFlag , "" , "Disable automatically running GC." )
158160 return ap
159161}
160162
@@ -227,7 +229,13 @@ func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dE
227229 return HandleVErrAndExitCode (errhand .BuildDError ("cannot use both --%s and --%s" , binaryAsHexFlag , skipBinaryAsHexFlag ).Build (), usage )
228230 }
229231
230- queryist , err := cliCtx .QueryEngine (ctx )
232+ enableAutoGC := true
233+ if apr .Contains (disableAutoGCFlag ) {
234+ enableAutoGC = false
235+ }
236+ queryist , err := cliCtx .QueryEngine (ctx , func (config * cli.LateBindQueryistConfig ) {
237+ config .EnableAutoGC = enableAutoGC
238+ })
231239 if err != nil {
232240 return HandleVErrAndExitCode (errhand .VerboseErrorFromError (err ), usage )
233241 }
@@ -618,6 +626,11 @@ func execBatchMode(ctx *sql.Context, qryist cli.Queryist, input io.Reader, conti
618626 scanner := NewStreamScanner (input )
619627 var query string
620628 for scanner .Scan () {
629+ // The session we get is wrapped in a command begin/end block.
630+ // By ending the command and starting a new one, Auto GC is able
631+ // to form safe points if/when it is enabled.
632+ sql .SessionCommandEnd (ctx .Session )
633+ sql .SessionCommandBegin (ctx .Session )
621634 if fileReadProg != nil {
622635 updateFileReadProgressOutput ()
623636 fileReadProg .setReadBytes (int64 (len (scanner .Bytes ())))
@@ -763,6 +776,12 @@ func execShell(sqlCtx *sql.Context, qryist cli.Queryist, format engine.PrintResu
763776 lastSqlCmd := ""
764777
765778 shell .Uninterpreted (func (c * ishell.Context ) {
779+ // The session we get is wrapped in a command begin/end block.
780+ // By ending the command and starting a new one, Auto GC is able
781+ // to form safe points if/when it is enabled.
782+ sql .SessionCommandEnd (sqlCtx .Session )
783+ sql .SessionCommandBegin (sqlCtx .Session )
784+
766785 query := c .Args [0 ]
767786 query = strings .TrimSpace (query )
768787 if len (query ) == 0 {
0 commit comments