mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-08 21:39:20 +02:00
I have attached a patch to allow GROUP BY and/or ORDER BY function or expressions. Note worthy items: 1. The expression or function need not be in the target list. Example: SELECT name FROM foo GROUP BY lower(name); 2. Simplified the grammar to use expressions only. 3. Cleaned up earlier patch in this area to make use of existing utility functions. 3. Reduced some of the members in the SortGroupBy parse node. The original data members were redundant with the new expression node. (MUST do a "make clean" now) 4. Added a new parse node "JoinUsing". The JOIN USING clause was overloading this SortGroupBy structure. With the afore mentioned reduction of members, the two clauses lost all their commonality. 5. A bug still exist where, if a function or expression is GROUPed BY, and an aggregate function does not include a attribute from the expression or function, the backend crashes. (or something like that) The bug pre-dates this patch. Example: SELECT lower(a) AS lowcase, count(b) FROM foo GROUP BY lowcase; *** BOOM *** --Also when not in target list SELECT count(b) FROM foo GROUP BY lower(a); *** BOOM AGAIN ***
314 lines
5.8 KiB
C
314 lines
5.8 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* nodes.h--
|
|
* Definitions for tagged nodes.
|
|
*
|
|
*
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* $Id: nodes.h,v 1.26 1998/08/05 04:49:12 scrappy Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef NODES_H
|
|
#define NODES_H
|
|
|
|
/*
|
|
* The first field of every node is NodeTag. Each node created (with makeNode)
|
|
* will have one of the following tags as the value of its first field.
|
|
*
|
|
* Note that the number of the node tags are not contiguous. We left holes
|
|
* here so that we can add more tags without changing the existing enum's.
|
|
*/
|
|
typedef enum NodeTag
|
|
{
|
|
T_Invalid = 0,
|
|
|
|
/*---------------------
|
|
* TAGS FOR PLAN NODES (plannodes.h)
|
|
*---------------------
|
|
*/
|
|
T_Plan = 10,
|
|
T_Result,
|
|
T_Append,
|
|
T_Scan,
|
|
T_SeqScan,
|
|
T_IndexScan,
|
|
T_Join,
|
|
T_NestLoop,
|
|
T_MergeJoin,
|
|
T_HashJoin,
|
|
T_Temp,
|
|
T_Material,
|
|
T_Sort,
|
|
T_Agg,
|
|
T_Unique,
|
|
T_Hash,
|
|
T_Choose,
|
|
T_Tee,
|
|
T_Group,
|
|
T_SubPlan,
|
|
|
|
/*---------------------
|
|
* TAGS FOR PRIMITIVE NODES (primnodes.h)
|
|
*---------------------
|
|
*/
|
|
T_Resdom = 100,
|
|
T_Fjoin,
|
|
T_Expr,
|
|
T_Var,
|
|
T_Oper,
|
|
T_Const,
|
|
T_Param,
|
|
T_Aggreg,
|
|
T_SubLink,
|
|
T_Func,
|
|
T_Array,
|
|
T_ArrayRef,
|
|
|
|
/*---------------------
|
|
* TAGS FOR INNER PLAN NODES (relation.h)
|
|
*---------------------
|
|
*/
|
|
T_RelOptInfo = 200,
|
|
T_Path,
|
|
T_IndexPath,
|
|
T_JoinPath,
|
|
T_MergePath,
|
|
T_HashPath,
|
|
T_OrderKey,
|
|
T_JoinKey,
|
|
T_MergeOrder,
|
|
T_CInfo,
|
|
T_JoinMethod,
|
|
T_HInfo,
|
|
T_MInfo,
|
|
T_JInfo,
|
|
T_Iter,
|
|
T_Stream,
|
|
|
|
/*---------------------
|
|
* TAGS FOR EXECUTOR NODES (execnodes.h)
|
|
*---------------------
|
|
*/
|
|
T_IndexInfo = 300,
|
|
T_RelationInfo,
|
|
T_TupleCount,
|
|
T_TupleTableSlot,
|
|
T_ExprContext,
|
|
T_ProjectionInfo,
|
|
T_JunkFilter,
|
|
T_EState,
|
|
T_BaseNode,
|
|
T_CommonState,
|
|
T_ResultState,
|
|
T_AppendState,
|
|
T_CommonScanState,
|
|
T_ScanState,
|
|
T_IndexScanState,
|
|
T_JoinState,
|
|
T_NestLoopState,
|
|
T_MergeJoinState,
|
|
T_HashJoinState,
|
|
T_MaterialState,
|
|
T_AggState,
|
|
T_GroupState,
|
|
T_SortState,
|
|
T_UniqueState,
|
|
T_HashState,
|
|
T_TeeState,
|
|
|
|
/*---------------------
|
|
* TAGS FOR MEMORY NODES (memnodes.h)
|
|
*---------------------
|
|
*/
|
|
T_MemoryContext = 400,
|
|
T_GlobalMemory,
|
|
T_PortalMemoryContext,
|
|
T_PortalVariableMemory,
|
|
T_PortalHeapMemory,
|
|
|
|
/*---------------------
|
|
* TAGS FOR VALUE NODES (pg_list.h)
|
|
*---------------------
|
|
*/
|
|
T_Value = 500,
|
|
T_List,
|
|
T_Integer,
|
|
T_Float,
|
|
T_String,
|
|
T_Null,
|
|
|
|
/*---------------------
|
|
* TAGS FOR PARSE TREE NODES (parsenode.h)
|
|
*---------------------
|
|
*/
|
|
T_Query = 600,
|
|
T_InsertStmt,
|
|
T_DeleteStmt,
|
|
T_UpdateStmt,
|
|
T_SelectStmt,
|
|
T_AddAttrStmt,
|
|
T_AggregateStmt,
|
|
T_ChangeACLStmt,
|
|
T_ClosePortalStmt,
|
|
T_ClusterStmt,
|
|
T_CopyStmt,
|
|
T_CreateStmt,
|
|
T_VersionStmt,
|
|
T_DefineStmt,
|
|
T_DestroyStmt,
|
|
T_ExtendStmt,
|
|
T_FetchStmt,
|
|
T_IndexStmt,
|
|
T_ProcedureStmt,
|
|
T_RecipeStmt,
|
|
T_RemoveAggrStmt,
|
|
T_RemoveFuncStmt,
|
|
T_RemoveOperStmt,
|
|
T_RemoveStmt,
|
|
T_RenameStmt,
|
|
T_RuleStmt,
|
|
T_NotifyStmt,
|
|
T_ListenStmt,
|
|
T_TransactionStmt,
|
|
T_ViewStmt,
|
|
T_LoadStmt,
|
|
T_CreatedbStmt,
|
|
T_DestroydbStmt,
|
|
T_VacuumStmt,
|
|
T_ExplainStmt,
|
|
T_CreateSeqStmt,
|
|
T_VariableSetStmt,
|
|
T_VariableShowStmt,
|
|
T_VariableResetStmt,
|
|
T_CreateTrigStmt,
|
|
T_DropTrigStmt,
|
|
T_CreatePLangStmt,
|
|
T_DropPLangStmt,
|
|
T_CreateUserStmt,
|
|
T_AlterUserStmt,
|
|
T_DropUserStmt,
|
|
|
|
T_A_Expr = 700,
|
|
T_Attr,
|
|
T_A_Const,
|
|
T_ParamNo,
|
|
T_Ident,
|
|
T_FuncCall,
|
|
T_A_Indices,
|
|
T_ResTarget,
|
|
T_ParamString,
|
|
T_RelExpr,
|
|
T_SortGroupBy,
|
|
T_RangeVar,
|
|
T_TypeName,
|
|
T_IndexElem,
|
|
T_ColumnDef,
|
|
T_Constraint,
|
|
T_DefElem,
|
|
T_TargetEntry,
|
|
T_RangeTblEntry,
|
|
T_SortClause,
|
|
T_GroupClause,
|
|
T_SubSelect,
|
|
T_JoinUsing
|
|
} NodeTag;
|
|
|
|
/*
|
|
* The first field of a node of any type is gauranteed to be the NodeTag.
|
|
* Hence the type of any node can be gotten by casting it to Node. Declaring
|
|
* a variable to be of Node * (instead of void *) can also facilitate
|
|
* debugging.
|
|
*/
|
|
typedef struct Node
|
|
{
|
|
NodeTag type;
|
|
} Node;
|
|
|
|
#define nodeTag(_node_) ((Node*)_node_)->type
|
|
|
|
#define makeNode(_node_) (_node_*)newNode(sizeof(_node_),T_##_node_)
|
|
#define NodeSetTag(n, t) ((Node *)n)->type = t
|
|
|
|
#define IsA(_node_,_tag_) (nodeTag(_node_) == T_##_tag_)
|
|
|
|
/* ----------------------------------------------------------------
|
|
* IsA functions (no inheritence any more)
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
#define IsA_JoinPath(jp) \
|
|
(nodeTag(jp)==T_JoinPath || nodeTag(jp)==T_MergePath || \
|
|
nodeTag(jp)==T_HashPath)
|
|
|
|
#define IsA_Join(j) \
|
|
(nodeTag(j)==T_Join || nodeTag(j)==T_NestLoop || \
|
|
nodeTag(j)==T_MergeJoin || nodeTag(j)==T_HashJoin)
|
|
|
|
#define IsA_Temp(t) \
|
|
(nodeTag(t)==T_Temp || nodeTag(t)==T_Material || nodeTag(t)==T_Sort || \
|
|
nodeTag(t)==T_Unique)
|
|
|
|
/* ----------------------------------------------------------------
|
|
* extern declarations follow
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
* nodes/nodes.c
|
|
*/
|
|
extern Node *newNode(Size size, NodeTag tag);
|
|
|
|
/*
|
|
* nodes/{outfuncs.c,print.c}
|
|
*/
|
|
#define nodeDisplay pprint
|
|
|
|
extern char *nodeToString(void *obj);
|
|
extern void print(void *obj);
|
|
|
|
/*
|
|
* nodes/{readfuncs.c,read.c}
|
|
*/
|
|
extern void *stringToNode(char *str);
|
|
|
|
/*
|
|
* nodes/copyfuncs.c
|
|
*/
|
|
extern void *copyObject(void *obj);
|
|
|
|
/*
|
|
* nodes/equalfuncs.c
|
|
*/
|
|
extern bool equal(void *a, void *b);
|
|
|
|
|
|
/* ----------------
|
|
* I don't know why this is here. Most likely a hack..
|
|
* -cim 6/3/90
|
|
* ----------------
|
|
*/
|
|
typedef float Cost;
|
|
|
|
/*
|
|
* CmdType -
|
|
* enums for type of operation to aid debugging
|
|
*
|
|
* ??? could have put this in parsenodes.h but many files not in the
|
|
* optimizer also need this...
|
|
*/
|
|
typedef enum CmdType
|
|
{
|
|
CMD_UNKNOWN,
|
|
CMD_SELECT, /* select stmt (formerly retrieve) */
|
|
CMD_UPDATE, /* update stmt (formerly replace) */
|
|
CMD_INSERT, /* insert stmt (formerly append) */
|
|
CMD_DELETE,
|
|
CMD_NOTIFY,
|
|
CMD_UTILITY /* cmds like create, destroy, copy,
|
|
* vacuum, etc. */
|
|
} CmdType;
|
|
|
|
|
|
#endif /* NODES_H */
|