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

Commit4c8ab1b

Browse files
committed
Add btree and hash opclasses for pg_lsn.
This is needed to allow ORDER BY, DISTINCT, etc to work as expected forpg_lsn values.We had previously decided to put this off for 9.5, but in view of commiteeca4cd there's no reason to avoid acatversion bump for 9.4beta2, and this does make a pretty significantusability difference for pg_lsn.Michael Paquier, with fixes from Andres Freund and Tom Lane
1 parenteeca4cd commit4c8ab1b

File tree

11 files changed

+196
-4
lines changed

11 files changed

+196
-4
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*-------------------------------------------------------------------------
22
*
33
* pg_lsn.c
4-
*Internal PostgreSQL LSN operations
4+
*Operations for the pg_lsn datatype.
55
*
6-
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
6+
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
@@ -13,6 +13,7 @@
1313
*/
1414
#include"postgres.h"
1515

16+
#include"access/hash.h"
1617
#include"funcapi.h"
1718
#include"libpq/pqformat.h"
1819
#include"utils/builtins.h"
@@ -153,6 +154,29 @@ pg_lsn_ge(PG_FUNCTION_ARGS)
153154
PG_RETURN_BOOL(lsn1 >=lsn2);
154155
}
155156

157+
/* btree index opclass support */
158+
Datum
159+
pg_lsn_cmp(PG_FUNCTION_ARGS)
160+
{
161+
XLogRecPtra=PG_GETARG_LSN(0);
162+
XLogRecPtrb=PG_GETARG_LSN(1);
163+
164+
if (a>b)
165+
PG_RETURN_INT32(1);
166+
elseif (a==b)
167+
PG_RETURN_INT32(0);
168+
else
169+
PG_RETURN_INT32(-1);
170+
}
171+
172+
/* hash index opclass support */
173+
Datum
174+
pg_lsn_hash(PG_FUNCTION_ARGS)
175+
{
176+
/* We can use hashint8 directly */
177+
returnhashint8(fcinfo);
178+
}
179+
156180

157181
/*----------------------------------------------------------
158182
*Arithmetic operators on PostgreSQL LSNs.

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201405111
56+
#defineCATALOG_VERSION_NO201406041
5757

5858
#endif

‎src/include/catalog/pg_amop.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,16 @@ DATA(insert (2968 2950 2950 3 s 2972403 0 ));
512512
DATA(insert (2968295029504s29774030 ));
513513
DATA(insert (2968295029505s29754030 ));
514514

515+
/*
516+
* btree pg_lsn_ops
517+
*/
518+
519+
DATA(insert (3253322032201s32244030 ));
520+
DATA(insert (3253322032202s32264030 ));
521+
DATA(insert (3253322032203s32224030 ));
522+
DATA(insert (3253322032204s32274030 ));
523+
DATA(insert (3253322032205s32254030 ));
524+
515525
/*
516526
*hash index _ops
517527
*/
@@ -581,6 +591,8 @@ DATA(insert (2231 1042 1042 1 s 1054 405 0 ));
581591
DATA(insert (2235103310331s9744050 ));
582592
/* uuid_ops */
583593
DATA(insert (2969295029501s29724050 ));
594+
/* pg_lsn_ops */
595+
DATA(insert (3254322032201s32224050 ));
584596
/* numeric_ops */
585597
DATA(insert (1998170017001s17524050 ));
586598
/* array_ops */

‎src/include/catalog/pg_amproc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ DATA(insert (2789 27 27 1 2794 ));
134134
DATA(insert (29682950295012960 ));
135135
DATA(insert (29942249224912987 ));
136136
DATA(insert (31942249224913187 ));
137+
DATA(insert (32533220322013251 ));
137138
DATA(insert (35223500350013514 ));
138139
DATA(insert (36263614361413622 ));
139140
DATA(insert (36833615361513668 ));
@@ -174,6 +175,7 @@ DATA(insert (2229 25 25 1 400 ));
174175
DATA(insert (22311042104211080 ));
175176
DATA(insert (2235103310331329 ));
176177
DATA(insert (29692950295012963 ));
178+
DATA(insert (32543220322013252 ));
177179
DATA(insert (35233500350013515 ));
178180
DATA(insert (39033831383113902 ));
179181
DATA(insert (40343802380214045 ));

‎src/include/catalog/pg_opclass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ DATA(insert (2742_reltime_opsPGNSP PGUID 2745 1024 t 703 ));
215215
DATA(insert (2742_tinterval_opsPGNSPPGUID27451025t704 ));
216216
DATA(insert (403uuid_opsPGNSPPGUID29682950t0 ));
217217
DATA(insert (405uuid_opsPGNSPPGUID29692950t0 ));
218+
DATA(insert (403pg_lsn_opsPGNSPPGUID32533220t0 ));
219+
DATA(insert (405pg_lsn_opsPGNSPPGUID32543220t0 ));
218220
DATA(insert (403enum_opsPGNSPPGUID35223500t0 ));
219221
DATA(insert (405enum_opsPGNSPPGUID35233500t0 ));
220222
DATA(insert (403tsvector_opsPGNSPPGUID36263614t0 ));

‎src/include/catalog/pg_operator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ DATA(insert OID = 2977 ( ">=" PGNSP PGUID b f f 2950 2950 16 2976 2974 uuid_
15951595
DESCR("greater than or equal");
15961596

15971597
/* pg_lsn operators */
1598-
DATA(insertOID=3222 ("="PGNSPPGUIDbff322032201632223223pg_lsn_eqeqseleqjoinsel ));
1598+
DATA(insertOID=3222 ("="PGNSPPGUIDbtt322032201632223223pg_lsn_eqeqseleqjoinsel ));
15991599
DESCR("equal");
16001600
DATA(insertOID=3223 ("<>"PGNSPPGUIDbff322032201632233222pg_lsn_neneqselneqjoinsel ));
16011601
DESCR("not equal");

‎src/include/catalog/pg_opfamily.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ DATA(insert OID = 1029 (783point_opsPGNSP PGUID ));
134134
DATA(insertOID=2745 (2742array_opsPGNSPPGUID ));
135135
DATA(insertOID=2968 (403uuid_opsPGNSPPGUID ));
136136
DATA(insertOID=2969 (405uuid_opsPGNSPPGUID ));
137+
DATA(insertOID=3253 (403pg_lsn_opsPGNSPPGUID ));
138+
DATA(insertOID=3254 (405pg_lsn_opsPGNSPPGUID ));
137139
DATA(insertOID=3522 (403enum_opsPGNSPPGUID ));
138140
DATA(insertOID=3523 (405enum_opsPGNSPPGUID ));
139141
DATA(insertOID=3626 (403tsvector_opsPGNSPPGUID ));

‎src/include/catalog/pg_proc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,6 +4293,10 @@ DATA(insert OID = 3238 ( pg_lsn_recvPGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3
42934293
DESCR("I/O");
42944294
DATA(insertOID=3239 (pg_lsn_sendPGNSPPGUID121000fffftfi1017"3220"_null__null__null__null_pg_lsn_send_null__null__null_ ));
42954295
DESCR("I/O");
4296+
DATA(insertOID=3251 (pg_lsn_cmpPGNSPPGUID121000fffftfi2023"3220 3220"_null__null__null__null_pg_lsn_cmp_null__null__null_ ));
4297+
DESCR("less-equal-greater");
4298+
DATA(insertOID=3252 (pg_lsn_hashPGNSPPGUID121000fffftfi1023"3220"_null__null__null__null_pg_lsn_hash_null__null__null_ ));
4299+
DESCR("hash");
42964300

42974301
/* enum related procs */
42984302
DATA(insertOID=3504 (anyenum_inPGNSPPGUID121000fffftfi103500"2275"_null__null__null__null_anyenum_in_null__null__null_ ));

‎src/include/utils/pg_lsn.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extern Datum pg_lsn_lt(PG_FUNCTION_ARGS);
2929
externDatumpg_lsn_gt(PG_FUNCTION_ARGS);
3030
externDatumpg_lsn_le(PG_FUNCTION_ARGS);
3131
externDatumpg_lsn_ge(PG_FUNCTION_ARGS);
32+
externDatumpg_lsn_cmp(PG_FUNCTION_ARGS);
33+
externDatumpg_lsn_hash(PG_FUNCTION_ARGS);
3234

3335
externDatumpg_lsn_mi(PG_FUNCTION_ARGS);
3436

‎src/test/regress/expected/pg_lsn.out

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,133 @@ SELECT '0/16AE7F8'::pg_lsn - '0/16AE7F7'::pg_lsn;
6464
1
6565
(1 row)
6666

67+
-- Check btree and hash opclasses
68+
EXPLAIN (COSTS OFF)
69+
SELECT DISTINCT (i || '/' || j)::pg_lsn f
70+
FROM generate_series(1, 10) i,
71+
generate_series(1, 10) j,
72+
generate_series(1, 5) k
73+
ORDER BY f;
74+
QUERY PLAN
75+
--------------------------------------------------------------------------
76+
Sort
77+
Sort Key: (((((i.i)::text || '/'::text) || (j.j)::text))::pg_lsn)
78+
-> HashAggregate
79+
Group Key: ((((i.i)::text || '/'::text) || (j.j)::text))::pg_lsn
80+
-> Nested Loop
81+
-> Function Scan on generate_series k
82+
-> Materialize
83+
-> Nested Loop
84+
-> Function Scan on generate_series i
85+
-> Function Scan on generate_series j
86+
(10 rows)
87+
88+
SELECT DISTINCT (i || '/' || j)::pg_lsn f
89+
FROM generate_series(1, 10) i,
90+
generate_series(1, 10) j,
91+
generate_series(1, 5) k
92+
ORDER BY f;
93+
f
94+
-------
95+
1/1
96+
1/2
97+
1/3
98+
1/4
99+
1/5
100+
1/6
101+
1/7
102+
1/8
103+
1/9
104+
1/10
105+
2/1
106+
2/2
107+
2/3
108+
2/4
109+
2/5
110+
2/6
111+
2/7
112+
2/8
113+
2/9
114+
2/10
115+
3/1
116+
3/2
117+
3/3
118+
3/4
119+
3/5
120+
3/6
121+
3/7
122+
3/8
123+
3/9
124+
3/10
125+
4/1
126+
4/2
127+
4/3
128+
4/4
129+
4/5
130+
4/6
131+
4/7
132+
4/8
133+
4/9
134+
4/10
135+
5/1
136+
5/2
137+
5/3
138+
5/4
139+
5/5
140+
5/6
141+
5/7
142+
5/8
143+
5/9
144+
5/10
145+
6/1
146+
6/2
147+
6/3
148+
6/4
149+
6/5
150+
6/6
151+
6/7
152+
6/8
153+
6/9
154+
6/10
155+
7/1
156+
7/2
157+
7/3
158+
7/4
159+
7/5
160+
7/6
161+
7/7
162+
7/8
163+
7/9
164+
7/10
165+
8/1
166+
8/2
167+
8/3
168+
8/4
169+
8/5
170+
8/6
171+
8/7
172+
8/8
173+
8/9
174+
8/10
175+
9/1
176+
9/2
177+
9/3
178+
9/4
179+
9/5
180+
9/6
181+
9/7
182+
9/8
183+
9/9
184+
9/10
185+
10/1
186+
10/2
187+
10/3
188+
10/4
189+
10/5
190+
10/6
191+
10/7
192+
10/8
193+
10/9
194+
10/10
195+
(100 rows)
196+

‎src/test/regress/sql/pg_lsn.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ SELECT '0/16AE7F7' < '0/16AE7F8'::pg_lsn;
2323
SELECT'0/16AE7F8'> pg_lsn'0/16AE7F7';
2424
SELECT'0/16AE7F7'::pg_lsn-'0/16AE7F8'::pg_lsn;
2525
SELECT'0/16AE7F8'::pg_lsn-'0/16AE7F7'::pg_lsn;
26+
27+
-- Check btree and hash opclasses
28+
EXPLAIN (COSTS OFF)
29+
SELECT DISTINCT (i||'/'|| j)::pg_lsn f
30+
FROM generate_series(1,10) i,
31+
generate_series(1,10) j,
32+
generate_series(1,5) k
33+
ORDER BY f;
34+
35+
SELECT DISTINCT (i||'/'|| j)::pg_lsn f
36+
FROM generate_series(1,10) i,
37+
generate_series(1,10) j,
38+
generate_series(1,5) k
39+
ORDER BY f;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp