* Get next tuple from TABLESAMPLE method. */
| 332 | * Get next tuple from TABLESAMPLE method. |
| 333 | */ |
| 334 | static TupleTableSlot * |
| 335 | tablesample_getnext(SampleScanState *scanstate) |
| 336 | { |
| 337 | TableScanDesc scan = scanstate->ss.ss_currentScanDesc; |
| 338 | TupleTableSlot *slot = scanstate->ss.ss_ScanTupleSlot; |
| 339 | |
| 340 | ExecClearTuple(slot); |
| 341 | |
| 342 | if (scanstate->done) |
| 343 | return NULL; |
| 344 | |
| 345 | for (;;) |
| 346 | { |
| 347 | if (!scanstate->haveblock) |
| 348 | { |
| 349 | if (!table_scan_sample_next_block(scan, scanstate)) |
| 350 | { |
| 351 | scanstate->haveblock = false; |
| 352 | scanstate->done = true; |
| 353 | |
| 354 | /* exhausted relation */ |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | scanstate->haveblock = true; |
| 359 | } |
| 360 | |
| 361 | if (!table_scan_sample_next_tuple(scan, scanstate, slot)) |
| 362 | { |
| 363 | /* |
| 364 | * If we get here, it means we've exhausted the items on this page |
| 365 | * and it's time to move to the next. |
| 366 | */ |
| 367 | scanstate->haveblock = false; |
| 368 | continue; |
| 369 | } |
| 370 | |
| 371 | /* Found visible tuple, return it. */ |
| 372 | break; |
| 373 | } |
| 374 | |
| 375 | scanstate->donetuples++; |
| 376 | |
| 377 | return slot; |
| 378 | } |
no test coverage detected