Skip to content
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

fix(interactive): Enhance Support for Optimizing IC Benchmark Queries #4294

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion interactive_engine/compiler/src/main/antlr4/CypherGS.g4
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,26 @@ CALL : ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ;
YIELD : ( 'Y' | 'y' ) ( 'I' | 'i' ) ( 'E' | 'e' ) ( 'L' | 'l' ) ( 'D' | 'd' ) ;

oC_RegularQuery
: oC_Match ( SP? ( oC_Match | oC_With | oC_Unwind ) )* ( SP oC_Return ) ;
: ( oC_ReadingClause SP? )* SP? oC_ReadingClause ( SP oC_Return )
;

oC_ReadingClause
: oC_Match
| oC_Unwind
| oC_With
| oC_UnionCallSubQuery
;

oC_SubQuery
: ( ( oC_Match | oC_With | oC_Unwind ) SP? )* ( SP? oC_Return ) ;

oC_CallSubQuery
: CALL SP? '{' SP? oC_SubQuery SP? '}';

oC_UnionCallSubQuery
: oC_CallSubQuery ( SP? UNION SP? oC_CallSubQuery )* ;

UNION : ( 'U' | 'u' ) ( 'N' | 'n' ) ( 'I' | 'i' ) ( 'O' | 'o' ) ( 'N' | 'n' ) ;

oC_Match
: ( OPTIONAL SP )? MATCH SP? oC_Pattern ( SP? oC_Where )? ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.alibaba.graphscope.common.ir.meta.IrMeta;
import com.alibaba.graphscope.common.ir.meta.glogue.calcite.GraphRelMetadataQuery;
import com.alibaba.graphscope.common.ir.meta.glogue.calcite.handler.GraphMetadataHandlerProvider;
import com.alibaba.graphscope.common.ir.meta.schema.CommonOptTable;
import com.alibaba.graphscope.common.ir.rel.CommonTableScan;
import com.alibaba.graphscope.common.ir.rel.GraphShuttle;
import com.alibaba.graphscope.common.ir.rel.graph.GraphLogicalSource;
import com.alibaba.graphscope.common.ir.rel.graph.match.AbstractLogicalMatch;
Expand All @@ -32,6 +34,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.apache.calcite.plan.GraphOptCluster;
import org.apache.calcite.plan.RelOptPlanner;
Expand All @@ -45,6 +48,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

/**
Expand Down Expand Up @@ -100,10 +104,26 @@ public RelNode optimize(RelNode before, GraphIOProcessor ioProcessor) {
public static class MatchOptimizer extends GraphShuttle {
private final GraphIOProcessor ioProcessor;
private final RelOptPlanner matchPlanner;
// record the common rel(s) which has been optimized
private final Map<String, RelNode> commonTableToOpt;

public MatchOptimizer(GraphIOProcessor ioProcessor, RelOptPlanner matchPlanner) {
this.ioProcessor = ioProcessor;
this.matchPlanner = matchPlanner;
this.commonTableToOpt = Maps.newHashMap();
}

@Override
public RelNode visit(CommonTableScan tableScan) {
CommonOptTable optTable = (CommonOptTable) tableScan.getTable();
String tableName = optTable.getQualifiedName().get(0);
RelNode commonOpt = commonTableToOpt.get(tableName);
if (commonOpt == null) {
commonOpt = optTable.getCommon().accept(this);
commonTableToOpt.put(tableName, commonOpt);
}
return new CommonTableScan(
tableScan.getCluster(), tableScan.getTraitSet(), new CommonOptTable(commonOpt));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public synchronized RelNode optimize(RelNode before, GraphIOProcessor ioProcesso
// apply rules of 'FilterPushDown' before the match optimization
relPlanner.setRoot(before);
RelNode relOptimized = relPlanner.findBestExp();
if (config.getRules().contains(FlatJoinToExpandRule.class.getSimpleName())) {
relOptimized = relOptimized.accept(new FlatJoinToExpandRule(config));
}
if (config.getOpt() == PlannerConfig.Opt.CBO) {
relOptimized =
relOptimized.accept(
Expand Down
Loading
Loading