| 49 | |
| 50 | |
| 51 | Just for reference, my full post was this: |
| 52 | |
| 53 | |
| 54 | ---- |
| 55 | |
| 56 | {{{ |
| 57 | I've been trying to troubleshoot the cause of this PostGIS recheck bug we |
| 58 | have reported by two people so far. The last test was a nice simple |
| 59 | repeatable one that triggered the issue: |
| 60 | |
| 61 | https://trac.osgeo.org/postgis/ticket/3418 |
| 62 | |
| 63 | |
| 64 | from what I have seen this only affects cases where we are doing a distance |
| 65 | check between two points, which we actually don't need to enable recheck for |
| 66 | anyway, but trying to disable that seems like just shoving the real problem |
| 67 | under the covers. |
| 68 | Where it errors is this line 272 in src/backend/executor/nodeIndexscan |
| 69 | |
| 70 | https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/exe |
| 71 | cutor/nodeIndexscan.c;h=3143bd94ec4499fba94b41693538b785c4b32e6c;hb=HEAD#l27 |
| 72 | 2 |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | 259 * Was the ORDER BY value returned by the index accurate? |
| 77 | The |
| 78 | 260 * recheck flag means that the index can return inaccurate |
| 79 | values, |
| 80 | 261 * but then again, the value returned for any particular |
| 81 | tuple |
| 82 | 262 * could also be exactly correct. Compare the value |
| 83 | returned by |
| 84 | 263 * the index with the recalculated value. (If the value |
| 85 | returned |
| 86 | 264 * by the index happened to be exact right, we can often |
| 87 | avoid |
| 88 | 265 * pushing the tuple to the queue, just to pop it back out |
| 89 | again.) |
| 90 | 266 */ |
| 91 | 267 cmp = cmp_orderbyvals(node->iss_OrderByValues, |
| 92 | 268 node->iss_OrderByNulls, |
| 93 | 269 scandesc->xs_orderbyvals, |
| 94 | 270 scandesc->xs_orderbynulls, |
| 95 | 271 node); |
| 96 | 272 if (cmp < 0) |
| 97 | 273 elog(ERROR, "index returned tuples in wrong order"); |
| 98 | 274 else if (cmp == 0) |
| 99 | 275 was_exact = true; |
| 100 | 276 else |
| 101 | 277 was_exact = false; |
| 102 | |
| 103 | If things are out of order, why isn't just going to was_exact = false good |
| 104 | enough? |
| 105 | |
| 106 | I'm not sure if the mistake is in our PostGIS code or something in |
| 107 | PostgreSQL recheck logic. |
| 108 | If I change the elog(ERROR ...) to a elog(NOTICE, the answers are correct |
| 109 | and sort order is right. |
| 110 | |
| 111 | Under what conditions would cmp return less than 0? I tried following the |
| 112 | code in cmp_orderbyvals, but got lost |
| 113 | and trying to put elog notices in to see what the distance is returning (I |
| 114 | probably did it wrong), just ended up crashing by backend. |
| 115 | |
| 116 | |
| 117 | Thanks for any thoughts, |
| 118 | Regina |
| 119 | }}} |
| 120 | |
| 121 | ---- |
| 122 | |
| 123 | |
| 124 | The git commit he references we can look for for guidance is this one: |
| 125 | https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=35fcb1b3d038a501f3f4c87c05630095abaaadab |
| 126 | |
| 127 | {{{ |
| 128 | Allow GiST distance function to return merely a lower-bound. |
| 129 | |
| 130 | The distance function can now set *recheck = false, like index quals. The |
| 131 | executor will then re-check the ORDER BY expressions, and use a queue to |
| 132 | reorder the results on the fly. |
| 133 | |
| 134 | This makes it possible to do kNN-searches on polygons and circles, which |
| 135 | don't store the exact value in the index, but just a bounding box. |
| 136 | |
| 137 | Alexander Korotkov and me |
| 138 | }}} |
| 139 | |
| 140 | |