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

Commit52200be

Browse files
committed
Implement types regprocedure, regoper, regoperator, regclass, regtype
per pghackers discussion. Add some more typsanity tests, and cleanup some problems exposed thereby (broken or missing array types forsome built-in types). Also, clean up loose ends from unknownin/outpatch.
1 parent4eac391 commit52200be

File tree

28 files changed

+1634
-225
lines changed

28 files changed

+1634
-225
lines changed

‎contrib/findoidjoins/README.findoidjoins

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
findoidjoins
33

4-
This program scans a database, and prints oid fields (also regproc fields)
5-
and the tables they join to. CAUTION: it is ver-r-r-y slow on a large
6-
database, or even a not-so-large one. We don't really recommend running
7-
it on anything but an empty database, such as template1.
4+
This program scans a database, and prints oid fields (also regproc, regclass
5+
andregtype fields) andthe tables they join to. CAUTION: it is ver-r-r-y
6+
slow on a largedatabase, or even a not-so-large one. We don't really
7+
recommend runningit on anything but an empty database, such as template1.
88

99
Uses pgeasy library.
1010

‎contrib/findoidjoins/findoidjoins.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ main(int argc, char **argv)
3939
WHERE a.attnum > 0 AND \
4040
relkind = 'r' AND \
4141
(typname = 'oid' OR \
42-
typname = 'regproc') AND \
42+
typname = 'regproc' OR \
43+
typname = 'regclass' OR \
44+
typname = 'regtype') AND \
4345
a.attrelid = c.oid AND \
4446
a.atttypid = t.oid \
4547
ORDER BY 2, a.attnum ; \
@@ -77,7 +79,7 @@ main(int argc, char **argv)
7779
DECLARE c_matches BINARY CURSOR FOR \
7880
SELECTcount(*)::int4 \
7981
FROM \"%s\" t1, \"%s\" t2 \
80-
WHERERegprocToOid(t1.\"%s\") = t2.oid ",
82+
WHERE t1.\"%s\"::oid = t2.oid ",
8183
relname,relname2,attname);
8284

8385
doquery(query);

‎doc/src/sgml/bki.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/bki.sgml,v 1.10 2002/03/22 19:20:02 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/bki.sgml,v 1.11 2002/04/25 02:56:55 tgl Exp $
33
-->
44

55
<chapter id="bki">
@@ -122,7 +122,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/bki.sgml,v 1.10 2002/03/22 19:20:02 petere
122122
storage. The following types are allowed: <type>bool</type>,
123123
<type>bytea</type>, <type>char</type> (1 byte),
124124
<type>name</type>, <type>int2</type>, <type>int2vector</type>,
125-
<type>int4</type>, <type>regproc</type>, <type>text</type>,
125+
<type>int4</type>, <type>regproc</type>, <type>regclass</type>,
126+
<type>regtype</type>, <type>text</type>,
126127
<type>oid</type>, <type>tid</type>, <type>xid</type>,
127128
<type>cid</type>, <type>oidvector</type>, <type>smgr</type>,
128129
<type>_int4</type> (array), <type>_aclitem</type> (array).

‎doc/src/sgml/datatype.sgml

Lines changed: 160 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.89 2002/04/21 18:58:00 thomas Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.90 2002/04/25 02:56:55 tgl Exp $
33
-->
44

55
<chapter id="datatype">
@@ -172,12 +172,6 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.89 2002/04/21 18:58:00 th
172172
<entry>exact numeric with selectable precision</entry>
173173
</row>
174174

175-
<row>
176-
<entry><type>oid</type></entry>
177-
<entry></entry>
178-
<entry>object identifier</entry>
179-
</row>
180-
181175
<row>
182176
<entry><type>path</type></entry>
183177
<entry></entry>
@@ -2894,6 +2888,165 @@ SELECT SUBSTRING(b FROM 1 FOR 2) FROM test;
28942888

28952889
</sect1>
28962890

2891+
<sect1 id="datatype-oid">
2892+
<title>Object Identifier Types</title>
2893+
2894+
<indexterm zone="datatype-oid">
2895+
<primary>object identifier</primary>
2896+
<secondary>data type</secondary>
2897+
</indexterm>
2898+
2899+
<indexterm zone="datatype-oid">
2900+
<primary>oid</primary>
2901+
</indexterm>
2902+
2903+
<indexterm zone="datatype-oid">
2904+
<primary>regproc</primary>
2905+
</indexterm>
2906+
2907+
<indexterm zone="datatype-oid">
2908+
<primary>regprocedure</primary>
2909+
</indexterm>
2910+
2911+
<indexterm zone="datatype-oid">
2912+
<primary>regoper</primary>
2913+
</indexterm>
2914+
2915+
<indexterm zone="datatype-oid">
2916+
<primary>regoperator</primary>
2917+
</indexterm>
2918+
2919+
<indexterm zone="datatype-oid">
2920+
<primary>regclass</primary>
2921+
</indexterm>
2922+
2923+
<indexterm zone="datatype-oid">
2924+
<primary>regtype</primary>
2925+
</indexterm>
2926+
2927+
<para>
2928+
Object identifiers (OIDs) are used internally by
2929+
<productname>PostgreSQL</productname> as primary keys for various system
2930+
tables. Also, an OID system column is added to user-created tables
2931+
(unless <literal>WITHOUT OIDS</> is specified at table creation time).
2932+
Type <type>oid</> represents an object identifier. There are also
2933+
several aliases for <type>oid</>: <type>regproc</>, <type>regprocedure</>,
2934+
<type>regoper</>, <type>regoperator</>, <type>regclass</>,
2935+
and <type>regtype</>.
2936+
</para>
2937+
2938+
<para>
2939+
The <type>oid</> type is currently implemented as an unsigned four-byte
2940+
integer.
2941+
Therefore, it is not large enough to provide database-wide uniqueness
2942+
in large databases, or even in large individual tables. So, using a
2943+
user-created table's OID column as a primary key is discouraged.
2944+
OIDs are best used only for references to system tables.
2945+
</para>
2946+
2947+
<para>
2948+
The <type>oid</> type itself has few operations beyond comparison
2949+
(which is implemented as unsigned comparison). It can be cast to
2950+
integer, however, and then manipulated using the standard integer
2951+
operators. (Beware of possible signed-versus-unsigned confusion
2952+
if you do this.)
2953+
</para>
2954+
2955+
<para>
2956+
The <type>oid</> alias types have no operations of their own except
2957+
for specialized input and output routines. These routines are able
2958+
to accept and display symbolic names for system objects, rather than
2959+
the raw numeric value that type <type>oid</> would use. The alias
2960+
types allow simplified lookup of OID values for objects: for example,
2961+
one may write <literal>'mytable'::regclass</> to get the OID of table
2962+
<literal>mytable</>, rather than <literal>SELECT oid FROM pg_class WHERE
2963+
relname = 'mytable'</>. (In reality, a much more complicated SELECT would
2964+
be needed to deal with selecting the right OID when there are multiple
2965+
tables named <literal>mytable</> in different schemas.)
2966+
</para>
2967+
2968+
<para>
2969+
<table tocentry="1">
2970+
<title>Object Identifier Types</title>
2971+
<tgroup cols="4">
2972+
<thead>
2973+
<row>
2974+
<entry>Type name</entry>
2975+
<entry>References</entry>
2976+
<entry>Description</entry>
2977+
<entry>Examples</entry>
2978+
</row>
2979+
</thead>
2980+
2981+
<tbody>
2982+
2983+
<row>
2984+
<entry><type>oid</></entry>
2985+
<entry>any</entry>
2986+
<entry>Numeric object identifier</entry>
2987+
<entry>564182</entry>
2988+
</row>
2989+
2990+
<row>
2991+
<entry><type>regproc</></entry>
2992+
<entry>pg_proc</entry>
2993+
<entry>Function name</entry>
2994+
<entry>sum</entry>
2995+
</row>
2996+
2997+
<row>
2998+
<entry><type>regprocedure</></entry>
2999+
<entry>pg_proc</entry>
3000+
<entry>Function with argument types</entry>
3001+
<entry>sum(int4)</entry>
3002+
</row>
3003+
3004+
<row>
3005+
<entry><type>regoper</></entry>
3006+
<entry>pg_operator</entry>
3007+
<entry>Operator name</entry>
3008+
<entry>+</entry>
3009+
</row>
3010+
3011+
<row>
3012+
<entry><type>regoperator</></entry>
3013+
<entry>pg_operator</entry>
3014+
<entry>Operator with argument types</entry>
3015+
<entry>*(integer,integer) -(NONE,integer)</entry>
3016+
</row>
3017+
3018+
<row>
3019+
<entry><type>regclass</></entry>
3020+
<entry>pg_class</entry>
3021+
<entry>Relation name</entry>
3022+
<entry>pg_type</entry>
3023+
</row>
3024+
3025+
<row>
3026+
<entry><type>regtype</></entry>
3027+
<entry>pg_type</entry>
3028+
<entry>Type name</entry>
3029+
<entry>integer</entry>
3030+
</row>
3031+
</tbody>
3032+
</tgroup>
3033+
</table>
3034+
</para>
3035+
3036+
<para>
3037+
All of the alias types accept schema-qualified names, and will
3038+
display schema-qualified names on output if the object would not
3039+
be found in the current search path without being qualified.
3040+
The <type>regproc</> and <type>regoper</> alias types will only
3041+
accept input names that are unique (not overloaded), so they are
3042+
of limited use; for most uses <type>regprocedure</> or
3043+
<type>regoperator</> is more appropriate. For <type>regoperator</>,
3044+
unary operators are identified by writing NONE for the unused
3045+
operand.
3046+
</para>
3047+
3048+
</sect1>
3049+
28973050
</chapter>
28983051

28993052
<!-- Keep this comment at the end of the file

‎src/backend/bootstrap/bootstrap.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.125 2002/03/26 19:15:16 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.126 2002/04/25 02:56:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -109,12 +109,14 @@ static struct typinfo Procid[] = {
109109
{"int2vector",INT2VECTOROID,0,INDEX_MAX_KEYS*2,F_INT2VECTORIN,F_INT2VECTOROUT},
110110
{"int4",INT4OID,0,4,F_INT4IN,F_INT4OUT},
111111
{"regproc",REGPROCOID,0,4,F_REGPROCIN,F_REGPROCOUT},
112+
{"regclass",REGCLASSOID,0,4,F_REGCLASSIN,F_REGCLASSOUT},
113+
{"regtype",REGTYPEOID,0,4,F_REGTYPEIN,F_REGTYPEOUT},
112114
{"text",TEXTOID,0,-1,F_TEXTIN,F_TEXTOUT},
113115
{"oid",OIDOID,0,4,F_OIDIN,F_OIDOUT},
114116
{"tid",TIDOID,0,6,F_TIDIN,F_TIDOUT},
115117
{"xid",XIDOID,0,4,F_XIDIN,F_XIDOUT},
116118
{"cid",CIDOID,0,4,F_CIDIN,F_CIDOUT},
117-
{"oidvector",30,0,INDEX_MAX_KEYS*4,F_OIDVECTORIN,F_OIDVECTOROUT},
119+
{"oidvector",OIDVECTOROID,0,INDEX_MAX_KEYS*4,F_OIDVECTORIN,F_OIDVECTOROUT},
118120
{"smgr",210,0,2,F_SMGRIN,F_SMGROUT},
119121
{"_int4",1007,INT4OID,-1,F_ARRAY_IN,F_ARRAY_OUT},
120122
{"_aclitem",1034,1033,-1,F_ARRAY_IN,F_ARRAY_OUT}
@@ -600,7 +602,7 @@ DefineAttr(char *name, char *type, int attnum)
600602
attrtypes[attnum]->attnum=1+attnum;/* fillatt */
601603
attlen=attrtypes[attnum]->attlen=Ap->am_typ.typlen;
602604
attrtypes[attnum]->attbyval=Ap->am_typ.typbyval;
603-
attrtypes[attnum]->attstorage=Ap->am_typ.typstorage;;
605+
attrtypes[attnum]->attstorage=Ap->am_typ.typstorage;
604606
attrtypes[attnum]->attalign=Ap->am_typ.typalign;
605607
}
606608
else
@@ -610,28 +612,37 @@ DefineAttr(char *name, char *type, int attnum)
610612
elog(DEBUG3,"column %s %s",NameStr(attrtypes[attnum]->attname),type);
611613
attrtypes[attnum]->attnum=1+attnum;/* fillatt */
612614
attlen=attrtypes[attnum]->attlen=Procid[typeoid].len;
613-
attrtypes[attnum]->attstorage='p';
614615

615616
/*
616617
* Cheat like mad to fill in these items from the length only.
617-
* This only has to work for typesusedinthe system catalogs...
618+
* This only has to work for typesthat appearinProcid[].
618619
*/
619620
switch (attlen)
620621
{
621622
case1:
622623
attrtypes[attnum]->attbyval= true;
624+
attrtypes[attnum]->attstorage='p';
623625
attrtypes[attnum]->attalign='c';
624626
break;
625627
case2:
626628
attrtypes[attnum]->attbyval= true;
629+
attrtypes[attnum]->attstorage='p';
627630
attrtypes[attnum]->attalign='s';
628631
break;
629632
case4:
630633
attrtypes[attnum]->attbyval= true;
634+
attrtypes[attnum]->attstorage='p';
635+
attrtypes[attnum]->attalign='i';
636+
break;
637+
case-1:
638+
attrtypes[attnum]->attbyval= false;
639+
attrtypes[attnum]->attstorage='x';
631640
attrtypes[attnum]->attalign='i';
632641
break;
633642
default:
643+
/* TID and fixed-length arrays, such as oidvector */
634644
attrtypes[attnum]->attbyval= false;
645+
attrtypes[attnum]->attstorage='p';
635646
attrtypes[attnum]->attalign='i';
636647
break;
637648
}
@@ -803,6 +814,13 @@ cleanup()
803814

804815
/* ----------------
805816
*gettype
817+
*
818+
* NB: this is really ugly; it will return an integer index into Procid[],
819+
* and not an OID at all, until the first reference to a type not known in
820+
* Procid[]. At that point it will read and cache pg_type in the Typ array,
821+
* and subsequently return a real OID (and set the global pointer Ap to
822+
* point at the found row in Typ). So caller must check whether Typ is
823+
* still NULL to determine what the return value is!
806824
* ----------------
807825
*/
808826
staticOid
@@ -827,7 +845,7 @@ gettype(char *type)
827845
}
828846
else
829847
{
830-
for (i=0;i <=n_types;i++)
848+
for (i=0;i<n_types;i++)
831849
{
832850
if (strncmp(type,Procid[i].name,NAMEDATALEN)==0)
833851
returni;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp