Hi, It's a bit odd that syncscan.c is used by both heapam.c and tableam.c, and provides a generic block-synchronization mechanism that other table AMs might want to use too, but it lives under src/backend/access/heap. It doesn't actually do anything heap specific (beyond being block-oriented), and it's weird that tableam.c has to include heapam.h.
Perhaps we should move the .c file under src/backend/access/table, as attached. I suppose it's remotely possible that someone might invent physical-order index scans, and once you have those you might sync scans of those too, and then even table would be too specific, but that may be a bit far fetched.
From c80c24572e8f42121aa9d75c2fdd8c6b127f8ae9 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Tue, 23 Jun 2020 10:49:51 +1200 Subject: [PATCH] Move syncscan.c to src/backend/access/table. Since the tableam.c code needs to make use of the syncscan.c routines itself, and since other block-oriented table AMs might also need to do that, it didn't make sense for syncscan.c to be under src/backend/access/heap. --- src/backend/access/heap/Makefile | 1 - src/backend/access/heap/heapam.c | 1 + src/backend/access/heap/heapam_handler.c | 1 + src/backend/access/table/Makefile | 1 + src/backend/access/{heap => table}/syncscan.c | 6 ++--- src/backend/access/table/tableam.c | 2 +- src/backend/storage/ipc/ipci.c | 1 + src/include/access/heapam.h | 6 ----- src/include/access/syncscan.h | 25 +++++++++++++++++++ 9 files changed, 33 insertions(+), 11 deletions(-) rename src/backend/access/{heap => table}/syncscan.c (98%) create mode 100644 src/include/access/syncscan.h diff --git a/src/backend/access/heap/Makefile b/src/backend/access/heap/Makefile index 51a7f5e0d0..af0bd1888e 100644 --- a/src/backend/access/heap/Makefile +++ b/src/backend/access/heap/Makefile @@ -20,7 +20,6 @@ OBJS = \ hio.o \ pruneheap.o \ rewriteheap.o \ - syncscan.o \ vacuumlazy.o \ visibilitymap.o diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 537913d1bb..d91722cfa5 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -41,6 +41,7 @@ #include "access/parallel.h" #include "access/relscan.h" #include "access/subtrans.h" +#include "access/syncscan.h" #include "access/sysattr.h" #include "access/tableam.h" #include "access/transam.h" diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index 56b35622f1..ac71c2352f 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -24,6 +24,7 @@ #include "access/heaptoast.h" #include "access/multixact.h" #include "access/rewriteheap.h" +#include "access/syncscan.h" #include "access/tableam.h" #include "access/tsmapi.h" #include "access/xact.h" diff --git a/src/backend/access/table/Makefile b/src/backend/access/table/Makefile index 9aba3ff489..4c2c669828 100644 --- a/src/backend/access/table/Makefile +++ b/src/backend/access/table/Makefile @@ -13,6 +13,7 @@ top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global OBJS = \ + syncscan.o \ table.o \ tableam.o \ tableamapi.o \ diff --git a/src/backend/access/heap/syncscan.c b/src/backend/access/table/syncscan.c similarity index 98% rename from src/backend/access/heap/syncscan.c rename to src/backend/access/table/syncscan.c index a32f6836f8..3f0e91c0cf 100644 --- a/src/backend/access/heap/syncscan.c +++ b/src/backend/access/table/syncscan.c @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------- * * syncscan.c - * heap scan synchronization support + * scan synchronization support for block-oriented table AMs * * When multiple backends run a sequential scan on the same table, we try * to keep them synchronized to reduce the overall I/O needed. The goal is @@ -40,13 +40,13 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * src/backend/access/heap/syncscan.c + * src/backend/access/table/syncscan.c * *------------------------------------------------------------------------- */ #include "postgres.h" -#include "access/heapam.h" +#include "access/syncscan.h" #include "miscadmin.h" #include "storage/lwlock.h" #include "storage/shmem.h" diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c index c814733b22..7e0cd895ac 100644 --- a/src/backend/access/table/tableam.c +++ b/src/backend/access/table/tableam.c @@ -21,7 +21,7 @@ #include <math.h> -#include "access/heapam.h" /* for ss_* */ +#include "access/syncscan.h" #include "access/tableam.h" #include "access/xact.h" #include "optimizer/plancat.h" diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 427b0d59cd..e850ebd131 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -20,6 +20,7 @@ #include "access/multixact.h" #include "access/nbtree.h" #include "access/subtrans.h" +#include "access/syncscan.h" #include "access/twophase.h" #include "commands/async.h" #include "miscadmin.h" diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index f279edc473..b31de38910 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -182,12 +182,6 @@ extern void heap_page_prune_execute(Buffer buffer, OffsetNumber *nowunused, int nunused); extern void heap_get_root_tuples(Page page, OffsetNumber *root_offsets); -/* in heap/syncscan.c */ -extern void ss_report_location(Relation rel, BlockNumber location); -extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks); -extern void SyncScanShmemInit(void); -extern Size SyncScanShmemSize(void); - /* in heap/vacuumlazy.c */ struct VacuumParams; extern void heap_vacuum_rel(Relation onerel, diff --git a/src/include/access/syncscan.h b/src/include/access/syncscan.h new file mode 100644 index 0000000000..7cbf63c399 --- /dev/null +++ b/src/include/access/syncscan.h @@ -0,0 +1,25 @@ +/*------------------------------------------------------------------------- + * + * syncscan.h + * POSTGRES synchronous scan support functions. + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/syncscan.h + * + *------------------------------------------------------------------------- + */ +#ifndef SYNCSCAN_H +#define SYNCSCAN_H + +#include "storage/block.h" +#include "utils/relcache.h" + +extern void ss_report_location(Relation rel, BlockNumber location); +extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks); +extern void SyncScanShmemInit(void); +extern Size SyncScanShmemSize(void); + +#endif -- 2.20.1