forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commite3f005d
committed
Limit the number of index clauses considered in choose_bitmap_and().
classify_index_clause_usage() is O(N^2) in the number of distinct indexqual clauses it considers, because of its use of a simple search list tostore them. For nearly all queries, that's fine because only a few clauseswill be considered. But Alexander Kuzmenkov reported a machine-generatedquery with 80000 (!) index qual clauses, which caused this code to takeforever. Somewhat remarkably, this is the only O(N^2) behavior we nowhave for such a query, so let's fix it.We can get rid of the O(N^2) runtime for cases like this without muchdamage to the functionality of choose_bitmap_and() by separating outpaths with "too many" qual or pred clauses, and deeming them to alwaysbe nonredundant with other paths. Then their clauses needn't go intothe search list, so it doesn't get too long, but we don't lose theability to consider bitmap AND plans altogether. I set the thresholdfor "too many" to be 100 clauses per path, which should be plenty toensure no change in planning behavior for normal queries.There are other things we could do to make this go faster, but it's notclear that it's worth any additional effort. 80000 qual clauses requirea whole lot of work in many other places, too.The code's been like this for a long time, so back-patch to all supportedbranches. The troublesome query only works back to 9.5 (in 9.4 it failswith stack overflow in the parser); so I'm not sure that fixing this in9.4 has any real-world benefit, but perhaps it does.Discussion:https://postgr.es/m/90c5bdfa-d633-dabe-9889-3cf3e1acd443@postgrespro.ru1 parentffb6898 commite3f005d
1 file changed
+31
-1
lines changedLines changed: 31 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
67 | 67 |
| |
68 | 68 |
| |
69 | 69 |
| |
| 70 | + | |
70 | 71 |
| |
71 | 72 |
| |
72 | 73 |
| |
| |||
1447 | 1448 |
| |
1448 | 1449 |
| |
1449 | 1450 |
| |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
1450 | 1459 |
| |
1451 | 1460 |
| |
1452 |
| - | |
| 1461 | + | |
| 1462 | + | |
1453 | 1463 |
| |
1454 | 1464 |
| |
1455 | 1465 |
| |
| |||
1484 | 1494 |
| |
1485 | 1495 |
| |
1486 | 1496 |
| |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
1487 | 1501 |
| |
1488 | 1502 |
| |
1489 | 1503 |
| |
| |||
1711 | 1725 |
| |
1712 | 1726 |
| |
1713 | 1727 |
| |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
1714 | 1743 |
| |
1715 | 1744 |
| |
1716 | 1745 |
| |
| |||
1728 | 1757 |
| |
1729 | 1758 |
| |
1730 | 1759 |
| |
| 1760 | + | |
1731 | 1761 |
| |
1732 | 1762 |
| |
1733 | 1763 |
| |
|
0 commit comments
Comments
(0)