Commit ab9e0e71 authored by Andres Freund's avatar Andres Freund

Add shared tuplestores.

SharedTuplestore allows multiple participants to write into it and
then read the tuples back from it in parallel.  Each reader receives
partial results.

For now it always uses disk files, but other buffering policies and
other kinds of scans (ie each reader receives complete results) may be
useful in future.

The upcoming parallel hash join feature will use this facility.

Author: Thomas Munro
Reviewed-By: Peter Geoghegan, Andres Freund, Robert Haas
Discussion: https://postgr.es/m/CAEepm=2W=cOkiZxcg6qiFQP-dHUe09aqTrEMM7yJDrHMhDv_RA@mail.gmail.com
parent 25d53269
......@@ -516,6 +516,8 @@ RegisterLWLockTranches(void)
"session_record_table");
LWLockRegisterTranche(LWTRANCHE_SESSION_TYPMOD_TABLE,
"session_typmod_table");
LWLockRegisterTranche(LWTRANCHE_SHARED_TUPLESTORE,
"shared_tuplestore");
LWLockRegisterTranche(LWTRANCHE_TBM, "tbm");
LWLockRegisterTranche(LWTRANCHE_PARALLEL_APPEND, "parallel_append");
......
......@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
OBJS = logtape.o sortsupport.o tuplesort.o tuplestore.o
OBJS = logtape.o sharedtuplestore.o sortsupport.o tuplesort.o tuplestore.o
tuplesort.o: qsort_tuple.c
......
This diff is collapsed.
......@@ -215,6 +215,7 @@ typedef enum BuiltinTrancheIds
LWTRANCHE_SESSION_DSA,
LWTRANCHE_SESSION_RECORD_TABLE,
LWTRANCHE_SESSION_TYPMOD_TABLE,
LWTRANCHE_SHARED_TUPLESTORE,
LWTRANCHE_TBM,
LWTRANCHE_PARALLEL_APPEND,
LWTRANCHE_FIRST_USER_DEFINED
......
/*-------------------------------------------------------------------------
*
* sharedtuplestore.h
* Simple mechinism for sharing tuples between backends.
*
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/utils/sharedtuplestore.h
*
*-------------------------------------------------------------------------
*/
#ifndef SHAREDTUPLESTORE_H
#define SHAREDTUPLESTORE_H
#include "storage/fd.h"
#include "storage/sharedfileset.h"
struct SharedTuplestore;
typedef struct SharedTuplestore SharedTuplestore;
struct SharedTuplestoreAccessor;
typedef struct SharedTuplestoreAccessor SharedTuplestoreAccessor;
/*
* A flag indicating that the tuplestore will only be scanned once, so backing
* files can be unlinked early.
*/
#define SHARED_TUPLESTORE_SINGLE_PASS 0x01
extern size_t sts_estimate(int participants);
extern SharedTuplestoreAccessor *sts_initialize(SharedTuplestore *sts,
int participants,
int my_participant_number,
size_t meta_data_size,
int flags,
SharedFileSet *fileset,
const char *name);
extern SharedTuplestoreAccessor *sts_attach(SharedTuplestore *sts,
int my_participant_number,
SharedFileSet *fileset);
extern void sts_end_write(SharedTuplestoreAccessor *accessor);
extern void sts_reinitialize(SharedTuplestoreAccessor *accessor);
extern void sts_begin_parallel_scan(SharedTuplestoreAccessor *accessor);
extern void sts_end_parallel_scan(SharedTuplestoreAccessor *accessor);
extern void sts_puttuple(SharedTuplestoreAccessor *accessor,
void *meta_data,
MinimalTuple tuple);
extern MinimalTuple sts_parallel_scan_next(SharedTuplestoreAccessor *accessor,
void *meta_data);
#endif /* SHAREDTUPLESTORE_H */
......@@ -2038,6 +2038,8 @@ SharedRecordTableEntry
SharedRecordTableKey
SharedRecordTypmodRegistry
SharedSortInfo
SharedTuplestore
SharedTuplestoreAccessor
SharedTypmodTableEntry
ShellTypeInfo
ShippableCacheEntry
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment