File tree Expand file tree Collapse file tree 11 files changed +196
-4
lines changed Expand file tree Collapse file tree 11 files changed +196
-4
lines changed Original file line number Diff line number Diff line change 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
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+ XLogRecPtr a = PG_GETARG_LSN (0 );
162+ XLogRecPtr b = PG_GETARG_LSN (1 );
163+
164+ if (a > b )
165+ PG_RETURN_INT32 (1 );
166+ else if (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+ return hashint8 (fcinfo );
178+ }
179+
156180
157181/*----------------------------------------------------------
158182 * Arithmetic operators on PostgreSQL LSNs.
Original file line number Diff line number Diff line change 5353 */
5454
5555/* yyyymmddN */
56- #define CATALOG_VERSION_NO 201405111
56+ #define CATALOG_VERSION_NO 201406041
5757
5858#endif
Original file line number Diff line number Diff line change @@ -512,6 +512,16 @@ DATA(insert ( 2968 2950 2950 3 s 2972 403 0 ));
512512DATA (insert ( 2968 2950 2950 4 s 2977 403 0 ));
513513DATA (insert ( 2968 2950 2950 5 s 2975 403 0 ));
514514
515+ /*
516+ * btree pg_lsn_ops
517+ */
518+
519+ DATA (insert ( 3253 3220 3220 1 s 3224 403 0 ));
520+ DATA (insert ( 3253 3220 3220 2 s 3226 403 0 ));
521+ DATA (insert ( 3253 3220 3220 3 s 3222 403 0 ));
522+ DATA (insert ( 3253 3220 3220 4 s 3227 403 0 ));
523+ DATA (insert ( 3253 3220 3220 5 s 3225 403 0 ));
524+
515525/*
516526 * hash index _ops
517527 */
@@ -581,6 +591,8 @@ DATA(insert ( 2231 1042 1042 1 s 1054 405 0 ));
581591DATA (insert ( 2235 1033 1033 1 s 974 405 0 ));
582592/* uuid_ops */
583593DATA (insert ( 2969 2950 2950 1 s 2972 405 0 ));
594+ /* pg_lsn_ops */
595+ DATA (insert ( 3254 3220 3220 1 s 3222 405 0 ));
584596/* numeric_ops */
585597DATA (insert ( 1998 1700 1700 1 s 1752 405 0 ));
586598/* array_ops */
Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ DATA(insert ( 2789 27 27 1 2794 ));
134134DATA (insert ( 2968 2950 2950 1 2960 ));
135135DATA (insert ( 2994 2249 2249 1 2987 ));
136136DATA (insert ( 3194 2249 2249 1 3187 ));
137+ DATA (insert ( 3253 3220 3220 1 3251 ));
137138DATA (insert ( 3522 3500 3500 1 3514 ));
138139DATA (insert ( 3626 3614 3614 1 3622 ));
139140DATA (insert ( 3683 3615 3615 1 3668 ));
@@ -174,6 +175,7 @@ DATA(insert ( 2229 25 25 1 400 ));
174175DATA (insert ( 2231 1042 1042 1 1080 ));
175176DATA (insert ( 2235 1033 1033 1 329 ));
176177DATA (insert ( 2969 2950 2950 1 2963 ));
178+ DATA (insert ( 3254 3220 3220 1 3252 ));
177179DATA (insert ( 3523 3500 3500 1 3515 ));
178180DATA (insert ( 3903 3831 3831 1 3902 ));
179181DATA (insert ( 4034 3802 3802 1 4045 ));
Original file line number Diff line number Diff line change @@ -215,6 +215,8 @@ DATA(insert ( 2742 _reltime_ops PGNSP PGUID 2745 1024 t 703 ));
215215DATA (insert ( 2742 _tinterval_ops PGNSP PGUID 2745 1025 t 704 ));
216216DATA (insert ( 403 uuid_ops PGNSP PGUID 2968 2950 t 0 ));
217217DATA (insert ( 405 uuid_ops PGNSP PGUID 2969 2950 t 0 ));
218+ DATA (insert ( 403 pg_lsn_ops PGNSP PGUID 3253 3220 t 0 ));
219+ DATA (insert ( 405 pg_lsn_ops PGNSP PGUID 3254 3220 t 0 ));
218220DATA (insert ( 403 enum_ops PGNSP PGUID 3522 3500 t 0 ));
219221DATA (insert ( 405 enum_ops PGNSP PGUID 3523 3500 t 0 ));
220222DATA (insert ( 403 tsvector_ops PGNSP PGUID 3626 3614 t 0 ));
Original file line number Diff line number Diff line change @@ -1595,7 +1595,7 @@ DATA(insert OID = 2977 ( ">=" PGNSP PGUID b f f 2950 2950 16 2976 2974 uuid_
15951595DESCR ("greater than or equal" );
15961596
15971597/* pg_lsn operators */
1598- DATA (insert OID = 3222 ( "=" PGNSP PGUID b f f 3220 3220 16 3222 3223 pg_lsn_eq eqsel eqjoinsel ));
1598+ DATA (insert OID = 3222 ( "=" PGNSP PGUID b t t 3220 3220 16 3222 3223 pg_lsn_eq eqsel eqjoinsel ));
15991599DESCR ("equal" );
16001600DATA (insert OID = 3223 ( "<>" PGNSP PGUID b f f 3220 3220 16 3223 3222 pg_lsn_ne neqsel neqjoinsel ));
16011601DESCR ("not equal" );
Original file line number Diff line number Diff line change @@ -134,6 +134,8 @@ DATA(insert OID = 1029 ( 783 point_ops PGNSP PGUID ));
134134DATA (insert OID = 2745 ( 2742 array_ops PGNSP PGUID ));
135135DATA (insert OID = 2968 ( 403 uuid_ops PGNSP PGUID ));
136136DATA (insert OID = 2969 ( 405 uuid_ops PGNSP PGUID ));
137+ DATA (insert OID = 3253 ( 403 pg_lsn_ops PGNSP PGUID ));
138+ DATA (insert OID = 3254 ( 405 pg_lsn_ops PGNSP PGUID ));
137139DATA (insert OID = 3522 ( 403 enum_ops PGNSP PGUID ));
138140DATA (insert OID = 3523 ( 405 enum_ops PGNSP PGUID ));
139141DATA (insert OID = 3626 ( 403 tsvector_ops PGNSP PGUID ));
Original file line number Diff line number Diff line change @@ -4293,6 +4293,10 @@ DATA(insert OID = 3238 ( pg_lsn_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3
42934293DESCR ("I/O" );
42944294DATA (insert OID = 3239 ( pg_lsn_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3220" _null_ _null_ _null_ _null_ pg_lsn_send _null_ _null_ _null_ ));
42954295DESCR ("I/O" );
4296+ DATA (insert OID = 3251 ( pg_lsn_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3220 3220" _null_ _null_ _null_ _null_ pg_lsn_cmp _null_ _null_ _null_ ));
4297+ DESCR ("less-equal-greater" );
4298+ DATA (insert OID = 3252 ( pg_lsn_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3220" _null_ _null_ _null_ _null_ pg_lsn_hash _null_ _null_ _null_ ));
4299+ DESCR ("hash" );
42964300
42974301/* enum related procs */
42984302DATA (insert OID = 3504 ( anyenum_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3500 "2275" _null_ _null_ _null_ _null_ anyenum_in _null_ _null_ _null_ ));
Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ extern Datum pg_lsn_lt(PG_FUNCTION_ARGS);
2929extern Datum pg_lsn_gt (PG_FUNCTION_ARGS );
3030extern Datum pg_lsn_le (PG_FUNCTION_ARGS );
3131extern Datum pg_lsn_ge (PG_FUNCTION_ARGS );
32+ extern Datum pg_lsn_cmp (PG_FUNCTION_ARGS );
33+ extern Datum pg_lsn_hash (PG_FUNCTION_ARGS );
3234
3335extern Datum pg_lsn_mi (PG_FUNCTION_ARGS );
3436
Original file line number Diff line number Diff 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+
You can’t perform that action at this time.
0 commit comments