Commit 39a0f04
committed
Parser: fix exponential parse time on table-factor paren chains
`parse_table_factor` speculatively parses `(...)` as a derived table; on
failure it rewinds and falls through to `parse_table_and_joins`, which
recurses back into `parse_table_factor` and re-attempts the same
speculative parse at every deeper paren. Both arms walk the remaining
chain, so on inputs like `SELECT 1 FROM ((((...` work doubles per level.
Caching the position at which the speculative arm failed short-circuits
the second descent.
Measured on `GenericDialect` with `with_recursion_limit(256)`, release
build:
| N | Before | After |
|----|---------|--------|
| 10 | 20 ms | 57 us |
| 20 | 820 ms | 119 us |
| 25 | 2.8 s | 281 us |
| 30 | 7.9 s | 345 us |1 parent b376022 commit 39a0f04
3 files changed
Lines changed: 88 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
248 | 276 | | |
249 | 277 | | |
250 | 278 | | |
| |||
253 | 281 | | |
254 | 282 | | |
255 | 283 | | |
256 | | - | |
| 284 | + | |
| 285 | + | |
257 | 286 | | |
258 | 287 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
372 | 376 | | |
373 | 377 | | |
374 | 378 | | |
| |||
414 | 418 | | |
415 | 419 | | |
416 | 420 | | |
| 421 | + | |
417 | 422 | | |
418 | 423 | | |
419 | 424 | | |
| |||
477 | 482 | | |
478 | 483 | | |
479 | 484 | | |
| 485 | + | |
480 | 486 | | |
481 | 487 | | |
482 | 488 | | |
| |||
16172 | 16178 | | |
16173 | 16179 | | |
16174 | 16180 | | |
16175 | | - | |
16176 | | - | |
| 16181 | + | |
| 16182 | + | |
| 16183 | + | |
| 16184 | + | |
| 16185 | + | |
| 16186 | + | |
| 16187 | + | |
| 16188 | + | |
16177 | 16189 | | |
| 16190 | + | |
| 16191 | + | |
| 16192 | + | |
| 16193 | + | |
| 16194 | + | |
| 16195 | + | |
| 16196 | + | |
| 16197 | + | |
| 16198 | + | |
| 16199 | + | |
| 16200 | + | |
16178 | 16201 | | |
16179 | 16202 | | |
16180 | 16203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19111 | 19111 | | |
19112 | 19112 | | |
19113 | 19113 | | |
| 19114 | + | |
| 19115 | + | |
| 19116 | + | |
| 19117 | + | |
| 19118 | + | |
| 19119 | + | |
| 19120 | + | |
| 19121 | + | |
| 19122 | + | |
| 19123 | + | |
| 19124 | + | |
| 19125 | + | |
| 19126 | + | |
| 19127 | + | |
| 19128 | + | |
| 19129 | + | |
| 19130 | + | |
| 19131 | + | |
| 19132 | + | |
| 19133 | + | |
| 19134 | + | |
| 19135 | + | |
| 19136 | + | |
| 19137 | + | |
| 19138 | + | |
| 19139 | + | |
| 19140 | + | |
| 19141 | + | |
| 19142 | + | |
| 19143 | + | |
| 19144 | + | |
0 commit comments