1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* execUtils.c
|
2000-07-12 04:37:39 +02:00
|
|
|
* miscellaneous executor utility routines
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2002-06-25 19:58:10 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.85 2002/06/25 17:58:10 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* INTERFACE ROUTINES
|
2000-07-12 04:37:39 +02:00
|
|
|
* ExecAssignExprContext Common code for plan node init routines.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-07-15 00:18:02 +02:00
|
|
|
* ExecOpenIndices \
|
|
|
|
* ExecCloseIndices | referenced by InitPlan, EndPlan,
|
2002-06-25 19:58:10 +02:00
|
|
|
* ExecInsertIndexTuples / ExecAppend, ExecReplace
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2002-05-12 22:10:05 +02:00
|
|
|
* RegisterExprContextCallback Register function shutdown callback
|
|
|
|
* UnregisterExprContextCallback Deregister function shutdown callback
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* NOTES
|
|
|
|
* This file has traditionally been the place to stick misc.
|
|
|
|
* executor support stuff that doesn't really go anyplace else.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1996-10-31 11:12:26 +01:00
|
|
|
#include "postgres.h"
|
|
|
|
|
1996-11-06 07:52:23 +01:00
|
|
|
#include "access/genam.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "access/heapam.h"
|
1996-11-06 07:52:23 +01:00
|
|
|
#include "catalog/catname.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "catalog/index.h"
|
2000-02-18 10:30:20 +01:00
|
|
|
#include "catalog/catalog.h"
|
2000-06-15 05:33:12 +02:00
|
|
|
#include "catalog/pg_index.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "executor/execdebug.h"
|
2000-02-18 10:30:20 +01:00
|
|
|
#include "miscadmin.h"
|
2000-05-28 19:56:29 +02:00
|
|
|
#include "utils/builtins.h"
|
|
|
|
#include "utils/fmgroids.h"
|
2000-07-12 04:37:39 +02:00
|
|
|
#include "utils/memutils.h"
|
2000-06-17 23:49:04 +02:00
|
|
|
#include "utils/relcache.h"
|
|
|
|
#include "utils/syscache.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-08-19 23:40:56 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* global counters for number of tuples processed, retrieved,
|
|
|
|
* appended, replaced, deleted.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
int NTupleProcessed;
|
|
|
|
int NTupleRetrieved;
|
|
|
|
int NTupleReplaced;
|
|
|
|
int NTupleAppended;
|
|
|
|
int NTupleDeleted;
|
|
|
|
int NIndexTupleInserted;
|
|
|
|
extern int NIndexTupleProcessed; /* have to be defined in the
|
1997-09-07 07:04:48 +02:00
|
|
|
* access method level so that the
|
|
|
|
* cinterface.a will link ok. */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2002-05-12 22:10:05 +02:00
|
|
|
|
|
|
|
static void ShutdownExprContext(ExprContext *econtext);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* statistic functions
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ResetTupleCount
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
1997-08-19 23:40:56 +02:00
|
|
|
#ifdef NOT_USED
|
1996-07-09 08:22:35 +02:00
|
|
|
void
|
1996-11-10 04:06:38 +01:00
|
|
|
ResetTupleCount(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
NTupleProcessed = 0;
|
|
|
|
NTupleRetrieved = 0;
|
|
|
|
NTupleAppended = 0;
|
|
|
|
NTupleDeleted = 0;
|
|
|
|
NTupleReplaced = 0;
|
|
|
|
NIndexTupleProcessed = 0;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-08-19 23:40:56 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* PrintTupleCount
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
1997-08-19 23:40:56 +02:00
|
|
|
#ifdef NOT_USED
|
1996-07-09 08:22:35 +02:00
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
DisplayTupleCount(FILE *statfp)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
if (NTupleProcessed > 0)
|
|
|
|
fprintf(statfp, "!\t%d tuple%s processed, ", NTupleProcessed,
|
|
|
|
(NTupleProcessed == 1) ? "" : "s");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(statfp, "!\tno tuples processed.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NIndexTupleProcessed > 0)
|
|
|
|
fprintf(statfp, "%d indextuple%s processed, ", NIndexTupleProcessed,
|
|
|
|
(NIndexTupleProcessed == 1) ? "" : "s");
|
|
|
|
if (NIndexTupleInserted > 0)
|
|
|
|
fprintf(statfp, "%d indextuple%s inserted, ", NIndexTupleInserted,
|
|
|
|
(NIndexTupleInserted == 1) ? "" : "s");
|
|
|
|
if (NTupleRetrieved > 0)
|
|
|
|
fprintf(statfp, "%d tuple%s retrieved. ", NTupleRetrieved,
|
|
|
|
(NTupleRetrieved == 1) ? "" : "s");
|
|
|
|
if (NTupleAppended > 0)
|
|
|
|
fprintf(statfp, "%d tuple%s appended. ", NTupleAppended,
|
|
|
|
(NTupleAppended == 1) ? "" : "s");
|
|
|
|
if (NTupleDeleted > 0)
|
|
|
|
fprintf(statfp, "%d tuple%s deleted. ", NTupleDeleted,
|
|
|
|
(NTupleDeleted == 1) ? "" : "s");
|
|
|
|
if (NTupleReplaced > 0)
|
|
|
|
fprintf(statfp, "%d tuple%s replaced. ", NTupleReplaced,
|
|
|
|
(NTupleReplaced == 1) ? "" : "s");
|
|
|
|
fprintf(statfp, "\n");
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-08-19 23:40:56 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
2000-07-12 04:37:39 +02:00
|
|
|
* miscellaneous node-init support functions
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------
|
2000-07-12 04:37:39 +02:00
|
|
|
* ExecAssignExprContext
|
|
|
|
*
|
|
|
|
* This initializes the ExprContext field. It is only necessary
|
|
|
|
* to do this for nodes which use ExecQual or ExecProject
|
|
|
|
* because those routines depend on econtext. Other nodes that
|
|
|
|
* don't have to evaluate expressions don't need to do this.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-07-12 04:37:39 +02:00
|
|
|
* Note: we assume CurrentMemoryContext is the correct per-query context.
|
|
|
|
* This should be true during plan node initialization.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
2000-07-12 04:37:39 +02:00
|
|
|
ExecAssignExprContext(EState *estate, CommonState *commonstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-07-12 04:37:39 +02:00
|
|
|
ExprContext *econtext = makeNode(ExprContext);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-07-12 04:37:39 +02:00
|
|
|
econtext->ecxt_scantuple = NULL;
|
|
|
|
econtext->ecxt_innertuple = NULL;
|
|
|
|
econtext->ecxt_outertuple = NULL;
|
|
|
|
econtext->ecxt_per_query_memory = CurrentMemoryContext;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2000-07-12 04:37:39 +02:00
|
|
|
/*
|
|
|
|
* Create working memory for expression evaluation in this context.
|
|
|
|
*/
|
|
|
|
econtext->ecxt_per_tuple_memory =
|
|
|
|
AllocSetContextCreate(CurrentMemoryContext,
|
|
|
|
"PlanExprContext",
|
|
|
|
ALLOCSET_DEFAULT_MINSIZE,
|
|
|
|
ALLOCSET_DEFAULT_INITSIZE,
|
|
|
|
ALLOCSET_DEFAULT_MAXSIZE);
|
|
|
|
econtext->ecxt_param_exec_vals = estate->es_param_exec_vals;
|
|
|
|
econtext->ecxt_param_list_info = estate->es_param_list_info;
|
|
|
|
econtext->ecxt_aggvalues = NULL;
|
|
|
|
econtext->ecxt_aggnulls = NULL;
|
2002-05-12 22:10:05 +02:00
|
|
|
econtext->ecxt_callbacks = NULL;
|
2000-07-12 04:37:39 +02:00
|
|
|
|
|
|
|
commonstate->cs_ExprContext = econtext;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
2000-07-12 04:37:39 +02:00
|
|
|
* MakeExprContext
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-07-12 04:37:39 +02:00
|
|
|
* Build an expression context for use outside normal plan-node cases.
|
|
|
|
* A fake scan-tuple slot can be supplied (pass NULL if not needed).
|
|
|
|
* A memory context sufficiently long-lived to use as fcache context
|
|
|
|
* must be supplied as well.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
2000-07-12 04:37:39 +02:00
|
|
|
ExprContext *
|
|
|
|
MakeExprContext(TupleTableSlot *slot,
|
|
|
|
MemoryContext queryContext)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-07-12 04:37:39 +02:00
|
|
|
ExprContext *econtext = makeNode(ExprContext);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-07-12 04:37:39 +02:00
|
|
|
econtext->ecxt_scantuple = slot;
|
|
|
|
econtext->ecxt_innertuple = NULL;
|
|
|
|
econtext->ecxt_outertuple = NULL;
|
|
|
|
econtext->ecxt_per_query_memory = queryContext;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2000-07-12 04:37:39 +02:00
|
|
|
/*
|
|
|
|
* We make the temporary context a child of current working context,
|
|
|
|
* not of the specified queryContext. This seems reasonable but I'm
|
|
|
|
* not totally sure about it...
|
|
|
|
*
|
|
|
|
* Expression contexts made via this routine typically don't live long
|
2001-03-22 05:01:46 +01:00
|
|
|
* enough to get reset, so specify a minsize of 0. That avoids
|
|
|
|
* alloc'ing any memory in the common case where expr eval doesn't use
|
|
|
|
* any.
|
2000-07-12 04:37:39 +02:00
|
|
|
*/
|
|
|
|
econtext->ecxt_per_tuple_memory =
|
|
|
|
AllocSetContextCreate(CurrentMemoryContext,
|
|
|
|
"TempExprContext",
|
|
|
|
0,
|
|
|
|
ALLOCSET_DEFAULT_INITSIZE,
|
|
|
|
ALLOCSET_DEFAULT_MAXSIZE);
|
|
|
|
econtext->ecxt_param_exec_vals = NULL;
|
|
|
|
econtext->ecxt_param_list_info = NULL;
|
|
|
|
econtext->ecxt_aggvalues = NULL;
|
|
|
|
econtext->ecxt_aggnulls = NULL;
|
2002-05-12 22:10:05 +02:00
|
|
|
econtext->ecxt_callbacks = NULL;
|
2000-07-12 04:37:39 +02:00
|
|
|
|
|
|
|
return econtext;
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-07-12 04:37:39 +02:00
|
|
|
/*
|
|
|
|
* Free an ExprContext made by MakeExprContext, including the temporary
|
2001-03-22 05:01:46 +01:00
|
|
|
* context used for expression evaluation. Note this will cause any
|
2000-07-12 04:37:39 +02:00
|
|
|
* pass-by-reference expression result to go away!
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
FreeExprContext(ExprContext *econtext)
|
|
|
|
{
|
2002-05-12 22:10:05 +02:00
|
|
|
/* Call any registered callbacks */
|
|
|
|
ShutdownExprContext(econtext);
|
|
|
|
/* And clean up the memory used */
|
2000-07-12 04:37:39 +02:00
|
|
|
MemoryContextDelete(econtext->ecxt_per_tuple_memory);
|
|
|
|
pfree(econtext);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2001-01-22 01:50:07 +01:00
|
|
|
/*
|
|
|
|
* Build a per-output-tuple ExprContext for an EState.
|
|
|
|
*
|
|
|
|
* This is normally invoked via GetPerTupleExprContext() macro.
|
|
|
|
*/
|
|
|
|
ExprContext *
|
|
|
|
MakePerTupleExprContext(EState *estate)
|
|
|
|
{
|
|
|
|
if (estate->es_per_tuple_exprcontext == NULL)
|
|
|
|
{
|
|
|
|
MemoryContext oldContext;
|
|
|
|
|
|
|
|
oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
|
|
|
|
estate->es_per_tuple_exprcontext =
|
|
|
|
MakeExprContext(NULL, estate->es_query_cxt);
|
|
|
|
MemoryContextSwitchTo(oldContext);
|
|
|
|
}
|
|
|
|
return estate->es_per_tuple_exprcontext;
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Result slot tuple type and ProjectionInfo support
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecAssignResultType
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecAssignResultType(CommonState *commonstate,
|
2001-01-29 01:39:20 +01:00
|
|
|
TupleDesc tupDesc, bool shouldFree)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2001-01-29 01:39:20 +01:00
|
|
|
TupleTableSlot *slot = commonstate->cs_ResultTupleSlot;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-01-29 01:39:20 +01:00
|
|
|
ExecSetSlotDescriptor(slot, tupDesc, shouldFree);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecAssignResultTypeFromOuterPlan
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecAssignResultTypeFromOuterPlan(Plan *node, CommonState *commonstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan *outerPlan;
|
|
|
|
TupleDesc tupDesc;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
outerPlan = outerPlan(node);
|
|
|
|
tupDesc = ExecGetTupType(outerPlan);
|
|
|
|
|
2001-01-29 01:39:20 +01:00
|
|
|
ExecAssignResultType(commonstate, tupDesc, false);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecAssignResultTypeFromTL
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-09-12 23:07:18 +02:00
|
|
|
TupleDesc tupDesc;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-01-29 01:39:20 +01:00
|
|
|
tupDesc = ExecTypeFromTL(node->targetlist);
|
|
|
|
ExecAssignResultType(commonstate, tupDesc, true);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecGetResultType
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
TupleDesc
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecGetResultType(CommonState *commonstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
TupleTableSlot *slot = commonstate->cs_ResultTupleSlot;
|
|
|
|
|
|
|
|
return slot->ttc_tupleDescriptor;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecAssignProjectionInfo
|
|
|
|
forms the projection information from the node's targetlist
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecAssignProjectionInfo(Plan *node, CommonState *commonstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
ProjectionInfo *projInfo;
|
1997-09-08 04:41:22 +02:00
|
|
|
List *targetList;
|
|
|
|
int len;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
targetList = node->targetlist;
|
|
|
|
len = ExecTargetListLength(targetList);
|
|
|
|
|
|
|
|
projInfo = makeNode(ProjectionInfo);
|
|
|
|
projInfo->pi_targetlist = targetList;
|
|
|
|
projInfo->pi_len = len;
|
1999-02-03 22:18:02 +01:00
|
|
|
projInfo->pi_tupValue = (len <= 0) ? NULL : (Datum *) palloc(sizeof(Datum) * len);
|
1997-09-07 07:04:48 +02:00
|
|
|
projInfo->pi_exprContext = commonstate->cs_ExprContext;
|
|
|
|
projInfo->pi_slot = commonstate->cs_ResultTupleSlot;
|
|
|
|
|
|
|
|
commonstate->cs_ProjInfo = projInfo;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecFreeProjectionInfo
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecFreeProjectionInfo(CommonState *commonstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
ProjectionInfo *projInfo;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* get projection info. if NULL then this node has none so we just
|
|
|
|
* return.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
projInfo = commonstate->cs_ProjInfo;
|
|
|
|
if (projInfo == NULL)
|
|
|
|
return;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* clean up memory used.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
if (projInfo->pi_tupValue != NULL)
|
|
|
|
pfree(projInfo->pi_tupValue);
|
|
|
|
|
|
|
|
pfree(projInfo);
|
|
|
|
commonstate->cs_ProjInfo = NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1999-03-20 02:13:22 +01:00
|
|
|
/* ----------------
|
|
|
|
* ExecFreeExprContext
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ExecFreeExprContext(CommonState *commonstate)
|
|
|
|
{
|
|
|
|
ExprContext *econtext;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* get expression context. if NULL then this node has none so we just
|
|
|
|
* return.
|
1999-03-20 02:13:22 +01:00
|
|
|
*/
|
|
|
|
econtext = commonstate->cs_ExprContext;
|
|
|
|
if (econtext == NULL)
|
|
|
|
return;
|
|
|
|
|
2002-05-12 22:10:05 +02:00
|
|
|
/*
|
|
|
|
* clean up any registered callbacks
|
|
|
|
*/
|
|
|
|
ShutdownExprContext(econtext);
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* clean up memory used.
|
1999-03-20 02:13:22 +01:00
|
|
|
*/
|
2000-07-12 04:37:39 +02:00
|
|
|
MemoryContextDelete(econtext->ecxt_per_tuple_memory);
|
1999-03-20 02:13:22 +01:00
|
|
|
pfree(econtext);
|
|
|
|
commonstate->cs_ExprContext = NULL;
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* the following scan type support functions are for
|
|
|
|
* those nodes which are stubborn and return tuples in
|
|
|
|
* their Scan tuple slot instead of their Result tuple
|
|
|
|
* slot.. luck fur us, these nodes do not do projections
|
|
|
|
* so we don't have to worry about getting the ProjectionInfo
|
|
|
|
* right for them... -cim 6/3/91
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecGetScanType
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
TupleDesc
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecGetScanType(CommonScanState *csstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
TupleTableSlot *slot = csstate->css_ScanTupleSlot;
|
|
|
|
|
|
|
|
return slot->ttc_tupleDescriptor;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecAssignScanType
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecAssignScanType(CommonScanState *csstate,
|
2001-01-29 01:39:20 +01:00
|
|
|
TupleDesc tupDesc, bool shouldFree)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2001-01-29 01:39:20 +01:00
|
|
|
TupleTableSlot *slot = csstate->css_ScanTupleSlot;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-01-29 01:39:20 +01:00
|
|
|
ExecSetSlotDescriptor(slot, tupDesc, shouldFree);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecAssignScanTypeFromOuterPlan
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecAssignScanTypeFromOuterPlan(Plan *node, CommonScanState *csstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan *outerPlan;
|
|
|
|
TupleDesc tupDesc;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
outerPlan = outerPlan(node);
|
|
|
|
tupDesc = ExecGetTupType(outerPlan);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2001-01-29 01:39:20 +01:00
|
|
|
ExecAssignScanType(csstate, tupDesc, false);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecInsertIndexTuples support
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* ExecOpenIndices
|
|
|
|
*
|
2000-06-17 23:49:04 +02:00
|
|
|
* Find the indices associated with a result relation, open them,
|
2000-11-12 01:37:02 +01:00
|
|
|
* and save information about them in the result ResultRelInfo.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2000-06-17 23:49:04 +02:00
|
|
|
* At entry, caller has already opened and locked
|
2000-11-12 01:37:02 +01:00
|
|
|
* resultRelInfo->ri_RelationDesc.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2000-06-17 23:49:04 +02:00
|
|
|
* This used to be horribly ugly code, and slow too because it
|
2001-03-22 05:01:46 +01:00
|
|
|
* did a sequential scan of pg_index. Now we rely on the relcache
|
2000-06-17 23:49:04 +02:00
|
|
|
* to cache a list of the OIDs of the indices associated with any
|
|
|
|
* specific relation, and we use the pg_index syscache to get the
|
|
|
|
* entries we need from pg_index.
|
1997-09-07 07:04:48 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2000-11-12 01:37:02 +01:00
|
|
|
ExecOpenIndices(ResultRelInfo *resultRelInfo)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-11-12 01:37:02 +01:00
|
|
|
Relation resultRelation = resultRelInfo->ri_RelationDesc;
|
2000-06-17 23:49:04 +02:00
|
|
|
List *indexoidlist,
|
|
|
|
*indexoidscan;
|
|
|
|
int len,
|
|
|
|
i;
|
1997-09-08 04:41:22 +02:00
|
|
|
RelationPtr relationDescs;
|
|
|
|
IndexInfo **indexInfoArray;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-11-12 01:37:02 +01:00
|
|
|
resultRelInfo->ri_NumIndices = 0;
|
2000-06-17 23:49:04 +02:00
|
|
|
|
|
|
|
/* checks for disabled indexes */
|
2001-03-22 05:01:46 +01:00
|
|
|
if (!RelationGetForm(resultRelation)->relhasindex)
|
2000-02-18 10:30:20 +01:00
|
|
|
return;
|
|
|
|
if (IsIgnoringSystemIndexes() &&
|
2002-04-12 22:38:31 +02:00
|
|
|
IsSystemRelation(resultRelation))
|
2000-02-18 10:30:20 +01:00
|
|
|
return;
|
2000-06-17 23:49:04 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* Get cached list of index OIDs
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-06-17 23:49:04 +02:00
|
|
|
indexoidlist = RelationGetIndexList(resultRelation);
|
|
|
|
len = length(indexoidlist);
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* allocate space for result arrays
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-06-17 23:49:04 +02:00
|
|
|
relationDescs = (RelationPtr) palloc(len * sizeof(Relation));
|
|
|
|
indexInfoArray = (IndexInfo **) palloc(len * sizeof(IndexInfo *));
|
|
|
|
|
2000-11-12 01:37:02 +01:00
|
|
|
resultRelInfo->ri_NumIndices = len;
|
|
|
|
resultRelInfo->ri_IndexRelationDescs = relationDescs;
|
|
|
|
resultRelInfo->ri_IndexRelationInfo = indexInfoArray;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* For each index, open the index relation and save pg_index info.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2000-06-17 23:49:04 +02:00
|
|
|
i = 0;
|
|
|
|
foreach(indexoidscan, indexoidlist)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-06-17 23:49:04 +02:00
|
|
|
Oid indexOid = lfirsti(indexoidscan);
|
|
|
|
Relation indexDesc;
|
|
|
|
IndexInfo *ii;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-06-17 23:49:04 +02:00
|
|
|
* Open (and lock, if necessary) the index relation
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2001-10-25 07:50:21 +02:00
|
|
|
* If the index AM is not safe for concurrent updates, obtain an
|
|
|
|
* exclusive lock on the index to lock out other updaters as well
|
|
|
|
* as readers (index_beginscan places AccessShareLock). We will
|
|
|
|
* release this lock in ExecCloseIndices.
|
2000-06-20 01:40:48 +02:00
|
|
|
*
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
* If the index AM supports concurrent updates, we obtain no lock
|
|
|
|
* here at all, which is a tad weird, but safe since any critical
|
2001-10-25 07:50:21 +02:00
|
|
|
* operation on the index (like deleting it) will acquire
|
|
|
|
* exclusive lock on the parent table. Perhaps someday we should
|
|
|
|
* acquire RowExclusiveLock on the index here?
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
*
|
|
|
|
* If there are multiple not-concurrent-safe indexes, all backends
|
2001-10-25 07:50:21 +02:00
|
|
|
* must lock the indexes in the same order or we will get
|
|
|
|
* deadlocks here during concurrent updates. This is guaranteed
|
|
|
|
* by RelationGetIndexList(), which promises to return the index
|
|
|
|
* list in OID order.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2000-06-17 23:49:04 +02:00
|
|
|
indexDesc = index_open(indexOid);
|
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
if (!indexDesc->rd_am->amconcurrent)
|
2000-06-17 23:49:04 +02:00
|
|
|
LockRelation(indexDesc, AccessExclusiveLock);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2002-02-19 21:11:20 +01:00
|
|
|
* extract index key information from the index's pg_index tuple
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2002-02-19 21:11:20 +01:00
|
|
|
ii = BuildIndexInfo(indexDesc->rd_index);
|
2000-11-16 23:30:52 +01:00
|
|
|
|
2000-06-17 23:49:04 +02:00
|
|
|
relationDescs[i] = indexDesc;
|
|
|
|
indexInfoArray[i] = ii;
|
|
|
|
i++;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-17 23:49:04 +02:00
|
|
|
freeList(indexoidlist);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecCloseIndices
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-11-12 01:37:02 +01:00
|
|
|
* Close the index relations stored in resultRelInfo
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2000-11-12 01:37:02 +01:00
|
|
|
ExecCloseIndices(ResultRelInfo *resultRelInfo)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int i;
|
|
|
|
int numIndices;
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
RelationPtr indexDescs;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-11-12 01:37:02 +01:00
|
|
|
numIndices = resultRelInfo->ri_NumIndices;
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
indexDescs = resultRelInfo->ri_IndexRelationDescs;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
for (i = 0; i < numIndices; i++)
|
1998-12-15 13:47:01 +01:00
|
|
|
{
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
if (indexDescs[i] == NULL)
|
1998-12-15 13:47:01 +01:00
|
|
|
continue;
|
1999-05-25 18:15:34 +02:00
|
|
|
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
/* Drop lock, if one was acquired by ExecOpenIndices */
|
2001-10-25 07:50:21 +02:00
|
|
|
if (!indexDescs[i]->rd_am->amconcurrent)
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
UnlockRelation(indexDescs[i], AccessExclusiveLock);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
index_close(indexDescs[i]);
|
1998-12-15 13:47:01 +01:00
|
|
|
}
|
1999-05-25 18:15:34 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
|
|
|
* XXX should free indexInfo array here too.
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* ExecInsertIndexTuples
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* This routine takes care of inserting index tuples
|
|
|
|
* into all the relations indexing the result relation
|
|
|
|
* when a heap tuple is inserted into the result relation.
|
|
|
|
* Much of this code should be moved into the genam
|
|
|
|
* stuff as it only exists here because the genam stuff
|
|
|
|
* doesn't provide the functionality needed by the
|
|
|
|
* executor.. -cim 9/27/89
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
ExecInsertIndexTuples(TupleTableSlot *slot,
|
1997-09-07 07:04:48 +02:00
|
|
|
ItemPointer tupleid,
|
1997-09-08 23:56:23 +02:00
|
|
|
EState *estate,
|
2002-05-24 20:57:57 +02:00
|
|
|
bool is_vacuum)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HeapTuple heapTuple;
|
2000-11-12 01:37:02 +01:00
|
|
|
ResultRelInfo *resultRelInfo;
|
1997-09-08 04:41:22 +02:00
|
|
|
int i;
|
|
|
|
int numIndices;
|
|
|
|
RelationPtr relationDescs;
|
|
|
|
Relation heapRelation;
|
2000-07-15 00:18:02 +02:00
|
|
|
TupleDesc heapDescriptor;
|
1997-09-08 04:41:22 +02:00
|
|
|
IndexInfo **indexInfoArray;
|
|
|
|
ExprContext *econtext;
|
2000-07-15 00:18:02 +02:00
|
|
|
Datum datum[INDEX_MAX_KEYS];
|
|
|
|
char nullv[INDEX_MAX_KEYS];
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
heapTuple = slot->val;
|
1996-08-26 08:32:06 +02:00
|
|
|
|
2000-08-22 06:06:22 +02:00
|
|
|
/*
|
|
|
|
* Get information from the result relation info structure.
|
1996-08-26 08:32:06 +02:00
|
|
|
*/
|
2000-11-12 01:37:02 +01:00
|
|
|
resultRelInfo = estate->es_result_relation_info;
|
|
|
|
numIndices = resultRelInfo->ri_NumIndices;
|
|
|
|
relationDescs = resultRelInfo->ri_IndexRelationDescs;
|
|
|
|
indexInfoArray = resultRelInfo->ri_IndexRelationInfo;
|
|
|
|
heapRelation = resultRelInfo->ri_RelationDesc;
|
2000-07-15 00:18:02 +02:00
|
|
|
heapDescriptor = RelationGetDescr(heapRelation);
|
|
|
|
|
2000-08-22 06:06:22 +02:00
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* We will use the EState's per-tuple context for evaluating
|
|
|
|
* predicates and functional-index functions (creating it if it's not
|
|
|
|
* already there).
|
2000-07-15 00:18:02 +02:00
|
|
|
*/
|
2001-01-22 01:50:07 +01:00
|
|
|
econtext = GetPerTupleExprContext(estate);
|
2000-08-22 06:06:22 +02:00
|
|
|
|
|
|
|
/* Arrange for econtext's scan tuple to be the tuple under test */
|
|
|
|
econtext->ecxt_scantuple = slot;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* for each index, form and insert the index tuple
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
for (i = 0; i < numIndices; i++)
|
|
|
|
{
|
2000-07-15 00:18:02 +02:00
|
|
|
IndexInfo *indexInfo;
|
2001-07-16 07:07:00 +02:00
|
|
|
List *predicate;
|
2000-07-15 00:18:02 +02:00
|
|
|
InsertIndexResult result;
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (relationDescs[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
indexInfo = indexInfoArray[i];
|
|
|
|
predicate = indexInfo->ii_Predicate;
|
2001-07-16 07:07:00 +02:00
|
|
|
if (predicate != NIL)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
/* Skip this index-update if the predicate isn't satisfied */
|
2001-07-16 07:07:00 +02:00
|
|
|
if (!ExecQual(predicate, econtext, false))
|
1997-09-07 07:04:48 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* FormIndexDatum fills in its datum and null parameters with
|
|
|
|
* attribute information taken from the given heap tuple.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2000-07-15 00:18:02 +02:00
|
|
|
FormIndexDatum(indexInfo,
|
|
|
|
heapTuple,
|
|
|
|
heapDescriptor,
|
|
|
|
econtext->ecxt_per_tuple_memory,
|
|
|
|
datum,
|
|
|
|
nullv);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-05-24 20:57:57 +02:00
|
|
|
/*
|
|
|
|
* The index AM does the rest. Note we suppress unique-index
|
|
|
|
* checks if we are being called from VACUUM, since VACUUM may
|
|
|
|
* need to move dead tuples that have the same keys as live ones.
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
result = index_insert(relationDescs[i], /* index relation */
|
|
|
|
datum, /* array of heaptuple Datums */
|
2000-07-15 00:18:02 +02:00
|
|
|
nullv, /* info on nulls */
|
1999-05-25 18:15:34 +02:00
|
|
|
&(heapTuple->t_self), /* tid of heap tuple */
|
2002-05-24 20:57:57 +02:00
|
|
|
heapRelation,
|
|
|
|
relationDescs[i]->rd_uniqueindex && !is_vacuum);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* keep track of index inserts for debugging
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
IncrIndexInserted();
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
pfree(result);
|
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1998-02-13 04:26:53 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
void
|
|
|
|
SetChangedParamList(Plan *node, List *newchg)
|
1998-02-13 04:26:53 +01:00
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
List *nl;
|
|
|
|
|
|
|
|
foreach(nl, newchg)
|
1998-02-13 04:26:53 +01:00
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
int paramId = lfirsti(nl);
|
|
|
|
|
1998-02-13 04:26:53 +01:00
|
|
|
/* if this node doesn't depend on a param ... */
|
1998-02-26 05:46:47 +01:00
|
|
|
if (!intMember(paramId, node->extParam) &&
|
|
|
|
!intMember(paramId, node->locParam))
|
1998-02-13 04:26:53 +01:00
|
|
|
continue;
|
|
|
|
/* if this param is already in list of changed ones ... */
|
1998-02-26 05:46:47 +01:00
|
|
|
if (intMember(paramId, node->chgParam))
|
1998-02-13 04:26:53 +01:00
|
|
|
continue;
|
|
|
|
/* else - add this param to the list */
|
1998-02-26 05:46:47 +01:00
|
|
|
node->chgParam = lappendi(node->chgParam, paramId);
|
1998-02-13 04:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
2002-05-12 22:10:05 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a shutdown callback in an ExprContext.
|
|
|
|
*
|
|
|
|
* Shutdown callbacks will be called (in reverse order of registration)
|
|
|
|
* when the ExprContext is deleted or rescanned. This provides a hook
|
|
|
|
* for functions called in the context to do any cleanup needed --- it's
|
|
|
|
* particularly useful for functions returning sets. Note that the
|
|
|
|
* callback will *not* be called in the event that execution is aborted
|
|
|
|
* by an error.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RegisterExprContextCallback(ExprContext *econtext,
|
|
|
|
ExprContextCallbackFunction function,
|
|
|
|
Datum arg)
|
|
|
|
{
|
|
|
|
ExprContext_CB *ecxt_callback;
|
|
|
|
|
|
|
|
/* Save the info in appropriate memory context */
|
|
|
|
ecxt_callback = (ExprContext_CB *)
|
|
|
|
MemoryContextAlloc(econtext->ecxt_per_query_memory,
|
|
|
|
sizeof(ExprContext_CB));
|
|
|
|
|
|
|
|
ecxt_callback->function = function;
|
|
|
|
ecxt_callback->arg = arg;
|
|
|
|
|
|
|
|
/* link to front of list for appropriate execution order */
|
|
|
|
ecxt_callback->next = econtext->ecxt_callbacks;
|
|
|
|
econtext->ecxt_callbacks = ecxt_callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deregister a shutdown callback in an ExprContext.
|
|
|
|
*
|
|
|
|
* Any list entries matching the function and arg will be removed.
|
|
|
|
* This can be used if it's no longer necessary to call the callback.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
UnregisterExprContextCallback(ExprContext *econtext,
|
|
|
|
ExprContextCallbackFunction function,
|
|
|
|
Datum arg)
|
|
|
|
{
|
|
|
|
ExprContext_CB **prev_callback;
|
|
|
|
ExprContext_CB *ecxt_callback;
|
|
|
|
|
|
|
|
prev_callback = &econtext->ecxt_callbacks;
|
|
|
|
|
|
|
|
while ((ecxt_callback = *prev_callback) != NULL)
|
|
|
|
{
|
|
|
|
if (ecxt_callback->function == function && ecxt_callback->arg == arg)
|
|
|
|
{
|
|
|
|
*prev_callback = ecxt_callback->next;
|
|
|
|
pfree(ecxt_callback);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_callback = &ecxt_callback->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call all the shutdown callbacks registered in an ExprContext.
|
|
|
|
*
|
|
|
|
* The callback list is emptied (important in case this is only a rescan
|
|
|
|
* reset, and not deletion of the ExprContext).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ShutdownExprContext(ExprContext *econtext)
|
|
|
|
{
|
|
|
|
ExprContext_CB *ecxt_callback;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call each callback function in reverse registration order.
|
|
|
|
*/
|
|
|
|
while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
|
|
|
|
{
|
|
|
|
econtext->ecxt_callbacks = ecxt_callback->next;
|
|
|
|
(*ecxt_callback->function) (ecxt_callback->arg);
|
|
|
|
pfree(ecxt_callback);
|
|
|
|
}
|
|
|
|
}
|