MCPcopy Create free account
hub / github.com/pingcap/tidb / NextSQL

Method NextSQL

pkg/ttl/sqlbuilder/sql.go:339–374  ·  view source on GitHub ↗

NextSQL creates next sql of the scan task

(continueFromResult [][]types.Datum, nextLimit int)

Source from the content-addressed store, hash-verified

337
338// NextSQL creates next sql of the scan task
339func (g *ScanQueryGenerator) NextSQL(continueFromResult [][]types.Datum, nextLimit int) (string, error) {
340 if g.exhausted {
341 return "", errors.New("generator is exhausted")
342 }
343
344 if nextLimit <= 0 {
345 return "", errors.Errorf("invalid limit '%d'", nextLimit)
346 }
347
348 defer func() {
349 g.firstBuild = false
350 }()
351
352 if g.stack == nil {
353 g.stack = make([][]types.Datum, 0, len(g.tbl.KeyColumns))
354 }
355
356 if len(continueFromResult) >= g.limit {
357 var continueFromKey []types.Datum
358 if cnt := len(continueFromResult); cnt > 0 {
359 continueFromKey = continueFromResult[cnt-1]
360 }
361 if err := g.setStack(continueFromKey); err != nil {
362 return "", err
363 }
364 } else {
365 if l := len(g.stack); l > 0 {
366 g.stack = g.stack[:l-1]
367 }
368 if len(g.stack) == 0 {
369 g.exhausted = true
370 }
371 }
372 g.limit = nextLimit
373 return g.buildSQL()
374}
375
376// IsExhausted returns whether the generator is exhausted
377func (g *ScanQueryGenerator) IsExhausted() bool {

Callers 3

TestScanQueryGeneratorFunction · 0.95
doScanMethod · 0.95
deleteExpiredRowsMethod · 0.95

Calls 4

setStackMethod · 0.95
buildSQLMethod · 0.95
NewMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestScanQueryGeneratorFunction · 0.76