NextSQL creates next sql of the scan task
(continueFromResult [][]types.Datum, nextLimit int)
| 337 | |
| 338 | // NextSQL creates next sql of the scan task |
| 339 | func (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 |
| 377 | func (g *ScanQueryGenerator) IsExhausted() bool { |