PostgreSQL/src/backend/nodes/makefuncs.c
Tom Lane db436adf76 Major revision of sort-node handling: push knowledge of query
sort order down into planner, instead of handling it only at the very top
level of the planner.  This fixes many things.  An explicit sort is now
avoided if there is a cheaper alternative (typically an indexscan) not
only for ORDER BY, but also for the internal sort of GROUP BY.  It works
even when there is no other reason (such as a WHERE condition) to consider
the indexscan.  It works for indexes on functions.  It works for indexes
on functions, backwards.  It's just so cool...

CAUTION: I have changed the representation of SortClause nodes, therefore
THIS UPDATE BREAKS STORED RULES.  You will need to initdb.
1999-08-21 03:49:17 +00:00

139 lines
2.7 KiB
C

/*
* makefuncs.c
* creator functions for primitive nodes. The functions here are for
* the most frequently created nodes.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.17 1999/08/21 03:48:58 tgl Exp $
*
* NOTES
* Creator functions in POSTGRES 4.2 are generated automatically. Most of
* them are rarely used. Now we don't generate them any more. If you want
* one, you have to write it yourself.
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
* Andrew Yu Oct 20, 1994 file creation
*/
#include "postgres.h"
#include "nodes/makefuncs.h"
/*
* makeOper -
* creates an Oper node
*/
Oper *
makeOper(Oid opno,
Oid opid,
Oid opresulttype,
int opsize,
FunctionCachePtr op_fcache)
{
Oper *oper = makeNode(Oper);
oper->opno = opno;
oper->opid = opid;
oper->opresulttype = opresulttype;
oper->opsize = opsize;
oper->op_fcache = op_fcache;
return oper;
}
/*
* makeVar -
* creates a Var node
*
*/
Var *
makeVar(Index varno,
AttrNumber varattno,
Oid vartype,
int32 vartypmod,
Index varlevelsup,
Index varnoold,
AttrNumber varoattno)
{
Var *var = makeNode(Var);
var->varno = varno;
var->varattno = varattno;
var->vartype = vartype;
var->vartypmod = vartypmod;
var->varlevelsup = varlevelsup;
var->varnoold = varnoold;
var->varoattno = varoattno;
return var;
}
/*
* makeTargetEntry -
* creates a TargetEntry node(contains a Resdom)
*/
TargetEntry *
makeTargetEntry(Resdom *resdom, Node *expr)
{
TargetEntry *rt = makeNode(TargetEntry);
rt->resdom = resdom;
rt->expr = expr;
return rt;
}
/*
* makeResdom -
* creates a Resdom (Result Domain) node
*/
Resdom *
makeResdom(AttrNumber resno,
Oid restype,
int32 restypmod,
char *resname,
Index reskey,
Oid reskeyop,
bool resjunk)
{
Resdom *resdom = makeNode(Resdom);
resdom->resno = resno;
resdom->restype = restype;
resdom->restypmod = restypmod;
resdom->resname = resname;
/* For historical reasons, ressortgroupref defaults to 0 while
* reskey/reskeyop are passed in explicitly. This is pretty silly.
*/
resdom->ressortgroupref = 0;
resdom->reskey = reskey;
resdom->reskeyop = reskeyop;
resdom->resjunk = resjunk;
return resdom;
}
/*
* makeConst -
* creates a Const node
*/
Const *
makeConst(Oid consttype,
int constlen,
Datum constvalue,
bool constisnull,
bool constbyval,
bool constisset,
bool constiscast)
{
Const *cnst = makeNode(Const);
cnst->consttype = consttype;
cnst->constlen = constlen;
cnst->constvalue = constvalue;
cnst->constisnull = constisnull;
cnst->constbyval = constbyval;
cnst->constisset = constisset;
cnst->constiscast = constiscast;
return cnst;
}