*** ./src/backend/executor/spi.c.orig 2003-06-30 00:48:37.000000000 +0530 --- ./src/backend/executor/spi.c 2003-06-30 00:51:06.000000000 +0530 *************** *** 1046,1051 **** --- 1046,1052 ---- case T_UpdateStmt: origCmdType = CMD_UPDATE; break; + case T_CubeSelectStmt: /*** DATACUBE ***/ case T_SelectStmt: origCmdType = CMD_SELECT; break; *** ./src/backend/nodes/copyfuncs.c.orig 2003-06-30 00:48:48.000000000 +0530 --- ./src/backend/nodes/copyfuncs.c 2003-06-30 00:51:17.000000000 +0530 *************** *** 2944,2949 **** --- 2944,2950 ---- case T_UpdateStmt: retval = _copyUpdateStmt(from); break; + case T_CubeSelectStmt: /*** DATACUBE ***/ case T_SelectStmt: retval = _copySelectStmt(from); break; *** ./src/backend/nodes/equalfuncs.c.orig 2003-06-30 00:48:51.000000000 +0530 --- ./src/backend/nodes/equalfuncs.c 2003-06-30 00:51:25.000000000 +0530 *************** *** 2149,2154 **** --- 2149,2155 ---- case T_UpdateStmt: retval = _equalUpdateStmt(a, b); break; + case T_CubeSelectStmt: /*** DATACUBE ***/ case T_SelectStmt: retval = _equalSelectStmt(a, b); break; *** ./src/backend/nodes/outfuncs.c.orig 2003-06-30 00:48:55.000000000 +0530 --- ./src/backend/nodes/outfuncs.c 2003-06-30 00:51:31.000000000 +0530 *************** *** 1555,1560 **** --- 1555,1561 ---- case T_NotifyStmt: _outNotifyStmt(str, obj); break; + case T_CubeSelectStmt: /*** DATACUBE ***/ case T_SelectStmt: _outSelectStmt(str, obj); break; *** ./src/backend/parser/analyze.c.orig 2003-06-30 00:49:02.000000000 +0530 --- ./src/backend/parser/analyze.c 2003-06-30 01:12:44.000000000 +0530 *************** *** 304,309 **** --- 304,310 ---- break; case T_SelectStmt: + case T_CubeSelectStmt: /*** DATACUBE ***/ if (((SelectStmt *) parseTree)->op == SETOP_NONE) result = transformSelectStmt(pstate, (SelectStmt *) parseTree); *** ./src/backend/parser/gram.y.orig 2003-06-30 00:49:06.000000000 +0530 --- ./src/backend/parser/gram.y 2003-06-30 15:31:14.000000000 +0530 *************** *** 212,218 **** any_operator expr_list dotted_name attrs target_list update_target_list insert_column_list insert_target_list def_list opt_indirection ! group_clause TriggerFuncArgs select_limit opt_select_limit opclass_item_list trans_options TableFuncElementList prep_type_clause prep_type_list --- 212,218 ---- any_operator expr_list dotted_name attrs target_list update_target_list insert_column_list insert_target_list def_list opt_indirection ! group_clause TriggerFuncArgs select_limit cube_group_clause /*** DATACUBE ***/ opt_select_limit opclass_item_list trans_options TableFuncElementList prep_type_clause prep_type_list *************** *** 331,337 **** CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT COMMITTED CONSTRAINT CONSTRAINTS CONVERSION_P CONVERT COPY CREATE CREATEDB CREATEUSER CROSS CURRENT_DATE CURRENT_TIME ! CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE DATABASE DAY_P DEALLOCATE DEC DECIMAL DECLARE DEFAULT DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS --- 331,337 ---- CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT COMMITTED CONSTRAINT CONSTRAINTS CONVERSION_P CONVERT COPY CREATE CREATEDB CREATEUSER CROSS CURRENT_DATE CURRENT_TIME ! CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE CUBE /*** DATACUBE ***/ DATABASE DAY_P DEALLOCATE DEC DECIMAL DECLARE DEFAULT DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS *************** *** 4234,4239 **** --- 4234,4254 ---- into_clause from_clause where_clause group_clause having_clause { + SelectStmt *n = makeNode(SelectStmt); + n->distinctClause = $2; + n->targetList = $3; + n->into = $4; + n->intoColNames = NIL; + n->fromClause = $5; + n->whereClause = $6; + n->groupClause = $7; + n->havingClause = $8; + $$ = (Node *)n; + } + | SELECT opt_distinct target_list + into_clause from_clause where_clause + cube_group_clause having_clause WITH CUBE /*** DATACUBE ***/ + { SelectStmt *n = makeNode(SelectStmt); n->distinctClause = $2; n->targetList = $3; *************** *** 4243,4248 **** --- 4258,4264 ---- n->whereClause = $6; n->groupClause = $7; n->havingClause = $8; + n->type = T_CubeSelectStmt; /*** DATACUBE ***/ $$ = (Node *)n; } | select_clause UNION opt_all select_clause *************** *** 4471,4476 **** --- 4487,4496 ---- | /*EMPTY*/ { $$ = NIL; } ; + cube_group_clause: /*** DATACUBE ***/ + GROUP_P BY expr_list { $$ = $3; } /*** DATACUBE ***/ + ; /*** DATACUBE ***/ + having_clause: HAVING a_expr { $$ = $2; } | /*EMPTY*/ { $$ = NULL; } *************** *** 6995,7000 **** --- 7015,7021 ---- | COPY | CREATEDB | CREATEUSER + | CUBE /*** DATACUBE ***/ | CURSOR | CYCLE | DATABASE *** ./src/backend/parser/keywords.c.orig 2003-06-30 00:49:12.000000000 +0530 --- ./src/backend/parser/keywords.c 2003-06-30 00:51:47.000000000 +0530 *************** *** 88,93 **** --- 88,94 ---- {"createdb", CREATEDB}, {"createuser", CREATEUSER}, {"cross", CROSS}, + {"cube", CUBE}, /*** DATACUBE ***/ {"current_date", CURRENT_DATE}, {"current_time", CURRENT_TIME}, {"current_timestamp", CURRENT_TIMESTAMP}, *** ./src/backend/tcop/Makefile.orig 2003-06-30 00:50:07.000000000 +0530 --- ./src/backend/tcop/Makefile 2003-06-30 00:52:28.000000000 +0530 *************** *** 12,18 **** top_builddir = ../../.. include $(top_builddir)/src/Makefile.global ! OBJS= dest.o fastpath.o postgres.o pquery.o utility.o all: SUBSYS.o --- 12,18 ---- top_builddir = ../../.. include $(top_builddir)/src/Makefile.global ! OBJS= dest.o fastpath.o postgres.o pquery.o utility.o datacube.o all: SUBSYS.o *** ./src/backend/tcop/postgres.c.orig 2003-06-30 00:49:21.000000000 +0530 --- ./src/backend/tcop/postgres.c 2003-06-30 14:50:46.000000000 +0530 *************** *** 18,23 **** --- 18,24 ---- */ #include "postgres.h" + #include "datacube.h" /*** DATACUBE ***/ #include #include *************** *** 69,74 **** --- 70,82 ---- extern int optind; extern char *optarg; + /* ---------------- + * Variables for DATACUBE + * ---------------- + */ + int dropTable = 0; + char refTableName[50]; + char *debug_query_string; /* for pgmonitor and * log_min_error_statement */ *************** *** 637,642 **** --- 645,651 ---- case T_UpdateStmt: origCmdType = CMD_UPDATE; break; + case T_CubeSelectStmt: /*** DATACUBE ***/ case T_SelectStmt: origCmdType = CMD_SELECT; break; *************** *** 803,808 **** --- 812,852 ---- */ Plan *plan; + /* ------------------------------------------------- + * DATACUBE: + * Depending on whether the original query is a + * CUBE statement, the function constructCube is + * called. + * + * cubeTable is the temporary table generated using + * the gettimeofday() function and is used for + * displaying the final result. + * + * dropTable is a flag which decides whether or not + * the temporary table is to be dropped. + * + * ------------------------------------------------- + */ + + if(nodeTag(parsetree) == T_CubeSelectStmt && querytree->hasAggs == false) + elog(ERROR, "CUBE operator requires atleast one measure attribute [SUM, MAX, MIN, COUNT, AVG]"); + else if (nodeTag(parsetree) == T_CubeSelectStmt && querytree->hasAggs == true) + { + char *cubeTable; + + cubeTable = palloc(sizeof(char)*30); + cubeTable = getTableName(); + strcpy(refTableName, cubeTable); + dropTable = 1; + + constructCube (querytree, TopMemoryContext, cubeTable); + #ifdef MEMORY_CONTEXT_CHECKING + MemoryContextCheck(TopMemoryContext); + #endif + + return; + } + /* * Initialize snapshot state for query. This has to * be done before running the planner, because it might *************** *** 1924,1932 **** --- 1968,1994 ---- QueryCancelPending = false; CHECK_FOR_INTERRUPTS(); + /* -------------------------------------------------- + * DATACUBE: + * The following if condition checks whether the + * flag dropTable is set and if it is, drops the + * temporary table created for the CUBE. + * + * -------------------------------------------------- + */ + if (dropTable == 1) + { + dropCubeTable (refTableName, TopMemoryContext); + dropTable = 0; + #ifdef MEMORY_CONTEXT_CHECKING + MemoryContextCheck(TopMemoryContext); + #endif + } + /* * (3) read a command (loop blocks here) */ + firstchar = ReadCommand(parser_input); /* *************** *** 2204,2209 **** --- 2266,2272 ---- tag = "UPDATE"; break; + case T_CubeSelectStmt: /*** DATACUBE ***/ case T_SelectStmt: tag = "SELECT"; break; *** ./src/backend/utils/adt/ruleutils.c.orig 2003-06-30 00:52:36.000000000 +0530 --- ./src/backend/utils/adt/ruleutils.c 2003-06-30 15:37:38.000000000 +0530 *************** *** 127,133 **** StringInfo buf); static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); ! static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc); static void get_select_query_def(Query *query, deparse_context *context, TupleDesc resultDesc); --- 127,133 ---- StringInfo buf); static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); ! void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc); static void get_select_query_def(Query *query, deparse_context *context, TupleDesc resultDesc); *************** *** 165,171 **** StringInfo buf); static bool tleIsArrayAssign(TargetEntry *tle); static char *generate_relation_name(Oid relid); ! static char *generate_function_name(Oid funcid, int nargs, Oid *argtypes); static char *generate_operator_name(Oid operid, Oid arg1, Oid arg2); static char *get_relid_attribute_name(Oid relid, AttrNumber attnum); --- 165,171 ---- StringInfo buf); static bool tleIsArrayAssign(TargetEntry *tle); static char *generate_relation_name(Oid relid); ! char *generate_function_name(Oid funcid, int nargs, Oid *argtypes); static char *generate_operator_name(Oid operid, Oid arg1, Oid arg2); static char *get_relid_attribute_name(Oid relid, AttrNumber attnum); *************** *** 1262,1268 **** * the view represented by a SELECT query. * ---------- */ ! static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc) { --- 1262,1268 ---- * the view represented by a SELECT query. * ---------- */ ! void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc) { *************** *** 3146,3152 **** * * The result includes all necessary quoting and schema-prefixing. */ ! static char * generate_function_name(Oid funcid, int nargs, Oid *argtypes) { HeapTuple proctup; --- 3146,3152 ---- * * The result includes all necessary quoting and schema-prefixing. */ ! char * generate_function_name(Oid funcid, int nargs, Oid *argtypes) { HeapTuple proctup; *** ./src/include/nodes/nodes.h.orig 2003-06-30 00:49:40.000000000 +0530 --- ./src/include/nodes/nodes.h 2003-06-30 00:50:40.000000000 +0530 *************** *** 203,208 **** --- 203,209 ---- T_PrepareStmt, T_ExecuteStmt, T_DeallocateStmt, + T_CubeSelectStmt, /*** DATACUBE ***/ T_A_Expr = 700, T_ColumnRef,