aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/tablesample/system.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2019-03-30 20:18:53 -0700
committerAndres Freund <andres@anarazel.de>2019-03-31 18:37:57 -0700
commit73c954d24896aeb05de0f81d75e891a858e439e9 (patch)
treefd4ef1ff3c9b695b061ea3180ecda8fbea8c8b9b /src/backend/access/tablesample/system.c
parent4bb50236eb561f4639e75a393a5a1c9b8681acfb (diff)
downloadpostgresql-73c954d24896aeb05de0f81d75e891a858e439e9.tar.gz
postgresql-73c954d24896aeb05de0f81d75e891a858e439e9.zip
tableam: sample scan.
This moves sample scan support to below tableam. It's not optional as there is, in contrast to e.g. bitmap heap scans, no alternative way to perform tablesample queries. If an AM can't deal with the block based API, it will have to throw an ERROR. The tableam callbacks for this are block based, but given the current TsmRoutine interface, that seems to be required. The new interface doesn't require TsmRoutines to perform visibility checks anymore - that requires the TsmRoutine to know details about the AM, which we want to avoid. To continue to allow taking the returned number of tuples account SampleScanState now has a donetuples field (which previously e.g. existed in SystemRowsSamplerData), which is only incremented after the visibility check succeeds. Author: Andres Freund Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
Diffstat (limited to 'src/backend/access/tablesample/system.c')
-rw-r--r--src/backend/access/tablesample/system.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/backend/access/tablesample/system.c b/src/backend/access/tablesample/system.c
index 26f7de3e45d..b1fb9b32015 100644
--- a/src/backend/access/tablesample/system.c
+++ b/src/backend/access/tablesample/system.c
@@ -26,7 +26,6 @@
#include <math.h>
-#include "access/heapam.h"
#include "access/relscan.h"
#include "access/tsmapi.h"
#include "catalog/pg_type.h"
@@ -56,7 +55,7 @@ static void system_beginsamplescan(SampleScanState *node,
Datum *params,
int nparams,
uint32 seed);
-static BlockNumber system_nextsampleblock(SampleScanState *node);
+static BlockNumber system_nextsampleblock(SampleScanState *node, BlockNumber nblocks);
static OffsetNumber system_nextsampletuple(SampleScanState *node,
BlockNumber blockno,
OffsetNumber maxoffset);
@@ -177,11 +176,9 @@ system_beginsamplescan(SampleScanState *node,
* Select next block to sample.
*/
static BlockNumber
-system_nextsampleblock(SampleScanState *node)
+system_nextsampleblock(SampleScanState *node, BlockNumber nblocks)
{
SystemSamplerData *sampler = (SystemSamplerData *) node->tsm_state;
- TableScanDesc scan = node->ss.ss_currentScanDesc;
- HeapScanDesc hscan = (HeapScanDesc) scan;
BlockNumber nextblock = sampler->nextblock;
uint32 hashinput[2];
@@ -200,7 +197,7 @@ system_nextsampleblock(SampleScanState *node)
* Loop over block numbers until finding suitable block or reaching end of
* relation.
*/
- for (; nextblock < hscan->rs_nblocks; nextblock++)
+ for (; nextblock < nblocks; nextblock++)
{
uint32 hash;
@@ -212,7 +209,7 @@ system_nextsampleblock(SampleScanState *node)
break;
}
- if (nextblock < hscan->rs_nblocks)
+ if (nextblock < nblocks)
{
/* Found a suitable block; remember where we should start next time */
sampler->nextblock = nextblock + 1;