mirror of
https://github.com/postgres/postgres.git
synced 2026-04-01 15:26:56 -04:00
this one could be useful for people experiencing out-of-memory crashes while executing queries which retrieve or use a very large number of tuples. The problem happens when storage is allocated for functions results used in a large query, for example: select upper(name) from big_table; select big_table.array[1] from big_table; select count(upper(name)) from big_table; This patch is a dirty hack that fixes the out-of-memory problem for the most common cases, like the above ones. It is not the final solution for the problem but it can work for some people, so I'm posting it. The patch should be safe because all changes are under #ifdef. Furthermore the feature can be enabled or disabled at runtime by the `free_tuple_memory' options in the pg_options file. The option is disabled by default and must be explicitly enabled at runtime to have any effect. To enable the patch add the follwing line to Makefile.custom: CUSTOM_COPT += -DFREE_TUPLE_MEMORY To enable the option at runtime add the following line to pg_option: free_tuple_memory=1 Massimo
93 lines
2.6 KiB
C
93 lines
2.6 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* portal.h
|
|
* POSTGRES portal definitions.
|
|
*
|
|
*
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* $Id: portal.h,v 1.14 1999/06/12 14:05:40 momjian Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
/*
|
|
* Note:
|
|
* A portal is an abstraction which represents the execution state of
|
|
* a running query (or a fixed sequence of queries). The "blank portal" is
|
|
* a portal with an InvalidName. This blank portal is in existance except
|
|
* between calls to BlankPortalAssignName and GetPortalByName(NULL).
|
|
*
|
|
* Note:
|
|
* now that PQ calls can be made from within a backend, a portal
|
|
* may also be used to keep track of the tuples resulting
|
|
* from the execution of a query. In this case, entryIndex
|
|
*/
|
|
#ifndef PORTAL_H
|
|
#define PORTAL_H
|
|
|
|
#include <executor/execdesc.h>
|
|
#include <lib/fstack.h>
|
|
#include <nodes/memnodes.h>
|
|
#include <utils/memutils.h>
|
|
|
|
typedef struct PortalBlockData
|
|
{
|
|
AllocSetData setData;
|
|
FixedItemData itemData;
|
|
} PortalBlockData;
|
|
|
|
typedef PortalBlockData *PortalBlock;
|
|
|
|
typedef struct PortalD PortalD;
|
|
typedef PortalD *Portal;
|
|
|
|
struct PortalD
|
|
{
|
|
char *name; /* XXX PortalName */
|
|
struct PortalVariableMemoryData variable;
|
|
struct PortalHeapMemoryData heap;
|
|
QueryDesc *queryDesc;
|
|
TupleDesc attinfo;
|
|
EState *state;
|
|
void (*cleanup) (Portal);
|
|
};
|
|
|
|
/*
|
|
* PortalIsValid
|
|
* True iff portal is valid.
|
|
*/
|
|
#define PortalIsValid(p) PointerIsValid(p)
|
|
|
|
/*
|
|
* Special portals (well, their names anyway)
|
|
*/
|
|
#define VACPNAME "<vacuum>"
|
|
|
|
extern bool PortalNameIsSpecial(char *pname);
|
|
extern void AtEOXact_portals(void);
|
|
extern void EnablePortalManager(bool on);
|
|
extern Portal GetPortalByName(char *name);
|
|
extern Portal BlankPortalAssignName(char *name);
|
|
extern void PortalSetQuery(Portal portal, QueryDesc *queryDesc,
|
|
TupleDesc attinfo, EState *state,
|
|
void (*cleanup) (Portal portal));
|
|
extern QueryDesc *PortalGetQueryDesc(Portal portal);
|
|
extern EState *PortalGetState(Portal portal);
|
|
extern Portal CreatePortal(char *name);
|
|
extern void PortalDestroy(Portal *portalP);
|
|
extern void StartPortalAllocMode(AllocMode mode, Size limit);
|
|
extern void EndPortalAllocMode(void);
|
|
extern PortalVariableMemory PortalGetVariableMemory(Portal portal);
|
|
extern PortalHeapMemory PortalGetHeapMemory(Portal portal);
|
|
|
|
#ifdef FREE_TUPLE_MEMORY
|
|
bool PortalHeapMemoryIsValid(MemoryContext context, Pointer pointer);
|
|
#endif
|
|
|
|
/* estimate of the maximum number of open portals a user would have,
|
|
* used in initially sizing the PortalHashTable in EnablePortalManager()
|
|
*/
|
|
#define PORTALS_PER_USER 10
|
|
|
|
|
|
#endif /* PORTAL_H */
|