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

Commit93fcbd1

Browse files
committed
Make oidin/oidout produce and consume unsigned representation of Oid,
rather than just being aliases for int4in/int4out. Give type Oid afull set of comparison operators that do proper unsigned comparison,instead of reusing the int4 comparators. Since pg_dump is now doingunsigned comparisons of OIDs, it is now *necessary* that we play bythe rules here. In fact, given that btoidcmp() has been doing unsignedcomparison for quite some time, it seems likely that we have index-corruption problems in 7.0 and before once the Oid counter goes past2G. Fixing these operators is a necessary step before we can thinkabout 8-byte Oid, too.
1 parent01f2547 commit93fcbd1

File tree

7 files changed

+171
-100
lines changed

7 files changed

+171
-100
lines changed

‎src/backend/utils/adt/oid.c

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.38 2000/08/01 18:29:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.39 2000/11/21 03:23:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -43,7 +43,7 @@ oidvectorin(PG_FUNCTION_ARGS)
4343
break;
4444
while (*oidString&&isspace((int)*oidString))
4545
oidString++;
46-
while (*oidString&&!isspace((int)*oidString))
46+
while (*oidString&&isdigit((int)*oidString))
4747
oidString++;
4848
}
4949
while (*oidString&&isspace((int)*oidString))
@@ -79,7 +79,7 @@ oidvectorout(PG_FUNCTION_ARGS)
7979
{
8080
if (num!=0)
8181
*rp++=' ';
82-
pg_ltoa((int32)oidArray[num],rp);
82+
sprintf(rp,"%u",oidArray[num]);
8383
while (*++rp!='\0')
8484
;
8585
}
@@ -91,18 +91,43 @@ Datum
9191
oidin(PG_FUNCTION_ARGS)
9292
{
9393
char*s=PG_GETARG_CSTRING(0);
94+
unsigned longcvt;
95+
char*endptr;
96+
Oidresult;
9497

95-
/* XXX should use an unsigned-int conversion here */
96-
returnDirectFunctionCall1(int4in,CStringGetDatum(s));
98+
errno=0;
99+
100+
cvt=strtoul(s,&endptr,10);
101+
102+
/*
103+
* strtoul() normally only sets ERANGE. On some systems it also
104+
* may set EINVAL, which simply means it couldn't parse the
105+
* input string. This is handled by the second "if" consistent
106+
* across platforms.
107+
*/
108+
if (errno&&errno!=EINVAL)
109+
elog(ERROR,"oidin: error reading \"%s\": %m",s);
110+
if (endptr&&*endptr)
111+
elog(ERROR,"oidin: error in \"%s\": can't parse \"%s\"",s,endptr);
112+
113+
/*
114+
* Cope with possibility that unsigned long is wider than Oid.
115+
*/
116+
result= (Oid)cvt;
117+
if ((unsigned long)result!=cvt)
118+
elog(ERROR,"oidin: error reading \"%s\": value too large",s);
119+
120+
returnObjectIdGetDatum(result);
97121
}
98122

99123
Datum
100124
oidout(PG_FUNCTION_ARGS)
101125
{
102126
Oido=PG_GETARG_OID(0);
127+
char*result= (char*)palloc(12);
103128

104-
/* XXX should use an unsigned-int conversion here */
105-
returnDirectFunctionCall1(int4out,ObjectIdGetDatum(o));
129+
snprintf(result,12,"%u",o);
130+
PG_RETURN_CSTRING(result);
106131
}
107132

108133
/*****************************************************************************
@@ -127,6 +152,42 @@ oidne(PG_FUNCTION_ARGS)
127152
PG_RETURN_BOOL(arg1!=arg2);
128153
}
129154

155+
Datum
156+
oidlt(PG_FUNCTION_ARGS)
157+
{
158+
Oidarg1=PG_GETARG_OID(0);
159+
Oidarg2=PG_GETARG_OID(1);
160+
161+
PG_RETURN_BOOL(arg1<arg2);
162+
}
163+
164+
Datum
165+
oidle(PG_FUNCTION_ARGS)
166+
{
167+
Oidarg1=PG_GETARG_OID(0);
168+
Oidarg2=PG_GETARG_OID(1);
169+
170+
PG_RETURN_BOOL(arg1 <=arg2);
171+
}
172+
173+
Datum
174+
oidge(PG_FUNCTION_ARGS)
175+
{
176+
Oidarg1=PG_GETARG_OID(0);
177+
Oidarg2=PG_GETARG_OID(1);
178+
179+
PG_RETURN_BOOL(arg1 >=arg2);
180+
}
181+
182+
Datum
183+
oidgt(PG_FUNCTION_ARGS)
184+
{
185+
Oidarg1=PG_GETARG_OID(0);
186+
Oidarg2=PG_GETARG_OID(1);
187+
188+
PG_RETURN_BOOL(arg1>arg2);
189+
}
190+
130191
Datum
131192
oidvectoreq(PG_FUNCTION_ARGS)
132193
{
@@ -197,26 +258,6 @@ oidvectorgt(PG_FUNCTION_ARGS)
197258
PG_RETURN_BOOL(false);
198259
}
199260

200-
Datum
201-
oideqint4(PG_FUNCTION_ARGS)
202-
{
203-
Oidarg1=PG_GETARG_OID(0);
204-
int32arg2=PG_GETARG_INT32(1);
205-
206-
/* oid is unsigned, but int4 is signed */
207-
PG_RETURN_BOOL(arg2 >=0&&arg1==arg2);
208-
}
209-
210-
Datum
211-
int4eqoid(PG_FUNCTION_ARGS)
212-
{
213-
int32arg1=PG_GETARG_INT32(0);
214-
Oidarg2=PG_GETARG_OID(1);
215-
216-
/* oid is unsigned, but int4 is signed */
217-
PG_RETURN_BOOL(arg1 >=0&&arg1==arg2);
218-
}
219-
220261
Datum
221262
oid_text(PG_FUNCTION_ARGS)
222263
{

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.62 2000/11/20 20:36:50 tgl Exp $
40+
* $Id: catversion.h,v 1.63 2000/11/21 03:23:19 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#defineCATALOG_VERSION_NO200011201
56+
#defineCATALOG_VERSION_NO200011211
5757

5858
#endif

‎src/include/catalog/pg_operator.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_operator.h,v 1.83 2000/10/24 20:15:45 petere Exp $
11+
* $Id: pg_operator.h,v 1.84 2000/11/21 03:23:19 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -280,10 +280,10 @@ DATA(insert OID = 606 ( "<#>" PGUID 0 b t f 702 702 7040 0 0 0 mktinte
280280
DATA(insertOID=607 ("="PGUID0btt262616607608609609oideqeqseleqjoinsel ));
281281
#defineMIN_OIDCMP 607/* used by cache code */
282282
DATA(insertOID=608 ("<>"PGUID0btf26261660860700oidneneqselneqjoinsel ));
283-
DATA(insertOID=609 ("<"PGUID0btf26261661061200int4ltscalarltselscalarltjoinsel ));
284-
DATA(insertOID=610 (">"PGUID0btf26261660961100int4gtscalargtselscalargtjoinsel ));
285-
DATA(insertOID=611 ("<="PGUID0btf26261661261000int4lescalarltselscalarltjoinsel ));
286-
DATA(insertOID=612 (">="PGUID0btf26261661160900int4gescalargtselscalargtjoinsel ));
283+
DATA(insertOID=609 ("<"PGUID0btf26261661061200oidltscalarltselscalarltjoinsel ));
284+
DATA(insertOID=610 (">"PGUID0btf26261660961100oidgtscalargtselscalargtjoinsel ));
285+
DATA(insertOID=611 ("<="PGUID0btf26261661261000oidlescalarltselscalarltjoinsel ));
286+
DATA(insertOID=612 (">="PGUID0btf26261661160900oidgescalargtselscalargtjoinsel ));
287287
#defineMAX_OIDCMP 612/* used by cache code */
288288

289289
DATA(insertOID=644 ("<>"PGUID0btf30301664464900oidvectorneneqselneqjoinsel ));
@@ -516,9 +516,9 @@ DATA(insert OID = 1133 ( ">"PGUID 0 b t f 701700 16 1122 1134 0 0 float84
516516
DATA(insertOID=1134 ("<="PGUID0btf701700161125113300float84lescalarltselscalarltjoinsel ));
517517
DATA(insertOID=1135 (">="PGUID0btf701700161124113200float84gescalargtselscalargtjoinsel ));
518518

519-
/* int4and oid equality */
520-
DATA(insertOID=1136 ("="PGUID0btt2326161137000int4eqoideqseleqjoinsel ));
521-
DATA(insertOID=1137 ("="PGUID0btt2623161136000oideqint4eqseleqjoinsel ));
519+
/* int4vs oid equality --- use oid (unsigned) comparison */
520+
DATA(insertOID=1136 ("="PGUID0btt2326161137165600oideqeqseleqjoinsel ));
521+
DATA(insertOID=1137 ("="PGUID0btt2623161136166100oideqeqseleqjoinsel ));
522522

523523
DATA(insertOID=1158 ("!"PGUID0rtf210230000int2fac-- ));
524524
DATA(insertOID=1175 ("!!"PGUID0ltf021230000int2fac-- ));
@@ -704,6 +704,18 @@ DATA(insert OID = 1631 ( "~~*" PGUID 0 b t f 1043 25 16 0 1632 0 0 texticli
704704
#defineOID_VARCHAR_ICLIKE_OP1631
705705
DATA(insertOID=1632 ("!~~*"PGUID0btf104325160163100texticnlikeicnlikeselicnlikejoinsel ));
706706

707+
/* int4 vs oid comparisons --- use oid (unsigned) comparison */
708+
DATA(insertOID=1656 ("<>"PGUID0btf2326161661113600oidneneqselneqjoinsel ));
709+
DATA(insertOID=1657 ("<"PGUID0btf2326161663166000oidltscalarltselscalarltjoinsel ));
710+
DATA(insertOID=1658 (">"PGUID0btf2326161662165900oidgtscalargtselscalargtjoinsel ));
711+
DATA(insertOID=1659 ("<="PGUID0btf2326161665165800oidlescalarltselscalarltjoinsel ));
712+
DATA(insertOID=1660 (">="PGUID0btf2326161664165700oidgescalargtselscalargtjoinsel ));
713+
DATA(insertOID=1661 ("<>"PGUID0btf2623161656113700oidneneqselneqjoinsel ));
714+
DATA(insertOID=1662 ("<"PGUID0btf2623161658166500oidltscalarltselscalarltjoinsel ));
715+
DATA(insertOID=1663 (">"PGUID0btf2623161657166400oidgtscalargtselscalargtjoinsel ));
716+
DATA(insertOID=1664 ("<="PGUID0btf2623161660166300oidlescalarltselscalarltjoinsel ));
717+
DATA(insertOID=1665 (">="PGUID0btf2623161659166200oidgescalargtselscalargtjoinsel ));
718+
707719
/* NUMERIC type - OID's 1700-1799 */
708720
DATA(insertOID=1751 ("-"PGUID0ltf0170017000000numeric_uminus-- ));
709721
DATA(insertOID=1752 ("="PGUID0btf17001700161752175317541754numeric_eqeqseleqjoinsel ));

‎src/include/catalog/pg_proc.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.174 2000/11/11 19:55:33 thomas Exp $
10+
* $Id: pg_proc.h,v 1.175 2000/11/21 03:23:19 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -936,10 +936,10 @@ DATA(insert OID = 713 ( oidrand PGUID 12 f t f t 2 f 16 "26 23" 100 0 0 100
936936
DESCR("random");
937937
DATA(insertOID=715 (oidsrandPGUID12ftft1f16"23"10000100oidsrand- ));
938938
DESCR("seed random number generator");
939-
DATA(insertOID=716 (oideqint4PGUID12fttt2f16"2623"10000100oideqint4- ));
940-
DESCR("equal");
941-
DATA(insertOID=717 (int4eqoidPGUID12fttt2f16"23 26"10000100int4eqoid- ));
942-
DESCR("equal");
939+
DATA(insertOID=716 (oidltPGUID12fttt2f16"2626"10000100oidlt- ));
940+
DESCR("less-than");
941+
DATA(insertOID=717 (oidlePGUID12fttt2f16"26 26"10000100oidle- ));
942+
DESCR("less-than-or-equal");
943943

944944
DATA(insertOID=720 (octet_lengthPGUID12fttt1f23"17"10000100byteaoctetlen- ));
945945
DESCR("octet length");
@@ -2128,6 +2128,11 @@ DESCR("convert encoding name to encoding id");
21282128
DATA(insertOID=1597 (pg_encoding_to_charPGUID12ftft1f19"23"10000100PG_encoding_to_char- ));
21292129
DESCR("convert encoding id to encoding name");
21302130

2131+
DATA(insertOID=1638 (oidgtPGUID12fttt2f16"26 26"10000100oidgt- ));
2132+
DESCR("greater-than");
2133+
DATA(insertOID=1639 (oidgePGUID12fttt2f16"26 26"10000100oidge- ));
2134+
DESCR("greater-than-or-equal");
2135+
21312136
/* System-view support functions */
21322137
DATA(insertOID=1640 (pg_get_ruledefPGUID12ftft1f25"19"10000100pg_get_ruledef- ));
21332138
DESCR("source text of a rule");

‎src/include/utils/builtins.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.141 2000/11/10 20:13:26 tgl Exp $
10+
* $Id: builtins.h,v 1.142 2000/11/21 03:23:20 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -283,22 +283,24 @@ extern Datum int4notin(PG_FUNCTION_ARGS);
283283
externDatumoidnotin(PG_FUNCTION_ARGS);
284284

285285
/* oid.c */
286-
externDatumoidvectorin(PG_FUNCTION_ARGS);
287-
externDatumoidvectorout(PG_FUNCTION_ARGS);
288286
externDatumoidin(PG_FUNCTION_ARGS);
289287
externDatumoidout(PG_FUNCTION_ARGS);
290288
externDatumoideq(PG_FUNCTION_ARGS);
291289
externDatumoidne(PG_FUNCTION_ARGS);
290+
externDatumoidlt(PG_FUNCTION_ARGS);
291+
externDatumoidle(PG_FUNCTION_ARGS);
292+
externDatumoidge(PG_FUNCTION_ARGS);
293+
externDatumoidgt(PG_FUNCTION_ARGS);
294+
externDatumoid_text(PG_FUNCTION_ARGS);
295+
externDatumtext_oid(PG_FUNCTION_ARGS);
296+
externDatumoidvectorin(PG_FUNCTION_ARGS);
297+
externDatumoidvectorout(PG_FUNCTION_ARGS);
292298
externDatumoidvectoreq(PG_FUNCTION_ARGS);
293299
externDatumoidvectorne(PG_FUNCTION_ARGS);
294300
externDatumoidvectorlt(PG_FUNCTION_ARGS);
295301
externDatumoidvectorle(PG_FUNCTION_ARGS);
296302
externDatumoidvectorge(PG_FUNCTION_ARGS);
297303
externDatumoidvectorgt(PG_FUNCTION_ARGS);
298-
externDatumoideqint4(PG_FUNCTION_ARGS);
299-
externDatumint4eqoid(PG_FUNCTION_ARGS);
300-
externDatumoid_text(PG_FUNCTION_ARGS);
301-
externDatumtext_oid(PG_FUNCTION_ARGS);
302304

303305
/* regexp.c */
304306
externDatumnameregexeq(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp