Alessandro Solimando created CALCITE-7956:
---------------------------------------------
Summary: LongBitmap.SubsetIterator produces OOM in DpHyp wide joins
Key: CALCITE-7956
URL: https://issues.apache.org/jira/browse/CALCITE-7956
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.42.0
Reporter: Alessandro Solimando
Assignee: Alessandro Solimando
Fix For: 1.43.0
_LongBitmap.SubsetIterator_ computes all the non-empty subsets of its bitmap in
the constructor and stores them as boxed _Long_ values in an {_}ArrayList{_},
before the first one is returned
([here|https://github.com/apache/calcite/blob/647e8f288b62d3fa594e901da5428f2c545f0609/core/src/main/java/org/apache/calcite/rel/rules/LongBitmap.java#L112-L122]):
{code:java}
public SubsetIterator(long bitmap) {
long curBiggestSubset = bitmap;
this.subsetList = new ArrayList<>();
while (curBiggestSubset != 0) {
subsetList.add(curBiggestSubset);
curBiggestSubset = (curBiggestSubset - 1) & bitmap;
}
this.index = subsetList.size() - 1;
}
{code}
_DpHyp_ creates one of these iterators over the neighbors of the current
subgraph at every step of _enumerateCsgRec_
([here|https://github.com/apache/calcite/blob/647e8f288b62d3fa594e901da5428f2c545f0609/core/src/main/java/org/apache/calcite/rel/rules/DpHyp.java#L150-L152])
and _enumerateCmpRec_
([here|https://github.com/apache/calcite/blob/647e8f288b62d3fa594e901da5428f2c545f0609/core/src/main/java/org/apache/calcite/rel/rules/DpHyp.java#L175-L177]).
For a subgraph with k neighbors, this allocates 2^k - 1 objects, so a star join
whose hub has a few dozen neighbors runs out of memory before any plan is
enumerated.
The bloat limit of _DpHyp_ does not prevent this, because it is checked only
when a plan is emitted
([here|https://github.com/apache/calcite/blob/647e8f288b62d3fa594e901da5428f2c545f0609/core/src/main/java/org/apache/calcite/rel/rules/DpHyp.java#L306]),
after the list has been built.
Reproducer (for a new {_}LongBitmapTest{_}):
{code:java}
@Test void testSubsetIteratorOnWideBitmap() {
final long bitmap = LongBitmap.newBitmapBetween(0, 30);
final Iterator<Long> subsets = new
LongBitmap.SubsetIterator(bitmap).iterator();
assertThat(subsets.next(), is(1L));
}
{code}
The test currently fails as follows, with the default test heap of 1536 MB:
{noformat}
java.lang.OutOfMemoryError: Java heap space
{noformat}
Proposed fix: compute each subset when it is requested, instead of in the
constructor. The subsets and their order stay the same, so the plans produced
by DpHyp do not change.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)