forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitc87cb5f
committed
Allow btree comparison functions to return INT_MIN.
Historically we forbade datatype-specific comparison functions fromreturning INT_MIN, so that it would be safe to invert the sort orderjust by negating the comparison result. However, this was neverreally safe for comparison functions that directly return the resultof memcmp(), strcmp(), etc, as POSIX doesn't place any such restrictionon those library functions. Buildfarm results show that at least onrecent Linux on s390x, memcmp() actually does return INT_MIN sometimes,causing sort failures.The agreed-on answer is to remove this restriction and fix relevantcall sites to not make such an assumption; code such as "res = -res"should be replaced by "INVERT_COMPARE_RESULT(res)". The same is neededin a few places that just directly negated the result of memcmp orstrcmp.To help find places having this problem, I've also added a compile optionto nbtcompare.c that causes some of the commonly used comparators toreturn INT_MIN/INT_MAX instead of their usual -1/+1. It'd likely bea good idea to have at least one buildfarm member running with"-DSTRESS_SORT_INT_MIN". That's far from a complete test of course,but it should help to prevent fresh introductions of such bugs.This is a longstanding portability hazard, so back-patch to all supportedbranches.Discussion:https://postgr.es/m/20180928185215.ffoq2xrq5d3pafna@alap3.anarazel.de1 parent113a659 commitc87cb5f
File tree
13 files changed
+92
-61
lines changed- contrib
- ltree
- pgcrypto
- doc/src/sgml
- src
- backend
- access/nbtree
- executor
- bin/pg_rewind
- include
- access
- utils
13 files changed
+92
-61
lines changedLines changed: 9 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
48 |
| - | |
49 | 48 |
| |
50 | 49 |
| |
51 | 50 |
| |
| 51 | + | |
| 52 | + | |
52 | 53 |
| |
53 | 54 |
| |
54 | 55 |
| |
55 | 56 |
| |
56 | 57 |
| |
57 | 58 |
| |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
58 | 64 |
| |
| 65 | + | |
59 | 66 |
| |
60 | 67 |
| |
61 | 68 |
| |
| |||
146 | 153 |
| |
147 | 154 |
| |
148 | 155 |
| |
149 |
| - | |
| 156 | + | |
150 | 157 |
| |
151 | 158 |
| |
152 | 159 |
| |
|
Lines changed: 6 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1254 | 1254 |
| |
1255 | 1255 |
| |
1256 | 1256 |
| |
1257 |
| - | |
1258 |
| - | |
1259 |
| - | |
1260 |
| - | |
1261 |
| - | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
1262 | 1260 |
| |
1263 | 1261 |
| |
1264 | 1262 |
| |
| |||
1314 | 1312 |
| |
1315 | 1313 |
| |
1316 | 1314 |
| |
1317 |
| - | |
1318 |
| - | |
1319 |
| - | |
1320 |
| - | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
1321 | 1318 |
| |
1322 | 1319 |
| |
1323 | 1320 |
| |
|
Lines changed: 2 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
228 | 228 |
| |
229 | 229 |
| |
230 | 230 |
| |
231 |
| - | |
232 |
| - | |
233 |
| - | |
234 |
| - | |
235 |
| - | |
| 231 | + | |
| 232 | + | |
236 | 233 |
| |
237 | 234 |
| |
238 | 235 |
| |
|
Lines changed: 47 additions & 30 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
22 | 22 |
| |
23 | 23 |
| |
24 | 24 |
| |
25 |
| - | |
26 |
| - | |
| 25 | + | |
| 26 | + | |
27 | 27 |
| |
28 |
| - | |
29 |
| - | |
| 28 | + | |
30 | 29 |
| |
31 | 30 |
| |
32 | 31 |
| |
| |||
44 | 43 |
| |
45 | 44 |
| |
46 | 45 |
| |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
47 | 54 |
| |
48 | 55 |
| |
49 | 56 |
| |
50 | 57 |
| |
| 58 | + | |
| 59 | + | |
51 | 60 |
| |
52 | 61 |
| |
53 | 62 |
| |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
54 | 71 |
| |
55 | 72 |
| |
56 | 73 |
| |
| |||
95 | 112 |
| |
96 | 113 |
| |
97 | 114 |
| |
98 |
| - | |
| 115 | + | |
99 | 116 |
| |
100 | 117 |
| |
101 | 118 |
| |
102 |
| - | |
| 119 | + | |
103 | 120 |
| |
104 | 121 |
| |
105 | 122 |
| |
| |||
109 | 126 |
| |
110 | 127 |
| |
111 | 128 |
| |
112 |
| - | |
| 129 | + | |
113 | 130 |
| |
114 | 131 |
| |
115 | 132 |
| |
116 |
| - | |
| 133 | + | |
117 | 134 |
| |
118 | 135 |
| |
119 | 136 |
| |
| |||
132 | 149 |
| |
133 | 150 |
| |
134 | 151 |
| |
135 |
| - | |
| 152 | + | |
136 | 153 |
| |
137 | 154 |
| |
138 | 155 |
| |
139 |
| - | |
| 156 | + | |
140 | 157 |
| |
141 | 158 |
| |
142 | 159 |
| |
| |||
146 | 163 |
| |
147 | 164 |
| |
148 | 165 |
| |
149 |
| - | |
| 166 | + | |
150 | 167 |
| |
151 | 168 |
| |
152 | 169 |
| |
153 |
| - | |
| 170 | + | |
154 | 171 |
| |
155 | 172 |
| |
156 | 173 |
| |
| |||
169 | 186 |
| |
170 | 187 |
| |
171 | 188 |
| |
172 |
| - | |
| 189 | + | |
173 | 190 |
| |
174 | 191 |
| |
175 | 192 |
| |
176 |
| - | |
| 193 | + | |
177 | 194 |
| |
178 | 195 |
| |
179 | 196 |
| |
| |||
183 | 200 |
| |
184 | 201 |
| |
185 | 202 |
| |
186 |
| - | |
| 203 | + | |
187 | 204 |
| |
188 | 205 |
| |
189 | 206 |
| |
190 |
| - | |
| 207 | + | |
191 | 208 |
| |
192 | 209 |
| |
193 | 210 |
| |
| |||
197 | 214 |
| |
198 | 215 |
| |
199 | 216 |
| |
200 |
| - | |
| 217 | + | |
201 | 218 |
| |
202 | 219 |
| |
203 | 220 |
| |
204 |
| - | |
| 221 | + | |
205 | 222 |
| |
206 | 223 |
| |
207 | 224 |
| |
| |||
211 | 228 |
| |
212 | 229 |
| |
213 | 230 |
| |
214 |
| - | |
| 231 | + | |
215 | 232 |
| |
216 | 233 |
| |
217 | 234 |
| |
218 |
| - | |
| 235 | + | |
219 | 236 |
| |
220 | 237 |
| |
221 | 238 |
| |
| |||
225 | 242 |
| |
226 | 243 |
| |
227 | 244 |
| |
228 |
| - | |
| 245 | + | |
229 | 246 |
| |
230 | 247 |
| |
231 | 248 |
| |
232 |
| - | |
| 249 | + | |
233 | 250 |
| |
234 | 251 |
| |
235 | 252 |
| |
| |||
239 | 256 |
| |
240 | 257 |
| |
241 | 258 |
| |
242 |
| - | |
| 259 | + | |
243 | 260 |
| |
244 | 261 |
| |
245 | 262 |
| |
246 |
| - | |
| 263 | + | |
247 | 264 |
| |
248 | 265 |
| |
249 | 266 |
| |
| |||
253 | 270 |
| |
254 | 271 |
| |
255 | 272 |
| |
256 |
| - | |
| 273 | + | |
257 | 274 |
| |
258 | 275 |
| |
259 | 276 |
| |
260 |
| - | |
| 277 | + | |
261 | 278 |
| |
262 | 279 |
| |
263 | 280 |
| |
| |||
267 | 284 |
| |
268 | 285 |
| |
269 | 286 |
| |
270 |
| - | |
| 287 | + | |
271 | 288 |
| |
272 | 289 |
| |
273 | 290 |
| |
274 |
| - | |
| 291 | + | |
275 | 292 |
| |
276 | 293 |
| |
277 | 294 |
| |
| |||
299 | 316 |
| |
300 | 317 |
| |
301 | 318 |
| |
302 |
| - | |
| 319 | + | |
303 | 320 |
| |
304 |
| - | |
| 321 | + | |
305 | 322 |
| |
306 | 323 |
| |
307 | 324 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
530 | 530 |
| |
531 | 531 |
| |
532 | 532 |
| |
533 |
| - | |
| 533 | + | |
534 | 534 |
| |
535 | 535 |
| |
536 | 536 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
518 | 518 |
| |
519 | 519 |
| |
520 | 520 |
| |
521 |
| - | |
| 521 | + | |
522 | 522 |
| |
523 | 523 |
| |
524 | 524 |
| |
| |||
1652 | 1652 |
| |
1653 | 1653 |
| |
1654 | 1654 |
| |
1655 |
| - | |
| 1655 | + | |
1656 | 1656 |
| |
1657 | 1657 |
| |
1658 | 1658 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
755 | 755 |
| |
756 | 756 |
| |
757 | 757 |
| |
758 |
| - | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
759 | 762 |
| |
760 | 763 |
| |
761 | 764 |
|
Lines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
467 | 467 |
| |
468 | 468 |
| |
469 | 469 |
| |
470 |
| - | |
471 |
| - | |
472 |
| - | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
473 | 474 |
| |
474 | 475 |
| |
475 | 476 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
338 | 338 |
| |
339 | 339 |
| |
340 | 340 |
| |
341 |
| - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
342 | 345 |
| |
343 | 346 |
| |
344 | 347 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
810 | 810 |
| |
811 | 811 |
| |
812 | 812 |
| |
813 |
| - | |
| 813 | + | |
814 | 814 |
| |
815 | 815 |
| |
816 | 816 |
|
Lines changed: 1 addition & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
274 | 274 |
| |
275 | 275 |
| |
276 | 276 |
| |
277 |
| - | |
278 |
| - | |
| 277 | + | |
279 | 278 |
| |
280 | 279 |
| |
281 | 280 |
| |
|
0 commit comments
Comments
(0)