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

Commitc590273

Browse files
committed
Clean up bogosities in pg_opclass, pg_amop, pg_amproc. There are amproc
entries now for int8 and network hash indexes. int24_ops and int42_opsare gone. pg_opclass no longer contains multiple entries claiming to bethe default opclass for the same datatype. opr_sanity regress testextended to catch errors like these in the future.
1 parenta53dc5e commitc590273

File tree

19 files changed

+269
-354
lines changed

19 files changed

+269
-354
lines changed

‎doc/src/sgml/indices.sgml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,6 @@
130130
<literal>bigbox_ops</literal>.
131131
</para>
132132
</listitem>
133-
134-
<listitem>
135-
<para>
136-
The <literal>int24_ops</literal>
137-
operator class is useful for constructing indices on int2 data, and
138-
doing comparisons against int4 data in query qualifications.
139-
Similarly, <literal>int42_ops</literal>
140-
support indices on int4 data that is to be compared against int2 data
141-
in queries.
142-
</para>
143-
</listitem>
144133
</itemizedlist>
145134
</para>
146135

‎doc/src/sgml/ref/create_index.sgml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.13 2000/05/02 20:02:03 thomas Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.14 2000/06/19 03:54:15 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -312,17 +312,6 @@ ERROR: Cannot create index: 'index_name' already exists.
312312
<literal>bigbox_ops</literal>.
313313
</para>
314314
</listitem>
315-
316-
<listitem>
317-
<para>
318-
The <literal>int24_ops</literal>
319-
operator class is useful for constructing indices on int2 data, and
320-
doing comparisons against int4 data in query qualifications.
321-
Similarly, <literal>int42_ops</literal>
322-
support indices on int4 data that is to be compared against int2 data
323-
in queries.
324-
</para>
325-
</listitem>
326315
</itemizedlist>
327316
</para>
328317

‎src/backend/access/hash/hashfunc.c

Lines changed: 41 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.26 2000/06/05 07:28:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.27 2000/06/19 03:54:17 tgl Exp $
1212
*
1313
* NOTES
1414
* These functions are stored in pg_amproc.For each operator class
@@ -21,10 +21,17 @@
2121

2222
#include"access/hash.h"
2323

24+
25+
Datum
26+
hashchar(PG_FUNCTION_ARGS)
27+
{
28+
PG_RETURN_UINT32(~ ((uint32)PG_GETARG_CHAR(0)));
29+
}
30+
2431
Datum
2532
hashint2(PG_FUNCTION_ARGS)
2633
{
27-
PG_RETURN_UINT32((uint32)~PG_GETARG_INT16(0));
34+
PG_RETURN_UINT32(~ ((uint32)PG_GETARG_INT16(0)));
2835
}
2936

3037
Datum
@@ -37,116 +44,37 @@ Datum
3744
hashint8(PG_FUNCTION_ARGS)
3845
{
3946
/* we just use the low 32 bits... */
40-
PG_RETURN_UINT32(~((uint32)PG_GETARG_INT64(0)));
47+
PG_RETURN_UINT32(~ ((uint32)PG_GETARG_INT64(0)));
48+
}
49+
50+
Datum
51+
hashoid(PG_FUNCTION_ARGS)
52+
{
53+
PG_RETURN_UINT32(~ ((uint32)PG_GETARG_OID(0)));
4154
}
4255

43-
/* Hash function from Chris Torek. */
4456
Datum
4557
hashfloat4(PG_FUNCTION_ARGS)
4658
{
4759
float4key=PG_GETARG_FLOAT4(0);
48-
char*kp= (char*)&key;
49-
intlen=sizeof(key);
50-
intloop;
51-
uint32h;
52-
53-
#defineHASH4a h = (h << 5) - h + *kp++;
54-
#defineHASH4b h = (h << 5) + h + *kp++;
55-
#defineHASH4 HASH4b
56-
57-
h=0;
58-
/*
59-
* This is a tad silly, given that we expect len = 4, but a smart
60-
* compiler should be able to eliminate the redundant code...
61-
*/
62-
loop= (len+8-1) >>3;
6360

64-
switch (len& (8-1))
65-
{
66-
case0:
67-
do
68-
{/* All fall throughs */
69-
HASH4;
70-
case7:
71-
HASH4;
72-
case6:
73-
HASH4;
74-
case5:
75-
HASH4;
76-
case4:
77-
HASH4;
78-
case3:
79-
HASH4;
80-
case2:
81-
HASH4;
82-
case1:
83-
HASH4;
84-
}while (--loop);
85-
}
86-
PG_RETURN_UINT32(h);
61+
returnhash_any((char*)&key,sizeof(key));
8762
}
8863

8964
Datum
9065
hashfloat8(PG_FUNCTION_ARGS)
9166
{
9267
float8key=PG_GETARG_FLOAT8(0);
93-
char*kp= (char*)&key;
94-
intlen=sizeof(key);
95-
intloop;
96-
uint32h;
9768

98-
#defineHASH4a h = (h << 5) - h + *kp++;
99-
#defineHASH4b h = (h << 5) + h + *kp++;
100-
#defineHASH4 HASH4b
101-
102-
h=0;
103-
/*
104-
* This is a tad silly, given that we expect len = 8, but a smart
105-
* compiler should be able to eliminate the redundant code...
106-
*/
107-
loop= (len+8-1) >>3;
108-
109-
switch (len& (8-1))
110-
{
111-
case0:
112-
do
113-
{/* All fall throughs */
114-
HASH4;
115-
case7:
116-
HASH4;
117-
case6:
118-
HASH4;
119-
case5:
120-
HASH4;
121-
case4:
122-
HASH4;
123-
case3:
124-
HASH4;
125-
case2:
126-
HASH4;
127-
case1:
128-
HASH4;
129-
}while (--loop);
130-
}
131-
PG_RETURN_UINT32(h);
132-
}
133-
134-
Datum
135-
hashoid(PG_FUNCTION_ARGS)
136-
{
137-
PG_RETURN_UINT32(~(uint32)PG_GETARG_OID(0));
69+
returnhash_any((char*)&key,sizeof(key));
13870
}
13971

14072
Datum
14173
hashoidvector(PG_FUNCTION_ARGS)
14274
{
14375
Oid*key= (Oid*)PG_GETARG_POINTER(0);
144-
inti;
145-
uint32result=0;
14676

147-
for (i=INDEX_MAX_KEYS;--i >=0;)
148-
result= (result <<1) ^ (~(uint32)key[i]);
149-
PG_RETURN_UINT32(result);
77+
returnhash_any((char*)key,INDEX_MAX_KEYS*sizeof(Oid));
15078
}
15179

15280
/*
@@ -158,69 +86,53 @@ Datum
15886
hashint2vector(PG_FUNCTION_ARGS)
15987
{
16088
int16*key= (int16*)PG_GETARG_POINTER(0);
161-
inti;
162-
uint32result=0;
16389

164-
for (i=INDEX_MAX_KEYS;--i >=0;)
165-
result= (result <<1) ^ (~(uint32)key[i]);
166-
PG_RETURN_UINT32(result);
90+
returnhash_any((char*)key,INDEX_MAX_KEYS*sizeof(int16));
16791
}
16892

169-
170-
#definePRIME137
171-
#definePRIME21048583
172-
17393
Datum
174-
hashchar(PG_FUNCTION_ARGS)
94+
hashname(PG_FUNCTION_ARGS)
17595
{
176-
uint32h;
177-
178-
/* Convert char to integer */
179-
h= (PG_GETARG_CHAR(0)-' ');
180-
h %=PRIME2;
96+
char*key=NameStr(*PG_GETARG_NAME(0));
18197

182-
PG_RETURN_UINT32(h);
98+
returnhash_any((char*)key,NAMEDATALEN);
18399
}
184100

101+
/*
102+
* hashvarlena() can be used for any varlena datatype in which there are
103+
* no non-significant bits, ie, distinct bitpatterns never compare as equal.
104+
*/
185105
Datum
186-
hashname(PG_FUNCTION_ARGS)
106+
hashvarlena(PG_FUNCTION_ARGS)
187107
{
188-
char*key=NameStr(*PG_GETARG_NAME(0));
189-
intlen=NAMEDATALEN;
190-
uint32h;
108+
structvarlena*key=PG_GETARG_VARLENA_P(0);
191109

192-
h=0;
193-
/* Convert string to integer */
194-
while (len--)
195-
h=h*PRIME1 ^ (*key++-' ');
196-
h %=PRIME2;
197-
198-
PG_RETURN_UINT32(h);
110+
returnhash_any(VARDATA(key),VARSIZE(key)-VARHDRSZ);
199111
}
200112

113+
201114
/*
115+
* hash_any --- compute a hash function for any specified chunk of memory
116+
*
117+
* This can be used as the underlying hash function for any pass-by-reference
118+
* data type in which there are no non-significant bits.
119+
*
202120
* (Comment from the original db3 hashing code: )
203121
*
204122
* "This is INCREDIBLY ugly, but fast. We break the string up into 8 byte
205123
* units. On the first time through the loop we get the 'leftover bytes'
206-
* (strlen % 8). On everyother iteration, we perform 8 HASHC's so we handle
124+
* (strlen % 8). On everylater iteration, we perform 8 HASHC's so we handle
207125
* all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If
208126
* this routine is heavily used enough, it's worth the ugly coding.
209127
*
210128
* "OZ's original sdbm hash"
211129
*/
212130
Datum
213-
hashtext(PG_FUNCTION_ARGS)
131+
hash_any(char*keydata,intkeylen)
214132
{
215-
text*key=PG_GETARG_TEXT_P(0);
216-
intkeylen;
217-
char*keydata;
218133
uint32n;
219134
intloop;
220135

221-
keydata=VARDATA(key);
222-
keylen=VARSIZE(key)-VARHDRSZ;
223-
224136
#defineHASHCn = *keydata++ + 65599 * n
225137

226138
n=0;
@@ -251,5 +163,8 @@ hashtext(PG_FUNCTION_ARGS)
251163
}while (--loop);
252164
}
253165
}
166+
167+
#undef HASHC
168+
254169
PG_RETURN_UINT32(n);
255170
}

‎src/backend/access/nbtree/nbtcompare.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.37 2000/06/15 03:31:54 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.38 2000/06/19 03:54:22 tgl Exp $
1212
*
1313
* NOTES
1414
*
@@ -81,34 +81,6 @@ btint8cmp(PG_FUNCTION_ARGS)
8181
PG_RETURN_INT32(-1);
8282
}
8383

84-
Datum
85-
btint24cmp(PG_FUNCTION_ARGS)
86-
{
87-
int16a=PG_GETARG_INT16(0);
88-
int32b=PG_GETARG_INT32(1);
89-
90-
if (a>b)
91-
PG_RETURN_INT32(1);
92-
elseif (a==b)
93-
PG_RETURN_INT32(0);
94-
else
95-
PG_RETURN_INT32(-1);
96-
}
97-
98-
Datum
99-
btint42cmp(PG_FUNCTION_ARGS)
100-
{
101-
int32a=PG_GETARG_INT32(0);
102-
int16b=PG_GETARG_INT16(1);
103-
104-
if (a>b)
105-
PG_RETURN_INT32(1);
106-
elseif (a==b)
107-
PG_RETURN_INT32(0);
108-
else
109-
PG_RETURN_INT32(-1);
110-
}
111-
11284
Datum
11385
btfloat4cmp(PG_FUNCTION_ARGS)
11486
{

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.47 2000/06/15 04:10:23 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.48 2000/06/19 03:54:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15-
#include<limits.h>
16-
#include<time.h>
1715

1816
#include"postgres.h"
17+
18+
#include<limits.h>
19+
#include<time.h>
1920
#ifdefHAVE_FLOAT_H
2021
#include<float.h>
2122
#endif
23+
24+
#include"access/hash.h"
2225
#include"miscadmin.h"
2326
#include"utils/date.h"
2427
#include"utils/nabstime.h"
2528

26-
staticint
27-
date2tm(DateADTdateVal,int*tzp,structtm*tm,double*fsec,char**tzn);
29+
30+
staticintdate2tm(DateADTdateVal,int*tzp,structtm*tm,
31+
double*fsec,char**tzn);
2832

2933

3034
/*****************************************************************************
@@ -762,6 +766,22 @@ timetz_cmp(PG_FUNCTION_ARGS)
762766
PG_RETURN_INT32(0);
763767
}
764768

769+
/*
770+
* timetz, being an unusual size, needs a specialized hash function.
771+
*/
772+
Datum
773+
timetz_hash(PG_FUNCTION_ARGS)
774+
{
775+
TimeTzADT*key=PG_GETARG_TIMETZADT_P(0);
776+
777+
/*
778+
* Specify hash length as sizeof(double) + sizeof(int4), not as
779+
* sizeof(TimeTzADT), so that any garbage pad bytes in the structure
780+
* won't be included in the hash!
781+
*/
782+
returnhash_any((char*)key,sizeof(double)+sizeof(int4));
783+
}
784+
765785
Datum
766786
timetz_larger(PG_FUNCTION_ARGS)
767787
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp