Re: fix for BUG #3720: wrong results at using ltree
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nikita Glukhov <n.gluhov@postgrespro.ru>
Cc: Pgsql Hackers <pgsql-hackers@postgresql.org>, Filip Rembiałkowski <filip.rembialkowski@gmail.com>, Tomas Vondra <tomas.vondra@2ndquadrant.com>, Alexander Korotkov <a.korotkov@postgrespro.ru>, Oleg Bartunov <obartunov@postgrespro.ru>, Thomas Munro <thomas.munro@gmail.com>, Teodor Sigaev <teodor@sigaev.ru>
Date: 2020-03-31T15:47:30Z
Lists: pgsql-hackers
I wrote:
> I've marked this RFC, and will push tomorrow unless somebody wants
> to object to the loss of backwards compatibility.
And done. I noticed in some final testing that it's possible to
make this code take a long time by forcing it to backtrack a lot:
regression=# SELECT (('1' || repeat('.1', 65534))::ltree) ~ '*.*.x';
?column?
----------
f
(1 row)
Time: 54015.421 ms (00:54.015)
so I threw in a CHECK_FOR_INTERRUPTS(). Maybe it'd be worth trying
to optimize such cases, but I'm not sure that it'd ever matter for
real-world cases with reasonable-size label strings.
The old implementation seems to handle that particular case well,
evidently because it more-or-less folds adjacent stars together.
However, before anyone starts complaining about regressions, they
should note that it's really easy to get the old code to fail
via stack overflow:
regression=# SELECT (('1' || repeat('.1', 65534))::ltree) ~ '*.!1.*';
ERROR: stack depth limit exceeded
(That's as of five minutes ago, before that it dumped core.)
So I don't feel bad about the tradeoff. At least now we have
simple, visibly correct code that could serve as a starting
point for optimization if anyone feels the need to.
regards, tom lane
Commits
-
Back-patch addition of stack overflow and interrupt checks for lquery.
- fade4d4dffca 11.8 landed
- e48ff22d39db 9.6.18 landed
- cffa57f52cc4 9.5.22 landed
- 94c9152dc880 12.3 landed
- 8b902e438608 10.13 landed
-
Fix lquery's NOT handling, and add ability to quantify non-'*' items.
- 70dc4c509b33 13.0 landed
-
Improve error messages in ltree_in and lquery_in.
- e07e2a40bd0c 13.0 landed
-
Fix lquery's behavior for consecutive '*' items.
- 9950c8aadf0e 13.0 landed
-
Protect against overflow of ltree.numlevel and lquery.numlevel.
- 8e1e630d004e 9.5.22 landed
- 95f7ddfdad99 13.0 landed
- 5feb3d0b3f6b 11.8 landed
- 39491aa0da48 9.6.18 landed
- 2bb6bdbe5da7 12.3 landed
- 2618ac6c6535 10.13 landed