mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-30 18:41:16 +02:00
9da0cc3528
To make this work, tuplesort.c and logtape.c must also support parallelism, so this patch adds that infrastructure and then applies it to the particular case of parallel btree index builds. Testing to date shows that this can often be 2-3x faster than a serial index build. The model for deciding how many workers to use is fairly primitive at present, but it's better than not having the feature. We can refine it as we get more experience. Peter Geoghegan with some help from Rushabh Lathia. While Heikki Linnakangas is not an author of this patch, he wrote other patches without which this feature would not have been possible, and therefore the release notes should possibly credit him as an author of this feature. Reviewed by Claudio Freire, Heikki Linnakangas, Thomas Munro, Tels, Amit Kapila, me. Discussion: http://postgr.es/m/CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com Discussion: http://postgr.es/m/CAH2-Wz=AxWqDoVvGU7dq856S4r6sJAj6DBn7VMtigkB33N5eyg@mail.gmail.com
82 lines
2.4 KiB
C
82 lines
2.4 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* parallel.h
|
|
* Infrastructure for launching parallel workers
|
|
*
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/access/parallel.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifndef PARALLEL_H
|
|
#define PARALLEL_H
|
|
|
|
#include "access/xlogdefs.h"
|
|
#include "lib/ilist.h"
|
|
#include "postmaster/bgworker.h"
|
|
#include "storage/shm_mq.h"
|
|
#include "storage/shm_toc.h"
|
|
|
|
typedef void (*parallel_worker_main_type) (dsm_segment *seg, shm_toc *toc);
|
|
|
|
typedef struct ParallelWorkerInfo
|
|
{
|
|
BackgroundWorkerHandle *bgwhandle;
|
|
shm_mq_handle *error_mqh;
|
|
int32 pid;
|
|
} ParallelWorkerInfo;
|
|
|
|
typedef struct ParallelContext
|
|
{
|
|
dlist_node node;
|
|
SubTransactionId subid;
|
|
int nworkers;
|
|
int nworkers_launched;
|
|
char *library_name;
|
|
char *function_name;
|
|
ErrorContextCallback *error_context_stack;
|
|
shm_toc_estimator estimator;
|
|
dsm_segment *seg;
|
|
void *private_memory;
|
|
shm_toc *toc;
|
|
ParallelWorkerInfo *worker;
|
|
int nknown_attached_workers;
|
|
bool *known_attached_workers;
|
|
} ParallelContext;
|
|
|
|
typedef struct ParallelWorkerContext
|
|
{
|
|
dsm_segment *seg;
|
|
shm_toc *toc;
|
|
} ParallelWorkerContext;
|
|
|
|
extern volatile bool ParallelMessagePending;
|
|
extern PGDLLIMPORT int ParallelWorkerNumber;
|
|
extern PGDLLIMPORT bool InitializingParallelWorker;
|
|
|
|
#define IsParallelWorker() (ParallelWorkerNumber >= 0)
|
|
|
|
extern ParallelContext *CreateParallelContext(const char *library_name,
|
|
const char *function_name, int nworkers,
|
|
bool serializable_okay);
|
|
extern void InitializeParallelDSM(ParallelContext *pcxt);
|
|
extern void ReinitializeParallelDSM(ParallelContext *pcxt);
|
|
extern void LaunchParallelWorkers(ParallelContext *pcxt);
|
|
extern void WaitForParallelWorkersToAttach(ParallelContext *pcxt);
|
|
extern void WaitForParallelWorkersToFinish(ParallelContext *pcxt);
|
|
extern void DestroyParallelContext(ParallelContext *pcxt);
|
|
extern bool ParallelContextActive(void);
|
|
|
|
extern void HandleParallelMessageInterrupt(void);
|
|
extern void HandleParallelMessages(void);
|
|
extern void AtEOXact_Parallel(bool isCommit);
|
|
extern void AtEOSubXact_Parallel(bool isCommit, SubTransactionId mySubId);
|
|
extern void ParallelWorkerReportLastRecEnd(XLogRecPtr last_xlog_end);
|
|
|
|
extern void ParallelWorkerMain(Datum main_arg);
|
|
|
|
#endif /* PARALLEL_H */
|