Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
6231e161
Commit
6231e161
authored
Dec 24, 1997
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implementation of UNIONs.
parent
18adbd9a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
95 additions
and
91 deletions
+95
-91
src/backend/nodes/copyfuncs.c
src/backend/nodes/copyfuncs.c
+13
-2
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/planner.c
+14
-6
src/backend/optimizer/prep/prepunion.c
src/backend/optimizer/prep/prepunion.c
+37
-34
src/backend/parser/analyze.c
src/backend/parser/analyze.c
+16
-14
src/backend/parser/gram.y
src/backend/parser/gram.y
+9
-17
src/include/nodes/parsenodes.h
src/include/nodes/parsenodes.h
+4
-16
src/include/optimizer/prep.h
src/include/optimizer/prep.h
+2
-2
No files found.
src/backend/nodes/copyfuncs.c
View file @
6231e161
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.2
5 1997/12/23 21:49:03
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.2
6 1997/12/24 06:05:52
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -1567,6 +1567,17 @@ _copyQuery(Query *from)
...
@@ -1567,6 +1567,17 @@ _copyQuery(Query *from)
else
else
newnode
->
qry_aggs
=
NULL
;
newnode
->
qry_aggs
=
NULL
;
if
(
from
->
unionClause
)
{
List
*
ulist
,
*
temp_list
=
NIL
;
foreach
(
ulist
,
from
->
unionClause
)
temp_list
=
lappend
(
temp_list
,
copyObject
(
lfirst
(
ulist
)));
newnode
->
unionClause
=
temp_list
;
}
else
newnode
->
unionClause
=
NULL
;
return
newnode
;
return
newnode
;
}
}
...
...
src/backend/optimizer/plan/planner.c
View file @
6231e161
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.1
5 1997/12/22 05:42:08
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.1
6 1997/12/24 06:06:01
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -81,11 +81,19 @@ planner(Query *parse)
...
@@ -81,11 +81,19 @@ planner(Query *parse)
int
rt_index
;
int
rt_index
;
/*
if
(
parse
->
unionClause
)
* plan inheritance
{
*/
result_plan
=
(
Plan
*
)
plan_union_queries
(
0
,
/* none */
rt_index
=
first_matching_rt_entry
(
rangetable
,
INHERITS_FLAG
);
parse
,
if
(
rt_index
!=
-
1
)
UNION_FLAG
);
/* XXX do we need to do this? bjm 12/19/97 */
tlist
=
preprocess_targetlist
(
tlist
,
parse
->
commandType
,
parse
->
resultRelation
,
parse
->
rtable
);
}
else
if
((
rt_index
=
first_matching_rt_entry
(
rangetable
,
INHERITS_FLAG
))
!=
-
1
)
{
{
result_plan
=
(
Plan
*
)
plan_union_queries
((
Index
)
rt_index
,
result_plan
=
(
Plan
*
)
plan_union_queries
((
Index
)
rt_index
,
parse
,
parse
,
...
...
src/backend/optimizer/prep/prepunion.c
View file @
6231e161
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.1
2 1997/12/21 05:18:28
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.1
3 1997/12/24 06:06:07
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -149,30 +149,6 @@ plan_union_queries(Index rt_index,
...
@@ -149,30 +149,6 @@ plan_union_queries(Index rt_index,
find_all_inheritors
(
lconsi
(
rt_entry
->
relid
,
find_all_inheritors
(
lconsi
(
rt_entry
->
relid
,
NIL
),
NIL
),
NIL
);
NIL
);
break
;
#if 0
case UNION_FLAG:
{
Index rt_index = 0;
union_plans = handleunion(root, rangetable, tlist, qual);
return (make_append(union_plans,
rt_index, rangetable,
((Plan *) lfirst(union_plans))->targetlist));
}
break;
#endif
case
VERSION_FLAG
:
union_relids
=
VersionGetParents
(
rt_entry
->
relid
);
break
;
default:
/* do nothing */
break
;
}
/*
/*
* Remove the flag for this relation, since we're about to handle it
* Remove the flag for this relation, since we're about to handle it
* (do it before recursing!). XXX destructive parse tree change
* (do it before recursing!). XXX destructive parse tree change
...
@@ -200,6 +176,33 @@ plan_union_queries(Index rt_index,
...
@@ -200,6 +176,33 @@ plan_union_queries(Index rt_index,
rt_index
,
rt_index
,
union_rt_entries
,
union_rt_entries
,
((
Plan
*
)
lfirst
(
union_plans
))
->
targetlist
));
((
Plan
*
)
lfirst
(
union_plans
))
->
targetlist
));
break
;
case
UNION_FLAG
:
{
List
*
ulist
,
*
hold_union
,
*
union_plans
;
hold_union
=
parse
->
unionClause
;
parse
->
unionClause
=
NULL
;
/* prevent looping */
union_plans
=
lcons
(
planner
(
parse
),
NIL
);
foreach
(
ulist
,
hold_union
)
union_plans
=
lappend
(
union_plans
,
planner
(
lfirst
(
ulist
)));
return
(
make_append
(
union_plans
,
rt_index
,
rangetable
,
((
Plan
*
)
lfirst
(
union_plans
))
->
targetlist
));
}
break
;
case
VERSION_FLAG
:
union_relids
=
VersionGetParents
(
rt_entry
->
relid
);
break
;
default:
/* do nothing */
break
;
}
}
}
...
...
src/backend/parser/analyze.c
View file @
6231e161
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.5
5 1997/12/23 19:39:42 thomas
Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.5
6 1997/12/24 06:06:18 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -821,18 +821,7 @@ transformSelectStmt(ParseState *pstate, RetrieveStmt *stmt)
...
@@ -821,18 +821,7 @@ transformSelectStmt(ParseState *pstate, RetrieveStmt *stmt)
/* fix where clause */
/* fix where clause */
qry
->
qual
=
transformWhereClause
(
pstate
,
stmt
->
whereClause
);
qry
->
qual
=
transformWhereClause
(
pstate
,
stmt
->
whereClause
);
/* check subselect clause */
/* check having clause */
if
(
stmt
->
unionClause
)
{
elog
(
NOTICE
,
"UNION not yet supported; using first SELECT only"
,
NULL
);
/* XXX HACK just playing with union clause - thomas 1997-12-19 */
if
((
qry
->
uniqueFlag
==
NULL
)
&&
(
!
((
SubSelect
*
)
lfirst
(
stmt
->
unionClause
))
->
unionall
))
qry
->
uniqueFlag
=
"*"
;
}
/* check subselect clause */
if
(
stmt
->
havingClause
)
if
(
stmt
->
havingClause
)
elog
(
NOTICE
,
"HAVING not yet supported; ignore clause"
,
NULL
);
elog
(
NOTICE
,
"HAVING not yet supported; ignore clause"
,
NULL
);
...
@@ -842,7 +831,6 @@ transformSelectStmt(ParseState *pstate, RetrieveStmt *stmt)
...
@@ -842,7 +831,6 @@ transformSelectStmt(ParseState *pstate, RetrieveStmt *stmt)
qry
->
targetList
,
qry
->
targetList
,
qry
->
uniqueFlag
);
qry
->
uniqueFlag
);
/* fix group by clause */
qry
->
groupClause
=
transformGroupClause
(
pstate
,
qry
->
groupClause
=
transformGroupClause
(
pstate
,
stmt
->
groupClause
,
stmt
->
groupClause
,
qry
->
targetList
);
qry
->
targetList
);
...
@@ -851,6 +839,20 @@ transformSelectStmt(ParseState *pstate, RetrieveStmt *stmt)
...
@@ -851,6 +839,20 @@ transformSelectStmt(ParseState *pstate, RetrieveStmt *stmt)
if
(
pstate
->
p_numAgg
>
0
)
if
(
pstate
->
p_numAgg
>
0
)
finalizeAggregates
(
pstate
,
qry
);
finalizeAggregates
(
pstate
,
qry
);
if
(
stmt
->
unionClause
)
{
List
*
ulist
=
NIL
;
QueryTreeList
*
qlist
;
int
i
;
qlist
=
parse_analyze
(
stmt
->
unionClause
);
for
(
i
=
0
;
i
<
qlist
->
len
;
i
++
)
ulist
=
lappend
(
ulist
,
qlist
->
qtrees
[
i
]);
qry
->
unionClause
=
ulist
;
}
else
qry
->
unionClause
=
NULL
;
return
(
Query
*
)
qry
;
return
(
Query
*
)
qry
;
}
}
...
...
src/backend/parser/gram.y
View file @
6231e161
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.8
0 1997/12/23 19:47:32 thomas
Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.8
1 1997/12/24 06:06:26 momjian
Exp $
*
*
* HISTORY
* HISTORY
* AUTHOR DATE MAJOR EVENT
* AUTHOR DATE MAJOR EVENT
...
@@ -120,11 +120,13 @@ Oid param_type(int t); /* used in parse_expr.c */
...
@@ -120,11 +120,13 @@ Oid param_type(int t); /* used in parse_expr.c */
ProcedureStmt, RecipeStmt, RemoveAggrStmt, RemoveOperStmt,
ProcedureStmt, RecipeStmt, RemoveAggrStmt, RemoveOperStmt,
RemoveFuncStmt, RemoveStmt,
RemoveFuncStmt, RemoveStmt,
RenameStmt, RevokeStmt, RuleStmt, TransactionStmt, ViewStmt, LoadStmt,
RenameStmt, RevokeStmt, RuleStmt, TransactionStmt, ViewStmt, LoadStmt,
CreatedbStmt, DestroydbStmt, VacuumStmt,
RetrieveStmt, CursorStm
t,
CreatedbStmt, DestroydbStmt, VacuumStmt,
CursorStmt, SubSelec
t,
ReplaceStmt, AppendStmt, NotifyStmt, DeleteStmt, ClusterStmt,
ReplaceStmt, AppendStmt,
RetrieveStmt,
NotifyStmt, DeleteStmt, ClusterStmt,
ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,
ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,
CreateUserStmt, AlterUserStmt, DropUserStmt
CreateUserStmt, AlterUserStmt, DropUserStmt
%type <rtstmt>
%type <str> opt_database, location
%type <str> opt_database, location
%type <pboolean> user_createdb_clause, user_createuser_clause
%type <pboolean> user_createdb_clause, user_createuser_clause
...
@@ -132,7 +134,6 @@ Oid param_type(int t); /* used in parse_expr.c */
...
@@ -132,7 +134,6 @@ Oid param_type(int t); /* used in parse_expr.c */
%type <str> user_valid_clause
%type <str> user_valid_clause
%type <list> user_group_list, user_group_clause
%type <list> user_group_list, user_group_clause
%type <node> SubSelect
%type <str> join_expr, join_outer, join_spec
%type <str> join_expr, join_outer, join_spec
%type <boolean> TriggerActionTime, TriggerForSpec, PLangTrusted
%type <boolean> TriggerActionTime, TriggerForSpec, PLangTrusted
...
@@ -1049,19 +1050,10 @@ OptArchiveType: ARCHIVE '=' NONE { }
...
@@ -1049,19 +1050,10 @@ OptArchiveType: ARCHIVE '=' NONE { }
CreateAsStmt: CREATE TABLE relation_name OptCreateAs AS SubSelect
CreateAsStmt: CREATE TABLE relation_name OptCreateAs AS SubSelect
{
{
RetrieveStmt *n = makeNode(RetrieveStmt);
RetrieveStmt *n = (RetrieveStmt *)$6;
SubSelect *s = (SubSelect *)$6;
n->unique = s->unique;
n->targetList = s->targetList;
if ($4 != NIL)
if ($4 != NIL)
mapTargetColumns($4, n->targetList);
mapTargetColumns($4, n->targetList);
n->into = $3;
n->into = $3;
n->fromClause = s->fromClause;
n->whereClause = s->whereClause;
n->groupClause = s->groupClause;
n->havingClause = s->havingClause;
n->unionClause = NULL;
n->sortClause = NULL;
$$ = (Node *)n;
$$ = (Node *)n;
}
}
;
;
...
@@ -2291,7 +2283,7 @@ RetrieveStmt: SELECT opt_unique res_target_list2
...
@@ -2291,7 +2283,7 @@ RetrieveStmt: SELECT opt_unique res_target_list2
union_clause: UNION opt_union select_list
union_clause: UNION opt_union select_list
{
{
SubSelect *n =
lfirst($3);
RetrieveStmt *n = (RetrieveStmt *)
lfirst($3);
n->unionall = $2;
n->unionall = $2;
$$ = $3;
$$ = $3;
}
}
...
@@ -2301,7 +2293,7 @@ union_clause: UNION opt_union select_list
...
@@ -2301,7 +2293,7 @@ union_clause: UNION opt_union select_list
select_list: select_list UNION opt_union SubSelect
select_list: select_list UNION opt_union SubSelect
{
{
SubSelect *n = (SubSelec
t *)$4;
RetrieveStmt *n = (RetrieveStm
t *)$4;
n->unionall = $3;
n->unionall = $3;
$$ = lappend($1, $4);
$$ = lappend($1, $4);
}
}
...
@@ -2313,7 +2305,7 @@ SubSelect: SELECT opt_unique res_target_list2
...
@@ -2313,7 +2305,7 @@ SubSelect: SELECT opt_unique res_target_list2
from_clause where_clause
from_clause where_clause
group_clause having_clause
group_clause having_clause
{
{
SubSelect *n = makeNode(SubSelec
t);
RetrieveStmt *n = makeNode(RetrieveStm
t);
n->unique = $2;
n->unique = $2;
n->unionall = FALSE;
n->unionall = FALSE;
n->targetList = $3;
n->targetList = $3;
...
...
src/include/nodes/parsenodes.h
View file @
6231e161
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: parsenodes.h,v 1.3
8 1997/12/23 19:58:12 thomas
Exp $
* $Id: parsenodes.h,v 1.3
9 1997/12/24 06:06:53 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -58,6 +58,8 @@ typedef struct Query
...
@@ -58,6 +58,8 @@ typedef struct Query
int
qry_numAgg
;
/* number of aggregates in the target list */
int
qry_numAgg
;
/* number of aggregates in the target list */
Aggreg
**
qry_aggs
;
/* the aggregates */
Aggreg
**
qry_aggs
;
/* the aggregates */
List
*
unionClause
;
/* unions are linked under the previous query */
/* internal to planner */
/* internal to planner */
List
*
base_relation_list_
;
/* base relation list */
List
*
base_relation_list_
;
/* base relation list */
List
*
join_relation_list_
;
/* list of relations */
List
*
join_relation_list_
;
/* list of relations */
...
@@ -634,6 +636,7 @@ typedef struct RetrieveStmt
...
@@ -634,6 +636,7 @@ typedef struct RetrieveStmt
Node
*
havingClause
;
/* having conditional-expression */
Node
*
havingClause
;
/* having conditional-expression */
List
*
unionClause
;
/* union subselect parameters */
List
*
unionClause
;
/* union subselect parameters */
List
*
sortClause
;
/* sort clause (a list of SortGroupBy's) */
List
*
sortClause
;
/* sort clause (a list of SortGroupBy's) */
int
unionall
;
/* union without unique sort */
}
RetrieveStmt
;
}
RetrieveStmt
;
...
@@ -641,21 +644,6 @@ typedef struct RetrieveStmt
...
@@ -641,21 +644,6 @@ typedef struct RetrieveStmt
* Supporting data structures for Parse Trees
* Supporting data structures for Parse Trees
****************************************************************************/
****************************************************************************/
/*
* SubSelect - specifies subselect parameters
*/
typedef
struct
SubSelect
{
NodeTag
type
;
char
*
unique
;
/* NULL, '*', or unique attribute name */
int
unionall
;
/* union without unique sort */
List
*
targetList
;
/* the target list (of ResTarget) */
List
*
fromClause
;
/* the from clause */
Node
*
whereClause
;
/* qualifications */
List
*
groupClause
;
/* group by clause */
Node
*
havingClause
;
/* having conditional-expression */
}
SubSelect
;
/*
/*
* TypeName - specifies a type in definitions
* TypeName - specifies a type in definitions
*/
*/
...
...
src/include/optimizer/prep.h
View file @
6231e161
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: prep.h,v 1.
9 1997/12/20 07:59:44
momjian Exp $
* $Id: prep.h,v 1.
10 1997/12/24 06:06:58
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -32,7 +32,7 @@ extern List *preprocess_targetlist(List *tlist, int command_type,
...
@@ -32,7 +32,7 @@ extern List *preprocess_targetlist(List *tlist, int command_type,
*/
*/
typedef
enum
UnionFlag
typedef
enum
UnionFlag
{
{
INHERITS_FLAG
,
VERSION_FLAG
INHERITS_FLAG
,
UNION_FLAG
,
VERSION_FLAG
}
UnionFlag
;
}
UnionFlag
;
extern
List
*
find_all_inheritors
(
List
*
unexamined_relids
,
extern
List
*
find_all_inheritors
(
List
*
unexamined_relids
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment