1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-21 02:52:47 +03:00

Add support for coordinating record typmods among parallel workers.

Tuples can have type RECORDOID and a typmod number that identifies a blessed
TupleDesc in a backend-private cache.  To support the sharing of such tuples
through shared memory and temporary files, provide a typmod registry in
shared memory.

To achieve that, introduce per-session DSM segments, created on demand when a
backend first runs a parallel query.  The per-session DSM segment has a
table-of-contents just like the per-query DSM segment, and initially the
contents are a shared record typmod registry and a DSA area to provide the
space it needs to grow.

State relating to the current session is accessed via a Session object
reached through global variable CurrentSession that may require significant
redesign further down the road as we figure out what else needs to be shared
or remodelled.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com
This commit is contained in:
Andres Freund
2017-09-14 19:59:21 -07:00
parent 9b6cb4650b
commit cc5f81366c
12 changed files with 948 additions and 39 deletions

View File

@@ -0,0 +1,44 @@
/*-------------------------------------------------------------------------
*
* session.h
* Encapsulation of user session.
*
* Copyright (c) 2017, PostgreSQL Global Development Group
*
* src/include/access/session.h
*
*-------------------------------------------------------------------------
*/
#ifndef SESSION_H
#define SESSION_H
#include "lib/dshash.h"
/* Defined in typcache.c */
typedef struct SharedRecordTypmodRegistry SharedRecordTypmodRegistry;
/*
* A struct encapsulating some elements of a user's session. For now this
* manages state that applies to parallel query, but it principle it could
* include other things that are currently global variables.
*/
typedef struct Session
{
dsm_segment *segment; /* The session-scoped DSM segment. */
dsa_area *area; /* The session-scoped DSA area. */
/* State managed by typcache.c. */
SharedRecordTypmodRegistry *shared_typmod_registry;
dshash_table *shared_record_table;
dshash_table *shared_typmod_table;
} Session;
extern void InitializeSession(void);
extern dsm_handle GetSessionDsmHandle(void);
extern void AttachSession(dsm_handle handle);
extern void DetachSession(void);
/* The current session, or NULL for none. */
extern Session *CurrentSession;
#endif /* SESSION_H */

View File

@@ -92,6 +92,12 @@ extern TupleDesc CreateTupleDescCopy(TupleDesc tupdesc);
extern TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc);
#define TupleDescSize(src) \
(offsetof(struct tupleDesc, attrs) + \
(src)->natts * sizeof(FormData_pg_attribute))
extern void TupleDescCopy(TupleDesc dst, TupleDesc src);
extern void TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
TupleDesc src, AttrNumber srcAttno);