forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit4e2477b
committed
Fix strange behavior (and possible crashes) in full text phrase search.
In an attempt to simplify the tsquery matching engine, the originalphrase search patch invented rewrite rules that would rearrange atsquery so that no AND/OR/NOT operator appeared below a PHRASE operator.But this approach had numerous problems. The rearrangement step wasmissed by ts_rewrite (and perhaps other places), allowing tsqueriesto be created that would cause Assert failures or perhaps crashes atexecution, as reported by Andreas Seltenreich. The rewrite ruleseffectively defined semantics for operators underneath PHRASE that werebuggy, or at least unintuitive. And because rewriting was done intsqueryin() rather than at execution, the rearrangement was user-visible,which is not very desirable --- for example, it might cause unexpectedmatches or failures to match in ts_rewrite.As a somewhat independent problem, the behavior of nested PHRASE operatorswas only sane for left-deep trees; queries like "x <-> (y <-> z)" did notbehave intuitively at all.To fix, get rid of the rewrite logic altogether, and instead teach thetsquery execution engine to manage AND/OR/NOT below a PHRASE operatorby explicitly computing the match location(s) and match widths for theseoperators.This requires introducing some additional fields into the publicly visibleExecPhraseData struct; but since there's no way for third-party code topass such a struct to TS_phrase_execute, it shouldn't create an ABI problemas long as we don't move the offsets of the existing fields.Another related problem was that index searches supposed that "!x <-> y"could be lossily approximated as "!x & y", which isn't correct becausethe latter will reject, say, "x q y" which the query itself accepts.This required some tweaking in TS_execute_ternary along with the maintsquery engine.Back-patch to 9.6 where phrase operators were introduced. While thiscould be argued to change behavior more than we'd like in a stable branch,we have to do something about the crash hazards and index-vs-seqscaninconsistency, and it doesn't seem desirable to let the unintuitivebehaviors induced by the rewriting implementation stand as precedent.Discussion:https://postgr.es/m/28215.1481999808@sss.pgh.pa.usDiscussion:https://postgr.es/m/26706.1482087250@sss.pgh.pa.us1 parenteaac6c7 commit4e2477b
File tree
14 files changed
+673
-599
lines changed- doc/src/sgml
- src
- backend/utils/adt
- include/tsearch
- test/regress
- expected
- sql
14 files changed
+673
-599
lines changedLines changed: 0 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3959 | 3959 |
| |
3960 | 3960 |
| |
3961 | 3961 |
| |
3962 |
| - | |
3963 |
| - | |
3964 |
| - | |
3965 |
| - | |
3966 |
| - | |
3967 | 3962 |
| |
3968 |
| - | |
3969 |
| - | |
3970 |
| - | |
3971 | 3963 |
| |
3972 | 3964 |
| |
3973 | 3965 |
| |
|
Lines changed: 25 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
264 | 264 |
| |
265 | 265 |
| |
266 | 266 |
| |
267 |
| - | |
| 267 | + | |
268 | 268 |
| |
269 | 269 |
| |
270 | 270 |
| |
| |||
323 | 323 |
| |
324 | 324 |
| |
325 | 325 |
| |
| 326 | + | |
| 327 | + | |
326 | 328 |
| |
327 | 329 |
| |
328 | 330 |
| |
| |||
377 | 379 |
| |
378 | 380 |
| |
379 | 381 |
| |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
380 | 404 |
| |
381 | 405 |
| |
382 | 406 |
| |
|
Lines changed: 18 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
212 | 212 |
| |
213 | 213 |
| |
214 | 214 |
| |
215 |
| - | |
| 215 | + | |
216 | 216 |
| |
217 | 217 |
| |
218 | 218 |
| |
| |||
230 | 230 |
| |
231 | 231 |
| |
232 | 232 |
| |
233 |
| - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
234 | 237 |
| |
235 | 238 |
| |
236 | 239 |
| |
237 | 240 |
| |
238 | 241 |
| |
239 | 242 |
| |
240 | 243 |
| |
241 |
| - | |
| 244 | + | |
242 | 245 |
| |
243 | 246 |
| |
244 |
| - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
245 | 251 |
| |
246 | 252 |
| |
247 | 253 |
| |
248 |
| - | |
| 254 | + | |
| 255 | + | |
249 | 256 |
| |
250 | 257 |
| |
251 |
| - | |
| 258 | + | |
252 | 259 |
| |
253 | 260 |
| |
254 | 261 |
| |
| |||
257 | 264 |
| |
258 | 265 |
| |
259 | 266 |
| |
260 |
| - | |
| 267 | + | |
| 268 | + | |
261 | 269 |
| |
262 | 270 |
| |
263 |
| - | |
| 271 | + | |
264 | 272 |
| |
265 | 273 |
| |
266 | 274 |
| |
| |||
307 | 315 |
| |
308 | 316 |
| |
309 | 317 |
| |
310 |
| - | |
| 318 | + | |
311 | 319 |
| |
312 | 320 |
| |
313 | 321 |
| |
| |||
343 | 351 |
| |
344 | 352 |
| |
345 | 353 |
| |
346 |
| - | |
| 354 | + | |
347 | 355 |
| |
348 | 356 |
| |
349 | 357 |
| |
|
Lines changed: 7 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
359 | 359 |
| |
360 | 360 |
| |
361 | 361 |
| |
362 |
| - | |
363 |
| - | |
| 362 | + | |
| 363 | + | |
364 | 364 |
| |
365 |
| - | |
366 |
| - | |
367 |
| - | |
| 365 | + | |
| 366 | + | |
368 | 367 |
| |
369 | 368 |
| |
370 | 369 |
| |
371 | 370 |
| |
372 | 371 |
| |
373 | 372 |
| |
374 | 373 |
| |
375 |
| - | |
376 |
| - | |
| 374 | + | |
377 | 375 |
| |
378 |
| - | |
379 |
| - | |
380 |
| - | |
| 376 | + | |
| 377 | + | |
381 | 378 |
| |
382 | 379 |
| |
383 | 380 |
| |
|
Lines changed: 13 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
557 | 557 |
| |
558 | 558 |
| |
559 | 559 |
| |
560 |
| - | |
561 |
| - | |
562 |
| - | |
563 | 560 |
| |
564 | 561 |
| |
565 | 562 |
| |
566 | 563 |
| |
| 564 | + | |
567 | 565 |
| |
568 | 566 |
| |
569 | 567 |
| |
| |||
574 | 572 |
| |
575 | 573 |
| |
576 | 574 |
| |
577 |
| - | |
578 |
| - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
579 | 578 |
| |
580 | 579 |
| |
581 | 580 |
| |
| |||
687 | 686 |
| |
688 | 687 |
| |
689 | 688 |
| |
690 |
| - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
691 | 693 |
| |
692 | 694 |
| |
693 | 695 |
| |
694 |
| - | |
695 |
| - | |
| 696 | + | |
696 | 697 |
| |
697 | 698 |
| |
698 |
| - | |
| 699 | + | |
699 | 700 |
| |
700 | 701 |
| |
701 | 702 |
| |
| |||
1088 | 1089 |
| |
1089 | 1090 |
| |
1090 | 1091 |
| |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
1091 | 1095 |
| |
1092 | 1096 |
| |
1093 | 1097 |
| |
| |||
1105 | 1109 |
| |
1106 | 1110 |
| |
1107 | 1111 |
| |
1108 |
| - | |
1109 |
| - | |
1110 |
| - | |
1111 | 1112 |
| |
1112 | 1113 |
| |
1113 | 1114 |
| |
|
0 commit comments
Comments
(0)