Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit71dc300

Browse files
committed
The contents of command.c, creatinh.c, define.c, remove.c and rename.c
have been divided according to the type of object manipulated - so ALTERTABLE code is in tablecmds.c, aggregate commands in aggregatecmds.c andso on.A few common support routines remain in define.c (prototypes insrc/include/commands/defrem.h).No code has been changed except for includes to reflect the new files.The prototypes for aggregatecmds.c, functioncmds.c, operatorcmds.c,and typecmds.c remain in src/include/commands/defrem.h.From John Gray <jgray@azuli.co.uk>
1 parentab1ead6 commit71dc300

29 files changed

+3598
-3556
lines changed

‎src/backend/commands/Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#-------------------------------------------------------------------------
22
#
33
# Makefile--
4-
# Makefile for commands
4+
# Makefile forbackend/commands
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.27 2001/07/1322:55:59 tgl Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.28 2002/04/15 05:22:03 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/commands
1212
top_builddir = ../../..
1313
include$(top_builddir)/src/Makefile.global
1414

15-
OBJS = async.o creatinh.o command.o comment.o copy.o indexcmds.o define.o\
16-
remove.o rename.o vacuum.o vacuumlazy.o analyze.o view.o cluster.o\
17-
explain.o sequence.o trigger.o user.o proclang.o\
18-
dbcommands.o variable.o
15+
OBJS = aggregatecmds.o analyze.o async.o cluster.o comment.o copy.o\
16+
dbcommands.o define.o explain.o functioncmds.o\
17+
indexcmds.o lockcmds.o operatorcmds.o portalcmds.o proclang.o\
18+
schemacmds.o sequence.o tablecmds.o trigger.o typecmds.o user.o\
19+
vacuum.o vacuumlazy.o variable.o view.o
1920

2021
all: SUBSYS.o
2122

‎src/backend/commands/aggregatecmds.c

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* aggregatecmds.c
4+
*
5+
* Routines for aggregate-manipulation commands
6+
*
7+
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8+
* Portions Copyright (c) 1994, Regents of the University of California
9+
*
10+
*
11+
* IDENTIFICATION
12+
* $Header: /cvsroot/pgsql/src/backend/commands/aggregatecmds.c,v 1.1 2002/04/15 05:22:03 tgl Exp $
13+
*
14+
* DESCRIPTION
15+
* The "DefineFoo" routines take the parse tree and pick out the
16+
* appropriate arguments/flags, passing the results to the
17+
* corresponding "FooDefine" routines (in src/catalog) that do
18+
* the actual catalog-munging. These routines also verify permission
19+
* of the user to execute the command.
20+
*
21+
*-------------------------------------------------------------------------
22+
*/
23+
#include"postgres.h"
24+
25+
#include"access/heapam.h"
26+
#include"catalog/catname.h"
27+
#include"catalog/namespace.h"
28+
#include"catalog/pg_aggregate.h"
29+
#include"commands/comment.h"
30+
#include"commands/defrem.h"
31+
#include"miscadmin.h"
32+
#include"parser/parse_func.h"
33+
#include"parser/parse_type.h"
34+
#include"utils/acl.h"
35+
#include"utils/builtins.h"
36+
#include"utils/lsyscache.h"
37+
#include"utils/syscache.h"
38+
39+
40+
/*
41+
*DefineAggregate
42+
*/
43+
void
44+
DefineAggregate(List*names,List*parameters)
45+
{
46+
char*aggName;
47+
OidaggNamespace;
48+
List*transfuncName=NIL;
49+
List*finalfuncName=NIL;
50+
TypeName*baseType=NULL;
51+
TypeName*transType=NULL;
52+
char*initval=NULL;
53+
OidbaseTypeId;
54+
OidtransTypeId;
55+
List*pl;
56+
57+
/* Convert list of names to a name and namespace */
58+
aggNamespace=QualifiedNameGetCreationNamespace(names,&aggName);
59+
60+
foreach(pl,parameters)
61+
{
62+
DefElem*defel= (DefElem*)lfirst(pl);
63+
64+
/*
65+
* sfunc1, stype1, and initcond1 are accepted as obsolete
66+
* spellings for sfunc, stype, initcond.
67+
*/
68+
if (strcasecmp(defel->defname,"sfunc")==0)
69+
transfuncName=defGetQualifiedName(defel);
70+
elseif (strcasecmp(defel->defname,"sfunc1")==0)
71+
transfuncName=defGetQualifiedName(defel);
72+
elseif (strcasecmp(defel->defname,"finalfunc")==0)
73+
finalfuncName=defGetQualifiedName(defel);
74+
elseif (strcasecmp(defel->defname,"basetype")==0)
75+
baseType=defGetTypeName(defel);
76+
elseif (strcasecmp(defel->defname,"stype")==0)
77+
transType=defGetTypeName(defel);
78+
elseif (strcasecmp(defel->defname,"stype1")==0)
79+
transType=defGetTypeName(defel);
80+
elseif (strcasecmp(defel->defname,"initcond")==0)
81+
initval=defGetString(defel);
82+
elseif (strcasecmp(defel->defname,"initcond1")==0)
83+
initval=defGetString(defel);
84+
else
85+
elog(WARNING,"DefineAggregate: attribute \"%s\" not recognized",
86+
defel->defname);
87+
}
88+
89+
/*
90+
* make sure we have our required definitions
91+
*/
92+
if (baseType==NULL)
93+
elog(ERROR,"Define: \"basetype\" unspecified");
94+
if (transType==NULL)
95+
elog(ERROR,"Define: \"stype\" unspecified");
96+
if (transfuncName==NIL)
97+
elog(ERROR,"Define: \"sfunc\" unspecified");
98+
99+
/*
100+
* Handle the aggregate's base type (input data type). This can be
101+
* specified as 'ANY' for a data-independent transition function, such
102+
* as COUNT(*).
103+
*/
104+
baseTypeId=LookupTypeName(baseType);
105+
if (OidIsValid(baseTypeId))
106+
{
107+
/* no need to allow aggregates on as-yet-undefined types */
108+
if (!get_typisdefined(baseTypeId))
109+
elog(ERROR,"Type \"%s\" is only a shell",
110+
TypeNameToString(baseType));
111+
}
112+
else
113+
{
114+
char*typnam=TypeNameToString(baseType);
115+
116+
if (strcasecmp(typnam,"ANY")!=0)
117+
elog(ERROR,"Type \"%s\" does not exist",typnam);
118+
baseTypeId=InvalidOid;
119+
}
120+
121+
/* handle transtype --- no special cases here */
122+
transTypeId=typenameTypeId(transType);
123+
124+
/*
125+
* Most of the argument-checking is done inside of AggregateCreate
126+
*/
127+
AggregateCreate(aggName,/* aggregate name */
128+
aggNamespace,/* namespace */
129+
transfuncName,/* step function name */
130+
finalfuncName,/* final function name */
131+
baseTypeId,/* type of data being aggregated */
132+
transTypeId,/* transition data type */
133+
initval);/* initial condition */
134+
}
135+
136+
137+
void
138+
RemoveAggregate(List*aggName,TypeName*aggType)
139+
{
140+
Relationrelation;
141+
HeapTupletup;
142+
OidbasetypeID;
143+
OidprocOid;
144+
145+
/*
146+
* if a basetype is passed in, then attempt to find an aggregate for
147+
* that specific type.
148+
*
149+
* else if the basetype is blank, then attempt to find an aggregate with
150+
* a basetype of zero.This is valid. It means that the aggregate is
151+
* to apply to all basetypes (eg, COUNT).
152+
*/
153+
if (aggType)
154+
basetypeID=typenameTypeId(aggType);
155+
else
156+
basetypeID=InvalidOid;
157+
158+
procOid=find_aggregate_func("RemoveAggregate",aggName,basetypeID);
159+
160+
/* Permission check */
161+
162+
if (!pg_proc_ownercheck(procOid,GetUserId()))
163+
{
164+
if (basetypeID==InvalidOid)
165+
elog(ERROR,"RemoveAggregate: aggregate %s for all types: permission denied",
166+
NameListToString(aggName));
167+
else
168+
elog(ERROR,"RemoveAggregate: aggregate %s for type %s: permission denied",
169+
NameListToString(aggName),format_type_be(basetypeID));
170+
}
171+
172+
/* Remove the pg_proc tuple */
173+
174+
relation=heap_openr(ProcedureRelationName,RowExclusiveLock);
175+
176+
tup=SearchSysCache(PROCOID,
177+
ObjectIdGetDatum(procOid),
178+
0,0,0);
179+
if (!HeapTupleIsValid(tup))/* should not happen */
180+
elog(ERROR,"RemoveAggregate: couldn't find pg_proc tuple for %s",
181+
NameListToString(aggName));
182+
183+
/* Delete any comments associated with this function */
184+
DeleteComments(procOid,RelationGetRelid(relation));
185+
186+
simple_heap_delete(relation,&tup->t_self);
187+
188+
ReleaseSysCache(tup);
189+
190+
heap_close(relation,RowExclusiveLock);
191+
192+
/* Remove the pg_aggregate tuple */
193+
194+
relation=heap_openr(AggregateRelationName,RowExclusiveLock);
195+
196+
tup=SearchSysCache(AGGFNOID,
197+
ObjectIdGetDatum(procOid),
198+
0,0,0);
199+
if (!HeapTupleIsValid(tup))/* should not happen */
200+
elog(ERROR,"RemoveAggregate: couldn't find pg_aggregate tuple for %s",
201+
NameListToString(aggName));
202+
203+
simple_heap_delete(relation,&tup->t_self);
204+
205+
ReleaseSysCache(tup);
206+
207+
heap_close(relation,RowExclusiveLock);
208+
}

‎src/backend/commands/cluster.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.77 2002/03/31 07:49:30 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.78 2002/04/15 05:22:03 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -29,8 +29,7 @@
2929
#include"catalog/pg_index.h"
3030
#include"catalog/pg_proc.h"
3131
#include"commands/cluster.h"
32-
#include"commands/command.h"
33-
#include"commands/rename.h"
32+
#include"commands/tablecmds.h"
3433
#include"miscadmin.h"
3534
#include"utils/builtins.h"
3635
#include"utils/lsyscache.h"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp