forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitce773f2
committed
Fix float4/float8 hash functions to produce uniform results for NaNs.
The IEEE 754 standard allows a wide variety of bit patterns for NaNs,of which at least two ("NaN" and "-NaN") are pretty easy to producefrom SQL on most machines. This is problematic because our btreecomparison functions deem all NaNs to be equal, but our float hashfunctions know nothing about NaNs and will happily produce varyinghash codes for them. That causes unexpected results from queriesthat hash a column containing different NaN values. It could alsoproduce unexpected lookup failures when using a hash index on afloat column, i.e. "WHERE x = 'NaN'" will not find all the rowsit should.To fix, special-case NaN in the float hash functions, not too muchunlike the existing special case that forces zero and minus zeroto hash the same. I arranged for the most vanilla sort of NaN(that coming from the C99 NAN constant) to still have the samehash code as before, to reduce the risk to existing hash indexes.I dithered about whether to back-patch this into stable branches,but ultimately decided to do so. It's a clear improvement forqueries that hash internally. If there is anybody who has -NaNin a hash index, they'd be well advised to re-index after applyingthis patch ... but the misbehavior if they don't will not be muchworse than the misbehavior they had before.Per bug #17172 from Ma Liangzhu.Discussion:https://postgr.es/m/17172-7505bea9e04e230f@postgresql.org1 parentba1b763 commitce773f2
File tree
3 files changed
+63
-0
lines changed- src
- backend/access/hash
- test/regress
- expected
- sql
3 files changed
+63
-0
lines changedLines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
30 | 30 |
| |
31 | 31 |
| |
32 | 32 |
| |
| 33 | + | |
33 | 34 |
| |
34 | 35 |
| |
35 | 36 |
| |
| |||
150 | 151 |
| |
151 | 152 |
| |
152 | 153 |
| |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
153 | 162 |
| |
154 | 163 |
| |
155 | 164 |
| |
| |||
172 | 181 |
| |
173 | 182 |
| |
174 | 183 |
| |
| 184 | + | |
| 185 | + | |
175 | 186 |
| |
176 | 187 |
| |
177 | 188 |
| |
| |||
190 | 201 |
| |
191 | 202 |
| |
192 | 203 |
| |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
193 | 212 |
| |
194 | 213 |
| |
195 | 214 |
| |
| |||
202 | 221 |
| |
203 | 222 |
| |
204 | 223 |
| |
| 224 | + | |
| 225 | + | |
205 | 226 |
| |
206 | 227 |
| |
207 | 228 |
| |
|
Lines changed: 33 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
339 | 339 |
| |
340 | 340 |
| |
341 | 341 |
| |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + |
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
253 | 253 |
| |
254 | 254 |
| |
255 | 255 |
| |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + |
0 commit comments
Comments
(0)