Skip to content

Commit 93fcbd1

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

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 long cvt;
95+
char *endptr;
96+
Oid result;
9497

95-
/* XXX should use an unsigned-int conversion here */
96-
return DirectFunctionCall1(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+
return ObjectIdGetDatum(result);
97121
}
98122

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

104-
/* XXX should use an unsigned-int conversion here */
105-
return DirectFunctionCall1(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+
Oid arg1 = PG_GETARG_OID(0);
159+
Oid arg2 = PG_GETARG_OID(1);
160+
161+
PG_RETURN_BOOL(arg1 < arg2);
162+
}
163+
164+
Datum
165+
oidle(PG_FUNCTION_ARGS)
166+
{
167+
Oid arg1 = PG_GETARG_OID(0);
168+
Oid arg2 = PG_GETARG_OID(1);
169+
170+
PG_RETURN_BOOL(arg1 <= arg2);
171+
}
172+
173+
Datum
174+
oidge(PG_FUNCTION_ARGS)
175+
{
176+
Oid arg1 = PG_GETARG_OID(0);
177+
Oid arg2 = PG_GETARG_OID(1);
178+
179+
PG_RETURN_BOOL(arg1 >= arg2);
180+
}
181+
182+
Datum
183+
oidgt(PG_FUNCTION_ARGS)
184+
{
185+
Oid arg1 = PG_GETARG_OID(0);
186+
Oid arg2 = 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-
Oid arg1 = PG_GETARG_OID(0);
204-
int32 arg2 = 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-
int32 arg1 = PG_GETARG_INT32(0);
214-
Oid arg2 = 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-
#define CATALOG_VERSION_NO 200011201
56+
#define CATALOG_VERSION_NO 200011211
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 704 0 0 0 0 mktinte
280280
DATA(insert OID = 607 ( "=" PGUID 0 b t t 26 26 16 607 608 609 609 oideq eqsel eqjoinsel ));
281281
#define MIN_OIDCMP 607 /* used by cache code */
282282
DATA(insert OID = 608 ( "<>" PGUID 0 b t f 26 26 16 608 607 0 0 oidne neqsel neqjoinsel ));
283-
DATA(insert OID = 609 ( "<" PGUID 0 b t f 26 26 16 610 612 0 0 int4lt scalarltsel scalarltjoinsel ));
284-
DATA(insert OID = 610 ( ">" PGUID 0 b t f 26 26 16 609 611 0 0 int4gt scalargtsel scalargtjoinsel ));
285-
DATA(insert OID = 611 ( "<=" PGUID 0 b t f 26 26 16 612 610 0 0 int4le scalarltsel scalarltjoinsel ));
286-
DATA(insert OID = 612 ( ">=" PGUID 0 b t f 26 26 16 611 609 0 0 int4ge scalargtsel scalargtjoinsel ));
283+
DATA(insert OID = 609 ( "<" PGUID 0 b t f 26 26 16 610 612 0 0 oidlt scalarltsel scalarltjoinsel ));
284+
DATA(insert OID = 610 ( ">" PGUID 0 b t f 26 26 16 609 611 0 0 oidgt scalargtsel scalargtjoinsel ));
285+
DATA(insert OID = 611 ( "<=" PGUID 0 b t f 26 26 16 612 610 0 0 oidle scalarltsel scalarltjoinsel ));
286+
DATA(insert OID = 612 ( ">=" PGUID 0 b t f 26 26 16 611 609 0 0 oidge scalargtsel scalargtjoinsel ));
287287
#define MAX_OIDCMP 612 /* used by cache code */
288288

289289
DATA(insert OID = 644 ( "<>" PGUID 0 b t f 30 30 16 644 649 0 0 oidvectorne neqsel neqjoinsel ));
@@ -516,9 +516,9 @@ DATA(insert OID = 1133 ( ">" PGUID 0 b t f 701 700 16 1122 1134 0 0 float84
516516
DATA(insert OID = 1134 ( "<=" PGUID 0 b t f 701 700 16 1125 1133 0 0 float84le scalarltsel scalarltjoinsel ));
517517
DATA(insert OID = 1135 ( ">=" PGUID 0 b t f 701 700 16 1124 1132 0 0 float84ge scalargtsel scalargtjoinsel ));
518518

519-
/* int4 and oid equality */
520-
DATA(insert OID = 1136 ( "=" PGUID 0 b t t 23 26 16 1137 0 0 0 int4eqoid eqsel eqjoinsel ));
521-
DATA(insert OID = 1137 ( "=" PGUID 0 b t t 26 23 16 1136 0 0 0 oideqint4 eqsel eqjoinsel ));
519+
/* int4 vs oid equality --- use oid (unsigned) comparison */
520+
DATA(insert OID = 1136 ( "=" PGUID 0 b t t 23 26 16 1137 1656 0 0 oideq eqsel eqjoinsel ));
521+
DATA(insert OID = 1137 ( "=" PGUID 0 b t t 26 23 16 1136 1661 0 0 oideq eqsel eqjoinsel ));
522522

523523
DATA(insert OID = 1158 ( "!" PGUID 0 r t f 21 0 23 0 0 0 0 int2fac - - ));
524524
DATA(insert OID = 1175 ( "!!" PGUID 0 l t f 0 21 23 0 0 0 0 int2fac - - ));
@@ -704,6 +704,18 @@ DATA(insert OID = 1631 ( "~~*" PGUID 0 b t f 1043 25 16 0 1632 0 0 texticli
704704
#define OID_VARCHAR_ICLIKE_OP 1631
705705
DATA(insert OID = 1632 ( "!~~*" PGUID 0 b t f 1043 25 16 0 1631 0 0 texticnlike icnlikesel icnlikejoinsel ));
706706

707+
/* int4 vs oid comparisons --- use oid (unsigned) comparison */
708+
DATA(insert OID = 1656 ( "<>" PGUID 0 b t f 23 26 16 1661 1136 0 0 oidne neqsel neqjoinsel ));
709+
DATA(insert OID = 1657 ( "<" PGUID 0 b t f 23 26 16 1663 1660 0 0 oidlt scalarltsel scalarltjoinsel ));
710+
DATA(insert OID = 1658 ( ">" PGUID 0 b t f 23 26 16 1662 1659 0 0 oidgt scalargtsel scalargtjoinsel ));
711+
DATA(insert OID = 1659 ( "<=" PGUID 0 b t f 23 26 16 1665 1658 0 0 oidle scalarltsel scalarltjoinsel ));
712+
DATA(insert OID = 1660 ( ">=" PGUID 0 b t f 23 26 16 1664 1657 0 0 oidge scalargtsel scalargtjoinsel ));
713+
DATA(insert OID = 1661 ( "<>" PGUID 0 b t f 26 23 16 1656 1137 0 0 oidne neqsel neqjoinsel ));
714+
DATA(insert OID = 1662 ( "<" PGUID 0 b t f 26 23 16 1658 1665 0 0 oidlt scalarltsel scalarltjoinsel ));
715+
DATA(insert OID = 1663 ( ">" PGUID 0 b t f 26 23 16 1657 1664 0 0 oidgt scalargtsel scalargtjoinsel ));
716+
DATA(insert OID = 1664 ( "<=" PGUID 0 b t f 26 23 16 1660 1663 0 0 oidle scalarltsel scalarltjoinsel ));
717+
DATA(insert OID = 1665 ( ">=" PGUID 0 b t f 26 23 16 1659 1662 0 0 oidge scalargtsel scalargtjoinsel ));
718+
707719
/* NUMERIC type - OID's 1700-1799 */
708720
DATA(insert OID = 1751 ( "-" PGUID 0 l t f 0 1700 1700 0 0 0 0 numeric_uminus - - ));
709721
DATA(insert OID = 1752 ( "=" PGUID 0 b t f 1700 1700 16 1752 1753 1754 1754 numeric_eq eqsel eqjoinsel ));

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(insert OID = 715 ( oidsrand PGUID 12 f t f t 1 f 16 "23" 100 0 0 100 oidsrand - ));
938938
DESCR("seed random number generator");
939-
DATA(insert OID = 716 ( oideqint4 PGUID 12 f t t t 2 f 16 "26 23" 100 0 0 100 oideqint4 - ));
940-
DESCR("equal");
941-
DATA(insert OID = 717 ( int4eqoid PGUID 12 f t t t 2 f 16 "23 26" 100 0 0 100 int4eqoid - ));
942-
DESCR("equal");
939+
DATA(insert OID = 716 ( oidlt PGUID 12 f t t t 2 f 16 "26 26" 100 0 0 100 oidlt - ));
940+
DESCR("less-than");
941+
DATA(insert OID = 717 ( oidle PGUID 12 f t t t 2 f 16 "26 26" 100 0 0 100 oidle - ));
942+
DESCR("less-than-or-equal");
943943

944944
DATA(insert OID = 720 ( octet_length PGUID 12 f t t t 1 f 23 "17" 100 0 0 100 byteaoctetlen - ));
945945
DESCR("octet length");
@@ -2128,6 +2128,11 @@ DESCR("convert encoding name to encoding id");
21282128
DATA(insert OID = 1597 ( pg_encoding_to_char PGUID 12 f t f t 1 f 19 "23" 100 0 0 100 PG_encoding_to_char - ));
21292129
DESCR("convert encoding id to encoding name");
21302130

2131+
DATA(insert OID = 1638 ( oidgt PGUID 12 f t t t 2 f 16 "26 26" 100 0 0 100 oidgt - ));
2132+
DESCR("greater-than");
2133+
DATA(insert OID = 1639 ( oidge PGUID 12 f t t t 2 f 16 "26 26" 100 0 0 100 oidge - ));
2134+
DESCR("greater-than-or-equal");
2135+
21312136
/* System-view support functions */
21322137
DATA(insert OID = 1640 ( pg_get_ruledef PGUID 12 f t f t 1 f 25 "19" 100 0 0 100 pg_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
extern Datum oidnotin(PG_FUNCTION_ARGS);
284284

285285
/* oid.c */
286-
extern Datum oidvectorin(PG_FUNCTION_ARGS);
287-
extern Datum oidvectorout(PG_FUNCTION_ARGS);
288286
extern Datum oidin(PG_FUNCTION_ARGS);
289287
extern Datum oidout(PG_FUNCTION_ARGS);
290288
extern Datum oideq(PG_FUNCTION_ARGS);
291289
extern Datum oidne(PG_FUNCTION_ARGS);
290+
extern Datum oidlt(PG_FUNCTION_ARGS);
291+
extern Datum oidle(PG_FUNCTION_ARGS);
292+
extern Datum oidge(PG_FUNCTION_ARGS);
293+
extern Datum oidgt(PG_FUNCTION_ARGS);
294+
extern Datum oid_text(PG_FUNCTION_ARGS);
295+
extern Datum text_oid(PG_FUNCTION_ARGS);
296+
extern Datum oidvectorin(PG_FUNCTION_ARGS);
297+
extern Datum oidvectorout(PG_FUNCTION_ARGS);
292298
extern Datum oidvectoreq(PG_FUNCTION_ARGS);
293299
extern Datum oidvectorne(PG_FUNCTION_ARGS);
294300
extern Datum oidvectorlt(PG_FUNCTION_ARGS);
295301
extern Datum oidvectorle(PG_FUNCTION_ARGS);
296302
extern Datum oidvectorge(PG_FUNCTION_ARGS);
297303
extern Datum oidvectorgt(PG_FUNCTION_ARGS);
298-
extern Datum oideqint4(PG_FUNCTION_ARGS);
299-
extern Datum int4eqoid(PG_FUNCTION_ARGS);
300-
extern Datum oid_text(PG_FUNCTION_ARGS);
301-
extern Datum text_oid(PG_FUNCTION_ARGS);
302304

303305
/* regexp.c */
304306
extern Datum nameregexeq(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy