File tree 11 files changed +196
-4
lines changed
11 files changed +196
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*-------------------------------------------------------------------------
2
2
*
3
3
* pg_lsn.c
4
- * Internal PostgreSQL LSN operations
4
+ * Operations for the pg_lsn datatype.
5
5
*
6
- * Portions Copyright (c) 1996-2011 , PostgreSQL Global Development Group
6
+ * Portions Copyright (c) 1996-2014 , PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* IDENTIFICATION
13
13
*/
14
14
#include "postgres.h"
15
15
16
+ #include "access/hash.h"
16
17
#include "funcapi.h"
17
18
#include "libpq/pqformat.h"
18
19
#include "utils/builtins.h"
@@ -153,6 +154,29 @@ pg_lsn_ge(PG_FUNCTION_ARGS)
153
154
PG_RETURN_BOOL (lsn1 >= lsn2 );
154
155
}
155
156
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
+
156
180
157
181
/*----------------------------------------------------------
158
182
* Arithmetic operators on PostgreSQL LSNs.
Original file line number Diff line number Diff line change 53
53
*/
54
54
55
55
/* yyyymmddN */
56
- #define CATALOG_VERSION_NO 201405111
56
+ #define CATALOG_VERSION_NO 201406041
57
57
58
58
#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 ));
512
512
DATA (insert ( 2968 2950 2950 4 s 2977 403 0 ));
513
513
DATA (insert ( 2968 2950 2950 5 s 2975 403 0 ));
514
514
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
+
515
525
/*
516
526
* hash index _ops
517
527
*/
@@ -581,6 +591,8 @@ DATA(insert ( 2231 1042 1042 1 s 1054 405 0 ));
581
591
DATA (insert ( 2235 1033 1033 1 s 974 405 0 ));
582
592
/* uuid_ops */
583
593
DATA (insert ( 2969 2950 2950 1 s 2972 405 0 ));
594
+ /* pg_lsn_ops */
595
+ DATA (insert ( 3254 3220 3220 1 s 3222 405 0 ));
584
596
/* numeric_ops */
585
597
DATA (insert ( 1998 1700 1700 1 s 1752 405 0 ));
586
598
/* array_ops */
Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ DATA(insert ( 2789 27 27 1 2794 ));
134
134
DATA (insert ( 2968 2950 2950 1 2960 ));
135
135
DATA (insert ( 2994 2249 2249 1 2987 ));
136
136
DATA (insert ( 3194 2249 2249 1 3187 ));
137
+ DATA (insert ( 3253 3220 3220 1 3251 ));
137
138
DATA (insert ( 3522 3500 3500 1 3514 ));
138
139
DATA (insert ( 3626 3614 3614 1 3622 ));
139
140
DATA (insert ( 3683 3615 3615 1 3668 ));
@@ -174,6 +175,7 @@ DATA(insert ( 2229 25 25 1 400 ));
174
175
DATA (insert ( 2231 1042 1042 1 1080 ));
175
176
DATA (insert ( 2235 1033 1033 1 329 ));
176
177
DATA (insert ( 2969 2950 2950 1 2963 ));
178
+ DATA (insert ( 3254 3220 3220 1 3252 ));
177
179
DATA (insert ( 3523 3500 3500 1 3515 ));
178
180
DATA (insert ( 3903 3831 3831 1 3902 ));
179
181
DATA (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 ));
215
215
DATA (insert ( 2742 _tinterval_ops PGNSP PGUID 2745 1025 t 704 ));
216
216
DATA (insert ( 403 uuid_ops PGNSP PGUID 2968 2950 t 0 ));
217
217
DATA (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 ));
218
220
DATA (insert ( 403 enum_ops PGNSP PGUID 3522 3500 t 0 ));
219
221
DATA (insert ( 405 enum_ops PGNSP PGUID 3523 3500 t 0 ));
220
222
DATA (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_
1595
1595
DESCR ("greater than or equal" );
1596
1596
1597
1597
/* 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 ));
1599
1599
DESCR ("equal" );
1600
1600
DATA (insert OID = 3223 ( "<>" PGNSP PGUID b f f 3220 3220 16 3223 3222 pg_lsn_ne neqsel neqjoinsel ));
1601
1601
DESCR ("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 ));
134
134
DATA (insert OID = 2745 ( 2742 array_ops PGNSP PGUID ));
135
135
DATA (insert OID = 2968 ( 403 uuid_ops PGNSP PGUID ));
136
136
DATA (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 ));
137
139
DATA (insert OID = 3522 ( 403 enum_ops PGNSP PGUID ));
138
140
DATA (insert OID = 3523 ( 405 enum_ops PGNSP PGUID ));
139
141
DATA (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
4293
4293
DESCR("I/O");
4294
4294
DATA(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_ ));
4295
4295
DESCR("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");
4296
4300
4297
4301
/* enum related procs */
4298
4302
DATA(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);
29
29
extern Datum pg_lsn_gt (PG_FUNCTION_ARGS );
30
30
extern Datum pg_lsn_le (PG_FUNCTION_ARGS );
31
31
extern 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 );
32
34
33
35
extern Datum pg_lsn_mi (PG_FUNCTION_ARGS );
34
36
Original file line number Diff line number Diff line change @@ -64,3 +64,133 @@ SELECT '0/16AE7F8'::pg_lsn - '0/16AE7F7'::pg_lsn;
64
64
1
65
65
(1 row)
66
66
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
+
Original file line number Diff line number Diff line change @@ -23,3 +23,17 @@ SELECT '0/16AE7F7' < '0/16AE7F8'::pg_lsn;
23
23
SELECT ' 0/16AE7F8' > pg_lsn ' 0/16AE7F7' ;
24
24
SELECT ' 0/16AE7F7' ::pg_lsn - ' 0/16AE7F8' ::pg_lsn;
25
25
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;
You can’t perform that action at this time.
0 commit comments