This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dcm: optimization pass to evaluate constant sub-query expressions onl…
…y once Signed-off-by: Lalith Suresh <[email protected]>
- Loading branch information
1 parent
8071541
commit 7d59066
Showing
3 changed files
with
78 additions
and
71 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
42 changes: 42 additions & 0 deletions
42
dcm/src/main/java/com/vmware/dcm/backend/ortools/IsConstantSubquery.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2018-2020 VMware, Inc. All Rights Reserved. | ||
* SPDX-License-Identifier: BSD-2 | ||
*/ | ||
|
||
package com.vmware.dcm.backend.ortools; | ||
|
||
import com.vmware.dcm.compiler.monoid.ColumnIdentifier; | ||
import com.vmware.dcm.compiler.monoid.GroupByComprehension; | ||
import com.vmware.dcm.compiler.monoid.MonoidComprehension; | ||
import com.vmware.dcm.compiler.monoid.TableRowGenerator; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/* | ||
* Evaluates whether a sub-query (and its inner sub-queries etc.) can be treated as a constant expression. | ||
*/ | ||
public class IsConstantSubquery { | ||
|
||
static boolean apply(final MonoidComprehension expr) { | ||
final GetColumnIdentifiers visitor = new GetColumnIdentifiers(true); | ||
if (expr instanceof GroupByComprehension) { | ||
final MonoidComprehension comprehension = ((GroupByComprehension) expr).getComprehension(); | ||
comprehension.getHead().getSelectExprs().forEach(visitor::visit); | ||
comprehension.getQualifiers().forEach(visitor::visit); | ||
} else { | ||
expr.getHead().getSelectExprs().forEach(visitor::visit); | ||
expr.getQualifiers().forEach(visitor::visit); | ||
} | ||
final LinkedHashSet<ColumnIdentifier> columnIdentifiers = visitor.getColumnIdentifiers(); | ||
|
||
final Set<String> accessedTables = expr.getQualifiers() | ||
.stream().filter(q -> q instanceof TableRowGenerator) | ||
.map(e -> ((TableRowGenerator ) e).getTable().getAliasedName()) | ||
.collect(Collectors.toSet()); | ||
return columnIdentifiers.stream().allMatch( | ||
ci -> !ci.getField().isControllable() && accessedTables.contains(ci.getTableName()) | ||
); | ||
} | ||
} |
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