-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] skip optimizer lock for materialized view #34569
Conversation
Signed-off-by: Murphy <mofei@starrocks.com>
Signed-off-by: Murphy <mofei@starrocks.com>
mv.partitionRefTableExprs = Lists.newArrayList(this.partitionRefTableExprs); | ||
} | ||
} | ||
|
||
@Override | ||
public MaterializedView selectiveCopy(Collection<String> reservedPartitions, boolean resetState, | ||
MaterializedIndex.IndexExtState extState) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code snippet you've provided appears to be from a Java application that deals with refreshing schemes and query copying for objects related to database tables or Materialized Views. The key points from the given code are:
- Implementation of the
copy()
method in theMvRefreshScheme
class. - Overrides of the
copyOnlyForQuery()
method in what looks like an extension or specialization of theOlapTable
class, possibly namedMaterializedView
.
Here are some suggestions for the code review:
Cloning/Copying Objects:
- In the
copy()
method ofMvRefreshScheme
, you are performing a shallow copy for the fieldstype
andlastRefreshTime
, which is fine if they are immutable. - However, if the
asyncRefreshContext
has mutable state that might be changed elsewhere, then itscopy()
method also needs to ensure it performs a deep copy to avoid shared mutable state issues.
Potential Null Dereference:
- When calling
this.asyncRefreshContext.copy()
, it seems you're assumingcopy()
exists and is public. Ensure that this method is indeed present and properly implements the deep copy if necessary. IfasyncRefreshContext
can be null, which seems to be checked, make sure that itscopy
method handles null values accordingly or isn't called on a null reference.
Type Safety:
- Using raw types like
Sets.newHashSet(this.baseTableIds)
andLists.newArrayList(this.baseTableInfos)
is type-safe, but it doesn't inform about the type of elements these collections contain. Use generic types if possible for better compile-time type checking, e.g.,Sets.<Type>newHashSet(this.baseTableIds)
whereType
is the actual data type of elements inbaseTableIds
.
Cost of Copying:
- Methods like
copyOnlyForQuery()
perform the copying of various data structures like sets and lists. Consider the size of these structures and the frequency of the copy operation as it could be costly in terms of performance.
Design/Architecture:
- Deep copying usually indicates that there's a significant alteration between instances that requires a new instance to be isolated from the original one. Reevaluate whether there's room for improvement in sharing data instead of copying if possible (
immutable objects
,shared references
with no mutations, etc.), which can reduce memory footprint and improve performance.
General Coding Practices:
- Always check any other object fields (like in
MaterializedView
) that might also require copying. - Wherever applicable, consider implementing
Cloneable
interface and useclone()
method (with proper handling ofCloneNotSupportedException
), although it should be noted thatclone()
has its own set of pitfalls and is not commonly recommended. - Document the behavior clearly where a method does a deep copy vs. a shallow copy, outlining the implications of using each.
Kudos, SonarCloud Quality Gate passed!
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 53 / 57 (92.98%) file detail
|
@Mergifyio backport branch-3.2 |
@Mergifyio backport branch-3.1 |
@Mergifyio backport branch-3.0 |
@Mergifyio backport branch-2.5 |
✅ Backports have been created
|
✅ Backports have been created
|
✅ Backports have been created
|
✅ Backports have been created
|
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541)
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java # fe/fe-core/src/main/java/com/starrocks/sql/StatementPlanner.java # fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AnalyzerUtils.java
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java # fe/fe-core/src/main/java/com/starrocks/sql/StatementPlanner.java
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java # fe/fe-core/src/main/java/com/starrocks/sql/StatementPlanner.java # fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AnalyzerUtils.java
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541)
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java # fe/fe-core/src/main/java/com/starrocks/sql/StatementPlanner.java
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java # fe/fe-core/src/main/java/com/starrocks/sql/StatementPlanner.java # fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AnalyzerUtils.java
Signed-off-by: Murphy <mofei@starrocks.com> (cherry picked from commit 9774541) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/catalog/MaterializedView.java # fe/fe-core/src/main/java/com/starrocks/sql/StatementPlanner.java # fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AnalyzerUtils.java
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: