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

Commit0144eb9

Browse files
committed
Add the full set of comparison functions for type TID, including a btree
opclass. This is not so much because anyone's likely to create an indexon TID, as that sorting TIDs can be useful. Also added max and minaggregates while at it, so that one can investigate the clusteredness ofa table with queries like SELECT min(ctid), max(ctid) FROM tab WHERE ...Greg Stark and Tom Lane
1 parentbc660c4 commit0144eb9

File tree

9 files changed

+167
-51
lines changed

9 files changed

+167
-51
lines changed

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

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/tid.c,v 1.53 2006/07/14 05:28:28 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/tid.c,v 1.54 2006/07/21 20:51:32 tgl Exp $
1212
*
1313
* NOTES
1414
* input routine largely stolen from boxin().
@@ -98,16 +98,11 @@ Datum
9898
tidout(PG_FUNCTION_ARGS)
9999
{
100100
ItemPointeritemPtr=PG_GETARG_ITEMPOINTER(0);
101-
BlockIdblockId;
102101
BlockNumberblockNumber;
103102
OffsetNumberoffsetNumber;
104103
charbuf[32];
105104

106-
if (!ItemPointerIsValid(itemPtr))
107-
PG_RETURN_CSTRING(pstrdup("()"));
108-
109-
blockId=&(itemPtr->ip_blkid);
110-
blockNumber=BlockIdGetBlockNumber(blockId);
105+
blockNumber=BlockIdGetBlockNumber(&(itemPtr->ip_blkid));
111106
offsetNumber=itemPtr->ip_posid;
112107

113108
/* Perhaps someday we should output this as a record. */
@@ -163,15 +158,36 @@ tidsend(PG_FUNCTION_ARGS)
163158
* PUBLIC ROUTINES *
164159
*****************************************************************************/
165160

161+
staticint32
162+
tid_cmp_internal(ItemPointerarg1,ItemPointerarg2)
163+
{
164+
/*
165+
* Don't use ItemPointerGetBlockNumber or ItemPointerGetOffsetNumber here,
166+
* because they assert ip_posid != 0 which might not be true for a
167+
* user-supplied TID.
168+
*/
169+
BlockNumberb1=BlockIdGetBlockNumber(&(arg1->ip_blkid));
170+
BlockNumberb2=BlockIdGetBlockNumber(&(arg2->ip_blkid));
171+
172+
if (b1<b2)
173+
return-1;
174+
elseif (b1>b2)
175+
return1;
176+
elseif (arg1->ip_posid<arg2->ip_posid)
177+
return-1;
178+
elseif (arg1->ip_posid>arg2->ip_posid)
179+
return1;
180+
else
181+
return0;
182+
}
183+
166184
Datum
167185
tideq(PG_FUNCTION_ARGS)
168186
{
169187
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
170188
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
171189

172-
PG_RETURN_BOOL(BlockIdGetBlockNumber(&(arg1->ip_blkid))==
173-
BlockIdGetBlockNumber(&(arg2->ip_blkid))&&
174-
arg1->ip_posid==arg2->ip_posid);
190+
PG_RETURN_BOOL(tid_cmp_internal(arg1,arg2)==0);
175191
}
176192

177193
Datum
@@ -180,11 +196,73 @@ tidne(PG_FUNCTION_ARGS)
180196
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
181197
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
182198

183-
PG_RETURN_BOOL(BlockIdGetBlockNumber(&(arg1->ip_blkid))!=
184-
BlockIdGetBlockNumber(&(arg2->ip_blkid))||
185-
arg1->ip_posid!=arg2->ip_posid);
199+
PG_RETURN_BOOL(tid_cmp_internal(arg1,arg2)!=0);
186200
}
187201

202+
Datum
203+
tidlt(PG_FUNCTION_ARGS)
204+
{
205+
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
206+
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
207+
208+
PG_RETURN_BOOL(tid_cmp_internal(arg1,arg2)<0);
209+
}
210+
211+
Datum
212+
tidle(PG_FUNCTION_ARGS)
213+
{
214+
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
215+
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
216+
217+
PG_RETURN_BOOL(tid_cmp_internal(arg1,arg2) <=0);
218+
}
219+
220+
Datum
221+
tidgt(PG_FUNCTION_ARGS)
222+
{
223+
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
224+
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
225+
226+
PG_RETURN_BOOL(tid_cmp_internal(arg1,arg2)>0);
227+
}
228+
229+
Datum
230+
tidge(PG_FUNCTION_ARGS)
231+
{
232+
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
233+
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
234+
235+
PG_RETURN_BOOL(tid_cmp_internal(arg1,arg2) >=0);
236+
}
237+
238+
Datum
239+
bttidcmp(PG_FUNCTION_ARGS)
240+
{
241+
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
242+
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
243+
244+
PG_RETURN_INT32(tid_cmp_internal(arg1,arg2));
245+
}
246+
247+
Datum
248+
tidlarger(PG_FUNCTION_ARGS)
249+
{
250+
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
251+
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
252+
253+
PG_RETURN_ITEMPOINTER(tid_cmp_internal(arg1,arg2) >=0 ?arg1 :arg2);
254+
}
255+
256+
Datum
257+
tidsmaller(PG_FUNCTION_ARGS)
258+
{
259+
ItemPointerarg1=PG_GETARG_ITEMPOINTER(0);
260+
ItemPointerarg2=PG_GETARG_ITEMPOINTER(1);
261+
262+
PG_RETURN_ITEMPOINTER(tid_cmp_internal(arg1,arg2) <=0 ?arg1 :arg2);
263+
}
264+
265+
188266
/*
189267
*Functions to get latest tid of a specified tuple.
190268
*

‎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-2006, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.338 2006/07/11 19:49:13 teodor Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.339 2006/07/21 20:51:33 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200607111
56+
#defineCATALOG_VERSION_NO200607211
5757

5858
#endif

‎src/include/catalog/pg_aggregate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_aggregate.h,v 1.54 2006/03/10 20:15:26 neilc Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_aggregate.h,v 1.55 2006/07/21 20:51:33 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -117,6 +117,7 @@ DATA(insert ( 2129text_larger-66625_null_ ));
117117
DATA(insert (2130numeric_larger-17561700_null_ ));
118118
DATA(insert (2050array_larger-10732277_null_ ));
119119
DATA(insert (2244bpchar_larger-10601042_null_ ));
120+
DATA(insert (2797tidlarger-280027_null_ ));
120121

121122
/* min */
122123
DATA(insert (2131int8smaller-41220_null_ ));
@@ -137,6 +138,7 @@ DATA(insert ( 2145text_smaller-66425_null_ ));
137138
DATA(insert (2146numeric_smaller-17541700_null_ ));
138139
DATA(insert (2051array_smaller-10722277_null_ ));
139140
DATA(insert (2245bpchar_smaller-10581042_null_ ));
141+
DATA(insert (2798tidsmaller-279927_null_ ));
140142

141143
/*
142144
* Using int8inc for count() is cheating a little, since it really only

‎src/include/catalog/pg_amop.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.72 2006/07/11 19:49:13 teodor Exp $
26+
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.73 2006/07/21 20:51:33 tgl Exp $
2727
*
2828
* NOTES
2929
* the genbki.sh script reads this file and generates .bki
@@ -156,6 +156,16 @@ DATA(insert (19890 3 f 607 ));
156156
DATA(insert (198904f612 ));
157157
DATA(insert (198905f610 ));
158158

159+
/*
160+
* btree tid_ops
161+
*/
162+
163+
DATA(insert (278901f2799 ));
164+
DATA(insert (278902f2801 ));
165+
DATA(insert (278903f387 ));
166+
DATA(insert (278904f2802 ));
167+
DATA(insert (278905f2800 ));
168+
159169
/*
160170
*btree oidvector_ops
161171
*/

‎src/include/catalog/pg_amproc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
22-
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.58 2006/05/02 15:23:16 teodor Exp $
22+
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.59 2006/07/21 20:51:33 tgl Exp $
2323
*
2424
* NOTES
2525
* the genbki.sh script reads this file and generates .bki
@@ -124,6 +124,7 @@ DATA(insert (20980 1 2187 ));
124124
DATA(insert (209901377 ));
125125
DATA(insert (223301380 ));
126126
DATA(insert (223401381 ));
127+
DATA(insert (2789012794 ));
127128

128129

129130
/* hash */

‎src/include/catalog/pg_opclass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
2828
* Portions Copyright (c) 1994, Regents of the University of California
2929
*
30-
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.70 2006/05/02 15:23:16 teodor Exp $
30+
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.71 2006/07/21 20:51:33 tgl Exp $
3131
*
3232
* NOTES
3333
* the genbki.sh script reads this file and generates .bki
@@ -162,6 +162,7 @@ DATA(insert OID = 2222 (405bool_opsPGNSP PGUID 16 t 0 ));
162162
#defineBOOL_HASH_OPS_OID 2222
163163
DATA(insertOID=2223 (405bytea_opsPGNSPPGUID17t0 ));
164164
DATA(insertOID=2224 (405int2vector_opsPGNSPPGUID22t0 ));
165+
DATA(insertOID=2789 (403tid_opsPGNSPPGUID27t0 ));
165166
DATA(insertOID=2225 (405xid_opsPGNSPPGUID28t0 ));
166167
DATA(insertOID=2226 (405cid_opsPGNSPPGUID29t0 ));
167168
DATA(insertOID=2227 (405abstime_opsPGNSPPGUID702t0 ));

‎src/include/catalog/pg_operator.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.143 2006/05/02 11:28:55 teodor Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.144 2006/07/21 20:51:33 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -128,9 +128,15 @@ DATA(insert OID = 388 ( "!" PGNSP PGUID r f20 01700 0 0 0 0 0
128128
DATA(insertOID=389 ("!!"PGNSPPGUIDlf0201700000000numeric_fac-- ));
129129
DATA(insertOID=385 ("="PGNSPPGUIDbt29291638500000cideqeqseleqjoinsel ));
130130
DATA(insertOID=386 ("="PGNSPPGUIDbt22221638600000int2vectoreqeqseleqjoinsel ));
131-
DATA(insertOID=387 ("="PGNSPPGUIDbf2727163874020000tideqeqseleqjoinsel ));
131+
132+
DATA(insertOID=387 ("="PGNSPPGUIDbf2727163874022799279927992800tideqeqseleqjoinsel ));
132133
#defineTIDEqualOperator 387
133-
DATA(insertOID=402 ("<>"PGNSPPGUIDbf2727164023870000tidneneqselneqjoinsel ));
134+
DATA(insertOID=402 ("<>"PGNSPPGUIDbf2727164023870000tidneneqselneqjoinsel ));
135+
DATA(insertOID=2799 ("<"PGNSPPGUIDbf272716280028020000tidltscalarltselscalarltjoinsel ));
136+
#defineTIDLessOperator 2799
137+
DATA(insertOID=2800 (">"PGNSPPGUIDbf272716279928010000tidgtscalargtselscalargtjoinsel ));
138+
DATA(insertOID=2801 ("<="PGNSPPGUIDbf272716280228000000tidlescalarltselscalarltjoinsel ));
139+
DATA(insertOID=2802 (">="PGNSPPGUIDbf272716280127990000tidgescalargtselscalargtjoinsel ));
134140

135141
DATA(insertOID=410 ("="PGNSPPGUIDbt202016410411412412412413int8eqeqseleqjoinsel ));
136142
DATA(insertOID=411 ("<>"PGNSPPGUIDbf2020164114100000int8neneqselneqjoinsel ));
@@ -262,6 +268,7 @@ DATA(insert OID = 596 ( "|/" PGNSP PGUID l f 0 701 701 0 0 0 0 0 0 ds
262268
DATA(insertOID=597 ("||/"PGNSPPGUIDlf0701701000000dcbrt-- ));
263269
DATA(insertOID=1284 ("|"PGNSPPGUIDlf0704702000000tintervalstart-- ));
264270
DATA(insertOID=606 ("<#>"PGNSPPGUIDbf702702704000000mktinterval-- ));
271+
265272
DATA(insertOID=607 ("="PGNSPPGUIDbt262616607608609609609610oideqeqseleqjoinsel ));
266273
#defineMIN_OIDCMP 607/* used by cache code */
267274
DATA(insertOID=608 ("<>"PGNSPPGUIDbf2626166086070000oidneneqselneqjoinsel ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp