postgresql/src/backend/nodes/outfuncs.c

1697 lines
35 KiB
C
Raw Normal View History

/*
*
* outfuncs.c--
* routines to convert a node to ascii representation
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: outfuncs.c,v 1.55 1998/12/15 04:00:46 scrappy Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
* knows how to create its ascii representation. These functions are
* useful for debugging as well as for storing plans in the system
* catalogs (eg. indexes). This is also the plan string sent out in
* Mariposa.
*
* These functions update the in/out argument of type StringInfo
* passed to them. This argument contains the string holding the ASCII
* representation plus some other information (string length, etc.)
*
*/
#include <stdio.h>
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup.h"
#include "utils/syscache.h"
#include "utils/lsyscache.h"
#include "fmgr.h"
#include "utils/elog.h"
#include "utils/datum.h"
#include "utils/palloc.h"
#include "nodes/nodes.h"
#include "nodes/execnodes.h"
#include "nodes/pg_list.h"
#include "nodes/plannodes.h"
#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
#include "nodes/relation.h"
#include "catalog/pg_type.h"
#include "lib/stringinfo.h"
#ifdef PARSEDEBUG
#include "../parse.h"
#endif
static void _outDatum(StringInfo str, Datum value, Oid type);
static void _outNode(StringInfo str, void *obj);
/*
* _outIntList -
* converts a List of integers
*/
static void
_outIntList(StringInfo str, List *list)
{
List *l;
appendStringInfo(str, "(");
foreach(l, list)
{
appendStringInfo(str, " %d ", (int) lfirst(l));
}
appendStringInfo(str, ")");
}
static void
_outCreateStmt(StringInfo str, CreateStmt *node)
{
appendStringInfo(str, " CREATE :relname %s :columns ", node->relname);
_outNode(str, node->tableElts);
appendStringInfo(str, " :inhRelnames ");
_outNode(str, node->inhRelnames);
appendStringInfo(str, " :constraints ");
_outNode(str, node->constraints);
}
static void
_outIndexStmt(StringInfo str, IndexStmt *node)
{
appendStringInfo(str,
" INDEX :idxname %s :relname %s :accessMethod %s :indexParams ",
node->idxname, node->relname, node->accessMethod);
_outNode(str, node->indexParams);
appendStringInfo(str, " :withClause ");
_outNode(str, node->withClause);
appendStringInfo(str, " :whereClause ");
_outNode(str, node->whereClause);
appendStringInfo(str, " :rangetable ");
_outNode(str, node->rangetable);
appendStringInfo(str, " :lossy %s :unique %s ",
node->lossy ? "true" : "false",
node->unique ? "true" : "false");
}
#ifdef PARSEDEBUG
static void
_outSelectStmt(StringInfo str, SelectStmt *node)
{
appendStringInfo(str, "SELECT :where ");
_outNode(str, node->whereClause);
}
static void
_outFuncCall(StringInfo str, FuncCall *node)
{
appendStringInfo(str, "FUNCTION %s :args ", node->funcname);
_outNode(str, node->args);
}
#endif
static void
_outColumnDef(StringInfo str, ColumnDef *node)
{
appendStringInfo(str, " COLUMNDEF :colname %s :typename ", node->colname);
_outNode(str, node->typename);
appendStringInfo(str, " :is_not_null %s :defval %s :constraints ",
node->is_not_null ? "true" : "false", node->defval);
_outNode(str, node->constraints);
}
static void
_outTypeName(StringInfo str, TypeName *node)
{
appendStringInfo(str,
" TYPENAME :name %s :timezone %s :setof %s typmod %d :arrayBounds ",
node->name,
1998-12-15 03:32:57 +01:00
node->timezone ? "true" : "false",
node->setof ? "true" : "false",
1998-12-15 03:32:57 +01:00
node->typmod);
appendStringInfo(str, " :arrayBounds ");
_outNode(str, node->arrayBounds);
}
static void
_outIndexElem(StringInfo str, IndexElem *node)
{
appendStringInfo(str, " INDEXELEM :name %s :args ", node->name);
_outNode(str, node->args);
appendStringInfo(str, " :class %s :typename ", node->class);
1998-08-26 07:22:58 +02:00
_outNode(str, node->typename);
}
static void
_outQuery(StringInfo str, Query *node)
{
appendStringInfo(str, " QUERY :command %d ", node->commandType);
if (node->utilityStmt)
{
switch (nodeTag(node->utilityStmt))
{
case T_CreateStmt:
appendStringInfo(str, " :create %s ",
((CreateStmt *) (node->utilityStmt))->relname);
_outNode(str, node->utilityStmt);
break;
case T_IndexStmt:
appendStringInfo(str, " :index %s on %s ",
((IndexStmt *) (node->utilityStmt))->idxname,
((IndexStmt *) (node->utilityStmt))->relname);
_outNode(str, node->utilityStmt);
break;
case T_NotifyStmt:
appendStringInfo(str, " :utility %s ",
((NotifyStmt *) (node->utilityStmt))->relname);
break;
default:
appendStringInfo(str, " :utility ? ");
}
}
else
{
appendStringInfo(str, " :utility %s", NULL);
}
appendStringInfo(str,
" :resultRelation %d :into %s :isPortal %s :isBinary %s :unionall %s ",
node->resultRelation,
node->into,
node->isPortal ? "true" : "false",
node->isBinary ? "true" : "false",
node->unionall ? "true" : "false");
appendStringInfo(str, " :unique %s :sortClause ", node->uniqueFlag);
_outNode(str, node->sortClause);
appendStringInfo(str, " :rtable ");
_outNode(str, node->rtable);
appendStringInfo(str, " :targetlist ");
_outNode(str, node->targetList);
appendStringInfo(str, " :qual ");
_outNode(str, node->qual);
appendStringInfo(str, " :groupClause ");
_outNode(str, node->groupClause);
appendStringInfo(str, " :havingQual ");
_outNode(str, node->havingQual);
appendStringInfo(str, " :hasAggs %s :hasSubLinks %s :unionClause ",
node->hasAggs ? "true" : "false",
node->hasSubLinks ? "true" : "false");
_outNode(str, node->unionClause);
1998-10-22 15:52:24 +02:00
appendStringInfo(str, " :limitOffset ");
_outNode(str, node->limitOffset);
1998-10-22 15:52:24 +02:00
appendStringInfo(str, " :limitCount ");
_outNode(str, node->limitCount);
}
static void
_outSortClause(StringInfo str, SortClause *node)
{
appendStringInfo(str, " SORTCLAUSE :resdom ");
_outNode(str, node->resdom);
appendStringInfo(str, " :opoid %u ", node->opoid);
}
static void
_outGroupClause(StringInfo str, GroupClause *node)
{
appendStringInfo(str, " GROUPCLAUSE :entry ");
_outNode(str, node->entry);
appendStringInfo(str, " :grpOpoid %u ", node->grpOpoid);
}
/*
* print the basic stuff of all nodes that inherit from Plan
*/
static void
_outPlanInfo(StringInfo str, Plan *node)
{
appendStringInfo(str,
":cost %g :size %d :width %d :state %s :qptargetlist ",
node->cost,
node->plan_size,
node->plan_width,
node->state ? "not-NULL" : "<>");
_outNode(str, node->targetlist);
appendStringInfo(str, " :qpqual ");
_outNode(str, node->qual);
appendStringInfo(str, " :lefttree ");
_outNode(str, node->lefttree);
appendStringInfo(str, " :righttree ");
_outNode(str, node->righttree);
appendStringInfo(str, " :extprm ");
_outIntList(str, node->extParam);
appendStringInfo(str, " :locprm ");
_outIntList(str, node->locParam);
appendStringInfo(str, " :initplan ");
_outNode(str, node->initPlan);
1998-12-15 03:32:57 +01:00
appendStringInfo(str, " :nprm %d ", node->nParamExec);
}
/*
* Stuff from plannodes.h
*/
static void
_outPlan(StringInfo str, Plan *node)
{
appendStringInfo(str, " PLAN ");
_outPlanInfo(str, (Plan *) node);
}
static void
_outResult(StringInfo str, Result *node)
{
appendStringInfo(str, " RESULT ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :resconstantqual ");
_outNode(str, node->resconstantqual);
}
/*
* Append is a subclass of Plan.
*/
static void
1997-09-08 22:59:27 +02:00
_outAppend(StringInfo str, Append *node)
{
appendStringInfo(str, " APPEND ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :appendplans ");
_outNode(str, node->appendplans);
appendStringInfo(str, " :unionrtables ");
_outNode(str, node->unionrtables);
appendStringInfo(str,
" :inheritrelid %d :inheritrtable ",
node->inheritrelid);
_outNode(str, node->inheritrtable);
}
/*
* Join is a subclass of Plan
*/
static void
_outJoin(StringInfo str, Join *node)
{
appendStringInfo(str, " JOIN ");
_outPlanInfo(str, (Plan *) node);
}
/*
* NestLoop is a subclass of Join
*/
static void
_outNestLoop(StringInfo str, NestLoop *node)
{
appendStringInfo(str, " NESTLOOP ");
_outPlanInfo(str, (Plan *) node);
}
/*
* MergeJoin is a subclass of Join
*/
static void
_outMergeJoin(StringInfo str, MergeJoin *node)
{
appendStringInfo(str, " MERGEJOIN ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :mergeclauses ");
_outNode(str, node->mergeclauses);
appendStringInfo(str,
" :mergejoinop %u :mergerightorder %u :mergeleftorder %u ",
node->mergejoinop,
node->mergerightorder,
node->mergeleftorder);
}
/*
* HashJoin is a subclass of Join.
*/
static void
_outHashJoin(StringInfo str, HashJoin *node)
{
appendStringInfo(str, " HASHJOIN ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :hashclauses ");
_outNode(str, node->hashclauses);
appendStringInfo(str,
" :hashjoinop %u :hashjointable 0x%x :hashjointablekey %d ",
node->hashjoinop,
(int) node->hashjointable,
node->hashjointablekey);
appendStringInfo(str,
" :hashjointablesize %d :hashdone %d ",
node->hashjointablesize,
node->hashdone);
}
static void
_outSubPlan(StringInfo str, SubPlan *node)
{
appendStringInfo(str, " SUBPLAN :plan ");
_outNode(str, node->plan);
appendStringInfo(str, " :planid %u :rtable ", node->plan_id);
_outNode(str, node->rtable);
appendStringInfo(str, " :setprm ");
_outIntList(str, node->setParam);
appendStringInfo(str, " :parprm ");
_outIntList(str, node->parParam);
appendStringInfo(str, " :slink ");
_outNode(str, node->sublink);
}
/*
* Scan is a subclass of Node
*/
static void
_outScan(StringInfo str, Scan *node)
{
appendStringInfo(str, " SCAN ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :scanrelid %d ", node->scanrelid);
}
/*
* SeqScan is a subclass of Scan
*/
static void
_outSeqScan(StringInfo str, SeqScan *node)
{
appendStringInfo(str, " SEQSCAN ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :scanrelid %d ", node->scanrelid);
}
/*
* IndexScan is a subclass of Scan
*/
static void
_outIndexScan(StringInfo str, IndexScan *node)
{
appendStringInfo(str, " INDEXSCAN ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :scanrelid %d :indxid ", node->scan.scanrelid);
_outIntList(str, node->indxid);
appendStringInfo(str, " :indxqual ");
_outNode(str, node->indxqual);
appendStringInfo(str, " :indxqualorig ");
_outNode(str, node->indxqualorig);
}
/*
* Temp is a subclass of Plan
*/
static void
_outTemp(StringInfo str, Temp *node)
{
appendStringInfo(str, " TEMP ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :tempid %u :keycount %d ",
node->tempid,
node->keycount);
}
/*
* Sort is a subclass of Temp
*/
static void
_outSort(StringInfo str, Sort *node)
{
appendStringInfo(str, " SORT ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :tempid %u :keycount %d ",
node->tempid,
node->keycount);
}
static void
1997-09-08 22:59:27 +02:00
_outAgg(StringInfo str, Agg *node)
{
appendStringInfo(str, " AGG ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :aggs ");
_outNode(str, node->aggs);
}
static void
_outGroup(StringInfo str, Group *node)
{
appendStringInfo(str, " GRP ");
_outPlanInfo(str, (Plan *) node);
/* the actual Group fields */
1998-12-15 03:32:57 +01:00
appendStringInfo(str, " :numCols %d :tuplePerGroup %s ",
node->numCols,
node->tuplePerGroup ? "true" : "false");
}
/*
* For some reason, unique is a subclass of Temp.
*/
static void
_outUnique(StringInfo str, Unique *node)
{
appendStringInfo(str, " UNIQUE ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :tempid %u :keycount %d ",
node->tempid,
node->keycount);
}
/*
* Hash is a subclass of Temp
*/
static void
_outHash(StringInfo str, Hash *node)
{
appendStringInfo(str, " HASH ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :hashkey ");
_outNode(str, node->hashkey);
appendStringInfo(str, " :hashtable 0x%x :hashtablekey %d :hashtablesize %d ",
(int) node->hashtable,
node->hashtablekey,
node->hashtablesize);
}
static void
_outTee(StringInfo str, Tee *node)
{
appendStringInfo(str, " TEE ");
_outPlanInfo(str, (Plan *) node);
appendStringInfo(str, " :leftParent %X :rightParent %X ",
(int) node->leftParent,
(int) node->rightParent);
appendStringInfo(str, " :rtentries ");
_outNode(str, node->rtentries);
}
/*****************************************************************************
*
* Stuff from primnodes.h.
*
*****************************************************************************/
/*
* Resdom is a subclass of Node
*/
static void
_outResdom(StringInfo str, Resdom *node)
{
appendStringInfo(str, " RESDOM :resno %d :restype %u :restypmod %d ",
node->resno,
node->restype,
node->restypmod);
appendStringInfo(str, " :resname \"%s\" :reskey %d :reskeyop %u :resjunk %d",
node->resname,
node->reskey,
node->reskeyop,
node->resjunk);
}
static void
_outFjoin(StringInfo str, Fjoin *node)
{
int i;
appendStringInfo(str, " FJOIN :initialized %s :nNodes %d ",
node->fj_initialized ? "true" : "false",
node->fj_nNodes);
appendStringInfo(str, " :innerNode ");
_outNode(str, node->fj_innerNode);
appendStringInfo(str, " :results @ 0x%x :alwaysdone",
(int) node->fj_results);
for (i = 0; i < node->fj_nNodes; i++)
appendStringInfo(str, (node->fj_alwaysDone[i]) ? "true" : "false");
}
/*
* Expr is a subclass of Node
*/
static void
_outExpr(StringInfo str, Expr *node)
{
char *opstr = NULL;
appendStringInfo(str, " EXPR :typeOid %u ",
node->typeOid);
switch (node->opType)
{
case OP_EXPR:
opstr = "op";
break;
case FUNC_EXPR:
opstr = "func";
break;
case OR_EXPR:
opstr = "or";
break;
case AND_EXPR:
opstr = "and";
break;
case NOT_EXPR:
opstr = "not";
break;
case SUBPLAN_EXPR:
opstr = "subp";
break;
}
appendStringInfo(str, " :opType %s :oper ", opstr);
_outNode(str, node->oper);
appendStringInfo(str, " :args ");
_outNode(str, node->args);
}
/*
* Var is a subclass of Expr
*/
static void
_outVar(StringInfo str, Var *node)
{
appendStringInfo(str,
" VAR :varno %d :varattno %d :vartype %u %vartypmod %d ",
node->varno,
node->varattno,
node->vartype,
node->vartypmod);
appendStringInfo(str, " :varlevelsup %u :varnoold %d :varoattno %d" ,
node->varlevelsup,
node->varnoold,
node->varoattno);
}
/*
* Const is a subclass of Expr
*/
static void
_outConst(StringInfo str, Const *node)
{
appendStringInfo(str,
" CONST :consttype %u :constlen %d :constisnull %s :constvalue ",
node->consttype,
node->constlen,
node->constisnull ? "true" : "false");
if (node->constisnull)
1998-01-07 16:32:47 +01:00
appendStringInfo(str, "<>");
else
_outDatum(str, node->constvalue, node->consttype);
appendStringInfo(str, " :constbyval %s ",
node->constbyval ? "true" : "false");
}
/*
* Aggreg
*/
static void
1997-09-08 22:59:27 +02:00
_outAggreg(StringInfo str, Aggreg *node)
{
appendStringInfo(str,
" AGGREG :aggname %s :basetype %u :aggtype %u :target ",
node->aggname,
node->basetype,
node->aggtype);
_outNode(str, node->target);
appendStringInfo(str, ":aggno %d :usenulls %s",
node->aggno,
node->usenulls ? "true" : "false");
}
/*
* SubLink
*/
static void
_outSubLink(StringInfo str, SubLink *node)
{
appendStringInfo(str,
" SUBLINK :subLinkType %d :useor %s :lefthand ",
node->subLinkType,
node->useor ? "true" : "false");
_outNode(str, node->lefthand);
appendStringInfo(str, " :oper ");
1998-01-20 06:05:08 +01:00
_outNode(str, node->oper);
appendStringInfo(str, " :subselect ");
_outNode(str, node->subselect);
}
/*
* Array is a subclass of Expr
*/
static void
1997-09-08 22:59:27 +02:00
_outArray(StringInfo str, Array *node)
{
int i;
appendStringInfo(str,
" ARRAY :arrayelemtype %u :arrayelemlength %d :arrayelembyval %c ",
node->arrayelemtype,
node->arrayelemlength,
node->arrayelembyval ? 't' : 'f');
appendStringInfo(str, " :arrayndim %d ", node->arrayndim);
appendStringInfo(str, " :arraylow ");
for (i = 0; i < node->arrayndim; i++)
{
appendStringInfo(str, " %d ", node->arraylow.indx[i]);
}
appendStringInfo(str, " :arrayhigh ");
for (i = 0; i < node->arrayndim; i++)
{
appendStringInfo(str, " %d ", node->arrayhigh.indx[i]);
}
appendStringInfo(str, " :arraylen %d ", node->arraylen);
}
/*
* ArrayRef is a subclass of Expr
*/
static void
1997-09-08 22:59:27 +02:00
_outArrayRef(StringInfo str, ArrayRef *node)
{
appendStringInfo(str,
" ARRAYREF :refelemtype %u :refattrlength $d :refelemlength %d ",
node->refelemtype,
node->refattrlength,
node->refelemlength);
appendStringInfo(str, " :refelembyval %c :refupperindex ",
node->refelembyval ? 't' : 'f');
_outNode(str, node->refupperindexpr);
appendStringInfo(str, " :reflowerindex ");
_outNode(str, node->reflowerindexpr);
appendStringInfo(str, " :refexpr ");
_outNode(str, node->refexpr);
appendStringInfo(str, " :refassgnexpr ");
_outNode(str, node->refassgnexpr);
}
/*
* Func is a subclass of Expr
*/
static void
_outFunc(StringInfo str, Func *node)
{
appendStringInfo(str,
" FUNC :funcid %u :functype %u :funcisindex %s :funcsize %d ",
node->funcid,
node->functype,
node->funcisindex ? "true" : "false",
node->funcsize);
appendStringInfo(str, " :func_fcache @ 0x%x :func_tlist ",
(int) node->func_fcache);
_outNode(str, node->func_tlist);
appendStringInfo(str, " :func_planlist ");
_outNode(str, node->func_planlist);
}
/*
* Oper is a subclass of Expr
*/
static void
_outOper(StringInfo str, Oper *node)
{
appendStringInfo(str,
" OPER :opno %u :opid %u :opresulttype %u ",
node->opno,
node->opid,
node->opresulttype);
}
/*
* Param is a subclass of Expr
*/
static void
_outParam(StringInfo str, Param *node)
{
appendStringInfo(str,
" PARAM :paramkind %d :paramid %d :paramname %s :paramtype %u ",
node->paramkind,
node->paramid,
node->paramname,
node->paramtype);
appendStringInfo(str, " :param_tlist ");
_outNode(str, node->param_tlist);
}
/*
* Stuff from execnodes.h
*/
/*
* EState is a subclass of Node.
*/
static void
_outEState(StringInfo str, EState *node)
{
appendStringInfo(str,
" ESTATE :direction %d :range_table ",
node->es_direction);
_outNode(str, node->es_range_table);
appendStringInfo(str, " :result_relation_info @ 0x%x ",
(int) (node->es_result_relation_info));
}
/*
* Stuff from relation.h
*/
static void
_outRelOptInfo(StringInfo str, RelOptInfo * node)
{
appendStringInfo(str, " RELOPTINFO :relids ");
_outIntList(str, node->relids);
appendStringInfo(str,
" :indexed %s :pages %u :tuples %u :size %u :width %u :targetlist ",
node->indexed ? "true" : "false",
node->pages,
node->tuples,
node->size,
node->width);
_outNode(str, node->targetlist);
appendStringInfo(str, " :pathlist ");
_outNode(str, node->pathlist);
/*
* Not sure if these are nodes or not. They're declared as struct
* Path *. Since i don't know, i'll just print the addresses for now.
* This can be changed later, if necessary.
*/
appendStringInfo(str,
" :unorderedpath @ 0x%x :cheapestpath @ 0x%x :pruneable %s :clauseinfo ",
(int) node->unorderedpath,
(int) node->cheapestpath,
node->pruneable ? "true" : "false");
_outNode(str, node->clauseinfo);
appendStringInfo(str, " :joininfo ");
_outNode(str, node->joininfo);
appendStringInfo(str, " :innerjoin ");
_outNode(str, node->innerjoin);
}
/*
* TargetEntry is a subclass of Node.
*/
static void
_outTargetEntry(StringInfo str, TargetEntry *node)
{
appendStringInfo(str, " TARGETENTRY :resdom ");
_outNode(str, node->resdom);
appendStringInfo(str, " :expr ");
_outNode(str, node->expr);
}
static void
_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
{
appendStringInfo(str,
" RTE :relname %s :refname %s :relid %u :inh %s :inFromCl %s :skipAcl %s",
node->relname,
node->refname,
node->relid,
node->inh ? "true" : "false",
node->inFromCl ? "true" : "false",
node->skipAcl ? "true" : "false");
}
/*
* Path is a subclass of Node.
*/
static void
_outPath(StringInfo str, Path *node)
{
appendStringInfo(str, " PATH :pathtype %d :cost %f :keys ",
node->pathtype,
node->path_cost);
_outNode(str, node->keys);
}
/*
* IndexPath is a subclass of Path.
*/
static void
_outIndexPath(StringInfo str, IndexPath *node)
{
appendStringInfo(str,
" INDEXPATH :pathtype %d :cost %f :keys ",
node->path.pathtype,
node->path.path_cost);
_outNode(str, node->path.keys);
appendStringInfo(str, " :indexid ");
_outIntList(str, node->indexid);
appendStringInfo(str, " :indexqual ");
_outNode(str, node->indexqual);
}
/*
* JoinPath is a subclass of Path
*/
static void
_outJoinPath(StringInfo str, JoinPath *node)
{
appendStringInfo(str,
" JOINPATH :pathtype %d :cost %f :keys ",
node->path.pathtype,
node->path.path_cost);
_outNode(str, node->path.keys);
appendStringInfo(str, " :pathclauseinfo ");
_outNode(str, node->pathclauseinfo);
/*
* Not sure if these are nodes; they're declared as "struct path *".
* For now, i'll just print the addresses.
*/
appendStringInfo(str,
" :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x :outjoincost %f :joinid ",
(int) node->outerjoinpath,
(int) node->innerjoinpath,
node->path.outerjoincost);
_outIntList(str, node->path.joinid);
}
/*
* MergePath is a subclass of JoinPath.
*/
static void
_outMergePath(StringInfo str, MergePath *node)
{
appendStringInfo(str,
" MERGEPATH :pathtype %d :cost %f :keys ",
node->jpath.path.pathtype,
node->jpath.path.path_cost);
_outNode(str, node->jpath.path.keys);
appendStringInfo(str, " :pathclauseinfo ");
_outNode(str, node->jpath.pathclauseinfo);
/*
* Not sure if these are nodes; they're declared as "struct path *".
* For now, i'll just print the addresses.
*/
appendStringInfo(str,
" :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x :outerjoincost %f :joinid ",
(int) node->jpath.outerjoinpath,
(int) node->jpath.innerjoinpath,
(int) node->jpath.path.outerjoincost);
_outIntList(str, node->jpath.path.joinid);
appendStringInfo(str, " :path_mergeclauses ");
_outNode(str, node->path_mergeclauses);
appendStringInfo(str, " :outersortkeys ");
_outNode(str, node->outersortkeys);
appendStringInfo(str, " :innersortkeys ");
_outNode(str, node->innersortkeys);
}
/*
* HashPath is a subclass of JoinPath.
*/
static void
_outHashPath(StringInfo str, HashPath *node)
{
appendStringInfo(str,
" HASHPATH :pathtype %d :cost %f :keys ",
node->jpath.path.pathtype,
node->jpath.path.path_cost);
_outNode(str, node->jpath.path.keys);
appendStringInfo(str, " :pathclauseinfo ");
_outNode(str, node->jpath.pathclauseinfo);
/*
* Not sure if these are nodes; they're declared as "struct path *".
* For now, i'll just print the addresses.
*/
appendStringInfo(str,
" :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x :outerjoincost %f :joinid ",
(int) node->jpath.outerjoinpath,
(int) node->jpath.innerjoinpath,
node->jpath.path.outerjoincost);
_outIntList(str, node->jpath.path.joinid);
appendStringInfo(str, " :path_hashclauses ");
_outNode(str, node->path_hashclauses);
appendStringInfo(str, " :outerhashkeys ");
_outNode(str, node->outerhashkeys);
appendStringInfo(str, " :innerhashkeys ");
_outNode(str, node->innerhashkeys);
}
/*
* OrderKey is a subclass of Node.
*/
static void
_outOrderKey(StringInfo str, OrderKey *node)
{
appendStringInfo(str,
" ORDERKEY :attribute_number %d :array_index %d ",
node->attribute_number,
node->array_index);
}
/*
* JoinKey is a subclass of Node.
*/
static void
_outJoinKey(StringInfo str, JoinKey *node)
{
appendStringInfo(str, " JOINKEY ");
appendStringInfo(str, " :outer ");
_outNode(str, node->outer);
appendStringInfo(str, " :inner ");
_outNode(str, node->inner);
}
/*
* MergeOrder is a subclass of Node.
*/
static void
_outMergeOrder(StringInfo str, MergeOrder *node)
{
char buf[500];
appendStringInfo(str, " MERGEORDER ");
1998-01-07 06:42:47 +01:00
sprintf(buf, " :join_operator %d ", node->join_operator);
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :left_operator %d ", node->left_operator);
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :right_operator %d ", node->right_operator);
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :left_type %d ", node->left_type);
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :right_type %d ", node->right_type);
appendStringInfo(str, buf);
}
/*
1998-09-01 05:29:17 +02:00
* ClauseInfo is a subclass of Node.
*/
static void
_outClauseInfo(StringInfo str, ClauseInfo * node)
{
char buf[500];
appendStringInfo(str, " CINFO ");
appendStringInfo(str, " :clause ");
_outNode(str, node->clause);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :selectivity %f ", node->selectivity);
appendStringInfo(str, buf);
appendStringInfo(str, " :notclause ");
appendStringInfo(str, node->notclause ? "true" : "false");
appendStringInfo(str, " :indexids ");
_outNode(str, node->indexids);
appendStringInfo(str, " :mergejoinorder ");
_outNode(str, node->mergejoinorder);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :hashjoinoperator %u ", node->hashjoinoperator);
appendStringInfo(str, buf);
}
/*
* JoinMethod is a subclass of Node.
*/
static void
_outJoinMethod(StringInfo str, JoinMethod *node)
{
appendStringInfo(str, " JOINMETHOD ");
appendStringInfo(str, " :jmkeys ");
_outNode(str, node->jmkeys);
appendStringInfo(str, " :clauses ");
_outNode(str, node->clauses);
}
/*
* HInfo is a subclass of JoinMethod.
*/
static void
_outHInfo(StringInfo str, HInfo *node)
{
char buf[500];
appendStringInfo(str, " HASHINFO ");
appendStringInfo(str, " :hashop ");
1998-01-07 06:42:47 +01:00
sprintf(buf, " %u ", node->hashop);
appendStringInfo(str, buf);
appendStringInfo(str, " :jmkeys ");
_outNode(str, node->jmethod.jmkeys);
appendStringInfo(str, " :clauses ");
_outNode(str, node->jmethod.clauses);
}
/*
1998-09-01 05:29:17 +02:00
* JoinInfo is a subclass of Node.
*/
static void
_outJoinInfo(StringInfo str, JoinInfo * node)
{
appendStringInfo(str, " JINFO ");
appendStringInfo(str, " :otherrels ");
_outIntList(str, node->otherrels);
appendStringInfo(str, " :jinfoclauseinfo ");
_outNode(str, node->jinfoclauseinfo);
appendStringInfo(str, " :mergejoinable ");
appendStringInfo(str, node->mergejoinable ? "true" : "false");
appendStringInfo(str, " :hashjoinable ");
appendStringInfo(str, node->hashjoinable ? "true" : "false");
}
/*
* Print the value of a Datum given its type.
*/
static void
_outDatum(StringInfo str, Datum value, Oid type)
{
char buf[500];
Size length,
typeLength;
bool byValue;
int i;
char *s;
/*
* find some information about the type and the "real" length of the
* datum.
*/
byValue = get_typbyval(type);
typeLength = get_typlen(type);
length = datumGetSize(value, type, byValue, typeLength);
if (byValue)
{
s = (char *) (&value);
sprintf(buf, " %d [ ", length);
appendStringInfo(str, buf);
for (i = 0; i < sizeof(Datum); i++)
{
1998-01-07 06:42:47 +01:00
sprintf(buf, " %d ", (int) (s[i]));
appendStringInfo(str, buf);
}
sprintf(buf, "] ");
appendStringInfo(str, buf);
}
else
{ /* !byValue */
s = (char *) DatumGetPointer(value);
if (!PointerIsValid(s))
{
sprintf(buf, " 0 [ ] ");
appendStringInfo(str, buf);
}
else
{
/*
* length is unsigned - very bad to do < comparison to -1
* without casting it to int first!! -mer 8 Jan 1991
*/
if (((int) length) <= -1)
length = VARSIZE(s);
sprintf(buf, " %d [ ", length);
appendStringInfo(str, buf);
for (i = 0; i < length; i++)
{
1998-01-07 06:42:47 +01:00
sprintf(buf, " %d ", (int) (s[i]));
appendStringInfo(str, buf);
}
sprintf(buf, "] ");
appendStringInfo(str, buf);
}
}
}
static void
_outIter(StringInfo str, Iter *node)
{
appendStringInfo(str, " ITER ");
appendStringInfo(str, " :iterexpr ");
_outNode(str, node->iterexpr);
}
static void
_outStream(StringInfo str, Stream *node)
{
char buf[500];
appendStringInfo(str, " STREAM ");
1998-01-07 06:42:47 +01:00
sprintf(buf, " :pathptr @ 0x%x ", (int) (node->pathptr));
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :cinfo @ 0x%x ", (int) (node->cinfo));
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :clausetype %d ", (int) (node->clausetype));
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :upstream @ 0x%x ", (int) (node->upstream));
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :downstream @ 0x%x ", (int) (node->downstream));
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :groupup %d ", node->groupup);
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :groupcost %f ", node->groupcost);
appendStringInfo(str, buf);
1998-01-07 06:42:47 +01:00
sprintf(buf, " :groupsel %f ", node->groupsel);
appendStringInfo(str, buf);
}
static void
_outAExpr(StringInfo str, A_Expr *node)
{
appendStringInfo(str, "EXPR ");
#ifdef PARSEDEBUG
switch (node->oper)
{
case AND:
appendStringInfo(str, "AND");
break;
case OR:
appendStringInfo(str, "OR");
break;
case NOT:
appendStringInfo(str, "NOT");
break;
case ISNULL:
appendStringInfo(str, "ISNULL");
break;
case NOTNULL:
appendStringInfo(str, "NOTNULL");
break;
default:
#endif
appendStringInfo(str, node->opname);
#ifdef PARSEDEBUG
break;
}
#endif
_outNode(str, node->lexpr);
_outNode(str, node->rexpr);
return;
}
static void
_outValue(StringInfo str, Value *value)
{
char buf[500];
switch (value->type)
{
case T_String:
1998-01-07 06:42:47 +01:00
sprintf(buf, " \"%s\" ", value->val.str);
appendStringInfo(str, buf);
break;
case T_Integer:
1998-01-07 06:42:47 +01:00
sprintf(buf, " %ld ", value->val.ival);
appendStringInfo(str, buf);
break;
case T_Float:
1998-01-07 06:42:47 +01:00
sprintf(buf, " %f ", value->val.dval);
appendStringInfo(str, buf);
break;
default:
break;
}
return;
}
static void
_outIdent(StringInfo str, Ident *node)
{
char buf[500];
1998-01-07 06:42:47 +01:00
sprintf(buf, " IDENT \"%s\" ", node->name);
appendStringInfo(str, buf);
return;
}
static void
_outAConst(StringInfo str, A_Const *node)
{
char buf[500];
sprintf(buf, "CONST ");
appendStringInfo(str, buf);
_outValue(str, &(node->val));
return;
}
1998-12-04 16:34:49 +01:00
static void
_outConstraint(StringInfo str, Constraint *node)
{
char buf[500];
sprintf(buf," %s :type",
((node->name != NULL)? node->name: "<>"));
appendStringInfo(str, buf);
switch (node->contype)
{
case CONSTR_PRIMARY:
sprintf(buf," PRIMARY KEY ");
appendStringInfo(str, buf);
_outNode(str, node->keys);
break;
case CONSTR_CHECK:
sprintf(buf," CHECK ");
appendStringInfo(str, buf);
appendStringInfo(str, node->def);
break;
case CONSTR_DEFAULT:
sprintf(buf," DEFAULT ");
appendStringInfo(str, buf);
appendStringInfo(str, node->def);
break;
case CONSTR_NOTNULL:
sprintf(buf," NOT NULL ");
appendStringInfo(str, buf);
break;
case CONSTR_UNIQUE:
sprintf(buf," UNIQUE ");
appendStringInfo(str, buf);
_outNode(str, node->keys);
break;
default:
sprintf(buf,"<unrecognized constraint>");
appendStringInfo(str, buf);
break;
}
return;
}
static void
_outCaseExpr(StringInfo str, CaseExpr *node)
{
char buf[500];
sprintf(buf, "CASE ");
appendStringInfo(str, buf);
_outNode(str, node->args);
sprintf(buf, " :default ");
appendStringInfo(str, buf);
_outNode(str, node->defresult);
return;
}
static void
_outCaseWhen(StringInfo str, CaseWhen *node)
{
char buf[500];
sprintf(buf, " WHEN ");
1998-12-04 16:34:49 +01:00
appendStringInfo(str, buf);
_outNode(str, node->expr);
sprintf(buf, " :then ");
appendStringInfo(str, buf);
_outNode(str, node->result);
return;
}
/*
* _outNode -
* converts a Node into ascii string and append it to 'str'
*/
static void
_outNode(StringInfo str, void *obj)
{
if (obj == NULL)
{
1998-01-07 16:32:47 +01:00
appendStringInfo(str, "<>");
return;
}
if (nodeTag(obj) == T_List)
{
List *l;
appendStringInfo(str, "(");
foreach(l, (List *) obj)
{
_outNode(str, lfirst(l));
if (lnext(l))
appendStringInfo(str, " ");
}
appendStringInfo(str, ")");
}
else
{
appendStringInfo(str, "{");
switch (nodeTag(obj))
{
case T_CreateStmt:
_outCreateStmt(str, obj);
break;
case T_IndexStmt:
_outIndexStmt(str, obj);
break;
case T_ColumnDef:
_outColumnDef(str, obj);
break;
case T_TypeName:
_outTypeName(str, obj);
break;
case T_IndexElem:
_outIndexElem(str, obj);
break;
#ifdef PARSEDEBUG
case T_VariableSetStmt:
break;
case T_SelectStmt:
_outSelectStmt(str, obj);
break;
case T_FuncCall:
_outFuncCall(str, obj);
break;
#endif
case T_Query:
_outQuery(str, obj);
break;
case T_SortClause:
_outSortClause(str, obj);
break;
case T_GroupClause:
_outGroupClause(str, obj);
break;
case T_Plan:
_outPlan(str, obj);
break;
case T_Result:
_outResult(str, obj);
break;
case T_Append:
_outAppend(str, obj);
break;
case T_Join:
_outJoin(str, obj);
break;
case T_NestLoop:
_outNestLoop(str, obj);
break;
case T_MergeJoin:
_outMergeJoin(str, obj);
break;
case T_HashJoin:
_outHashJoin(str, obj);
break;
case T_Scan:
_outScan(str, obj);
break;
case T_SeqScan:
_outSeqScan(str, obj);
break;
case T_IndexScan:
_outIndexScan(str, obj);
break;
case T_Temp:
_outTemp(str, obj);
break;
case T_Sort:
_outSort(str, obj);
break;
case T_Agg:
_outAgg(str, obj);
break;
case T_Group:
_outGroup(str, obj);
break;
case T_Unique:
_outUnique(str, obj);
break;
case T_Hash:
_outHash(str, obj);
break;
case T_SubPlan:
_outSubPlan(str, obj);
break;
case T_Tee:
_outTee(str, obj);
break;
case T_Resdom:
_outResdom(str, obj);
break;
case T_Fjoin:
_outFjoin(str, obj);
break;
case T_Expr:
_outExpr(str, obj);
break;
case T_Var:
_outVar(str, obj);
break;
case T_Const:
_outConst(str, obj);
break;
case T_Aggreg:
_outAggreg(str, obj);
break;
case T_SubLink:
_outSubLink(str, obj);
break;
case T_Array:
_outArray(str, obj);
break;
case T_ArrayRef:
_outArrayRef(str, obj);
break;
case T_Func:
_outFunc(str, obj);
break;
case T_Oper:
_outOper(str, obj);
break;
case T_Param:
_outParam(str, obj);
break;
case T_EState:
_outEState(str, obj);
break;
1998-07-18 06:22:52 +02:00
case T_RelOptInfo:
1998-08-02 00:12:13 +02:00
_outRelOptInfo(str, obj);
break;
case T_TargetEntry:
_outTargetEntry(str, obj);
break;
case T_RangeTblEntry:
_outRangeTblEntry(str, obj);
break;
case T_Path:
_outPath(str, obj);
break;
case T_IndexPath:
_outIndexPath(str, obj);
break;
case T_JoinPath:
_outJoinPath(str, obj);
break;
case T_MergePath:
_outMergePath(str, obj);
break;
case T_HashPath:
_outHashPath(str, obj);
break;
case T_OrderKey:
_outOrderKey(str, obj);
break;
case T_JoinKey:
_outJoinKey(str, obj);
break;
case T_MergeOrder:
_outMergeOrder(str, obj);
break;
1998-09-01 05:29:17 +02:00
case T_ClauseInfo:
_outClauseInfo(str, obj);
break;
case T_JoinMethod:
_outJoinMethod(str, obj);
break;
case T_HInfo:
_outHInfo(str, obj);
break;
1998-09-01 05:29:17 +02:00
case T_JoinInfo:
_outJoinInfo(str, obj);
break;
case T_Iter:
_outIter(str, obj);
break;
case T_Stream:
_outStream(str, obj);
break;
case T_Integer:
case T_String:
case T_Float:
_outValue(str, obj);
break;
case T_A_Expr:
_outAExpr(str, obj);
break;
case T_Ident:
_outIdent(str, obj);
break;
case T_A_Const:
_outAConst(str, obj);
break;
1998-12-04 16:34:49 +01:00
case T_Constraint:
_outConstraint(str, obj);
break;
case T_CaseExpr:
_outCaseExpr(str, obj);
break;
case T_CaseWhen:
_outCaseWhen(str, obj);
break;
default:
1998-01-07 06:42:47 +01:00
elog(NOTICE, "_outNode: don't know how to print type %d ",
nodeTag(obj));
break;
}
appendStringInfo(str, "}");
}
return;
}
/*
* nodeToString -
* returns the ascii representation of the Node
*/
char *
nodeToString(void *obj)
{
StringInfo str;
char *s;
if (obj == NULL)
return "";
Assert(obj != NULL);
str = makeStringInfo();
_outNode(str, obj);
s = str->data;
pfree(str);
return s;
}