forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: prevent stack overflow when deriving computed column filters
Previously, a filter of the form `col IN (elem0, elem1, ..., elemN)` could result in a stack overflow in the optimizer when `N` is very large, e.g., 1.6 million or more . The problem would occur when trying to derive constraints for indexes on computed column, specifically when those computed columns are dependent on the column in the filter, e.g., `col` in the example. The current implementation builds an `OrExpr` tree with depth equal to the length of the `IN` list (see the TODO in `makeSpansForExpr` suggesting that this should be avoided). It then constructs a `FiltersItem` with the `OrExpr` tree as the condition, causing logical properties to be built for the expression. When building logical properties, the `OrExpr` tree is traversed recursively, which causes the stack to overflow when the tree is very deep. Now, a `FiltersItems` is never constructed, thus logical properties are not built for the `OrExpr` tree, avoiding this particular type of stack overflow. Fixes cockroachdb#132669 Release note (bug fix): A bug in the query optimizer which could cause CockroachDB nodes to crash in rare cases has been fixed. The bug could occur when a query contains a filter in the form `col IN (elem0, elem1, ..., elemN)` only when `N` is very large, e.g., 1.6+ million, and when `col` exists in a hash-sharded index or exists a table with an indexed, computed column dependent on `col`.
- Loading branch information
Showing
3 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters