Skip to content

Commit

Permalink
[BugFix] Fix oom problem in complex type prune (backport #49113) (#49133
Browse files Browse the repository at this point in the history
)

Co-authored-by: Smith Cruise <[email protected]>
  • Loading branch information
mergify[bot] and Smith-Cruise authored Jul 30, 2024
1 parent 171c833 commit 3760787
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@

package com.starrocks.catalog;

import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;

// Record ColumnRefOperator's each ComplexTypeAccessPaths
// We have to use HashSet to deduplicate same ComplexTypeAccessPaths, it can avoid oom problem
public class ComplexTypeAccessGroup {
private final List<ComplexTypeAccessPaths> accessPaths = new ArrayList<>();

public int size() {
return accessPaths.size();
}

public ComplexTypeAccessPaths get(int idx) {
return accessPaths.get(idx);
}
private final Set<ComplexTypeAccessPaths> accessPaths = new HashSet<>();

public void addAccessPaths(ComplexTypeAccessPaths complexTypeAccessPaths) {
accessPaths.add(complexTypeAccessPaths);
}

public List<ComplexTypeAccessPaths> getAccessGroup() {
public Set<ComplexTypeAccessPaths> getAccessGroup() {
return accessPaths;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.starrocks.catalog;

import java.util.Objects;

public class ComplexTypeAccessPath {
private final ComplexTypeAccessPathType accessPathType;

Expand All @@ -36,4 +38,25 @@ public ComplexTypeAccessPathType getAccessPathType() {
public String getStructSubfieldName() {
return this.structSubfieldName;
}

@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ComplexTypeAccessPath)) {
return false;
}

ComplexTypeAccessPath that = (ComplexTypeAccessPath) o;
return accessPathType == that.accessPathType &&
Objects.equals(structSubfieldName, that.structSubfieldName);
}

@Override
public int hashCode() {
int result = Objects.hashCode(accessPathType);
result = 31 * result + Objects.hashCode(structSubfieldName);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

package com.starrocks.catalog;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import java.util.Objects;

public class ComplexTypeAccessPaths {
private final ImmutableList<ComplexTypeAccessPath> accessPaths;

public ComplexTypeAccessPaths(ImmutableList<ComplexTypeAccessPath> accessPaths) {
Preconditions.checkNotNull(accessPaths, "accessPaths can't be null");
this.accessPaths = accessPaths;
}

Expand All @@ -38,4 +42,22 @@ public boolean isEmpty() {
public ImmutableList<ComplexTypeAccessPath> getAccessPaths() {
return accessPaths;
}

@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ComplexTypeAccessPaths)) {
return false;
}

ComplexTypeAccessPaths that = (ComplexTypeAccessPaths) o;
return Objects.equals(accessPaths, that.accessPaths);
}

@Override
public int hashCode() {
return Objects.hashCode(accessPaths);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ public void addAccessPaths(ColumnRefOperator columnRefOperator, ComplexTypeAcces
public void addAccessPaths(ColumnRefOperator columnRefOperator,
ComplexTypeAccessPaths curAccessPaths,
ComplexTypeAccessGroup visitedAccessGroup) {
int size = visitedAccessGroup.size();
// We should we below loop to avoid ConcurrentModificationException
for (int i = 0; i < size; i++) {
addAccessPaths(columnRefOperator, concatAccessPaths(curAccessPaths, visitedAccessGroup.get(i)));
// We should copy it first to avoid ConcurrentModificationException
ImmutableList<ComplexTypeAccessPaths> accessGroup = ImmutableList.<ComplexTypeAccessPaths>builder().addAll(
visitedAccessGroup.getAccessGroup()).build();
for (ComplexTypeAccessPaths complexTypeAccessPaths : accessGroup) {
addAccessPaths(columnRefOperator, concatAccessPaths(curAccessPaths, complexTypeAccessPaths));
}
}

Expand Down

0 comments on commit 3760787

Please sign in to comment.