From 984106ed930c9138ca6797fdb2117dea273d2a03 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 17 Dec 2024 13:51:45 +0100 Subject: [PATCH] fixed routing catch to even add routed plan, added missing metadata --- .../db/processing/AbstractQueryProcessor.java | 9 ++++++--- .../db/processing/caching/RoutingPlanCache.java | 2 ++ .../db/routing/dto/CachedProposedRoutingPlan.java | 10 ++++++---- .../org/polypheny/db/routing/routers/SimpleRouter.java | 4 +++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java index e3b2934e77..5f5db9f6b8 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -1382,10 +1382,13 @@ private void finalizeAccessedPartitions( StatementEvent eventData ) { private void cacheRouterPlans( List proposedRoutingPlans, List approximatedCosts, String queryId, Set partitionIds ) { - List cachedPlans = new ArrayList<>(); + List cachedPlans = new ArrayList<>( RoutingPlanCache.INSTANCE.getIfPresent( queryId, partitionIds ) ); for ( int i = 0; i < proposedRoutingPlans.size(); i++ ) { - if ( proposedRoutingPlans.get( i ).isCacheable() && !RoutingPlanCache.INSTANCE.isKeyPresent( queryId, partitionIds ) ) { - cachedPlans.add( new CachedProposedRoutingPlan( proposedRoutingPlans.get( i ), approximatedCosts.get( i ) ) ); + if ( proposedRoutingPlans.get( i ).isCacheable() ) { + CachedProposedRoutingPlan plan = new CachedProposedRoutingPlan( proposedRoutingPlans.get( i ), approximatedCosts.get( i ) ); + if ( !cachedPlans.contains( plan ) ) { + cachedPlans.add( plan ); + } } } diff --git a/dbms/src/main/java/org/polypheny/db/processing/caching/RoutingPlanCache.java b/dbms/src/main/java/org/polypheny/db/processing/caching/RoutingPlanCache.java index 552002b0ae..9053de028f 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/caching/RoutingPlanCache.java +++ b/dbms/src/main/java/org/polypheny/db/processing/caching/RoutingPlanCache.java @@ -26,6 +26,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.polypheny.db.config.RuntimeConfig; import org.polypheny.db.information.InformationAction; import org.polypheny.db.information.InformationGraph; @@ -69,6 +70,7 @@ public boolean isKeyPresent( String queryId, Set partitionIds ) { } + @NotNull public List getIfPresent( String queryId, Set partitionIds ) { List routingPlans = planCache.getIfPresent( Pair.of( queryId, partitionIds ) ); if ( routingPlans == null ) { diff --git a/dbms/src/main/java/org/polypheny/db/routing/dto/CachedProposedRoutingPlan.java b/dbms/src/main/java/org/polypheny/db/routing/dto/CachedProposedRoutingPlan.java index 8e7d57a1aa..9e3dd00c19 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/dto/CachedProposedRoutingPlan.java +++ b/dbms/src/main/java/org/polypheny/db/routing/dto/CachedProposedRoutingPlan.java @@ -18,6 +18,7 @@ import lombok.Getter; import lombok.Setter; +import lombok.Value; import org.polypheny.db.plan.AlgOptCost; import org.polypheny.db.routing.ColumnDistribution.RoutedDistribution; import org.polypheny.db.routing.FieldDistribution; @@ -31,6 +32,7 @@ */ @Getter @Setter +@Value public class CachedProposedRoutingPlan implements RoutingPlan { @Getter @@ -38,10 +40,10 @@ public class CachedProposedRoutingPlan implements RoutingPlan { @Getter public FieldDistribution fieldDistribution; // PartitionId -> List - protected String queryClass; - protected String physicalQueryClass; - protected AlgOptCost preCosts; - protected Class router; + String queryClass; + String physicalQueryClass; + AlgOptCost preCosts; + Class router; public CachedProposedRoutingPlan( ProposedRoutingPlan routingPlan, AlgOptCost approximatedCosts ) { diff --git a/dbms/src/main/java/org/polypheny/db/routing/routers/SimpleRouter.java b/dbms/src/main/java/org/polypheny/db/routing/routers/SimpleRouter.java index 5ddaa11c3f..e0081817cd 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/routers/SimpleRouter.java +++ b/dbms/src/main/java/org/polypheny/db/routing/routers/SimpleRouter.java @@ -62,7 +62,9 @@ protected List handleNonePartitioning( AlgNode node, LogicalTa List entities = Catalog.snapshot().alloc().getFromLogical( table.id ); List partitionId = List.of( entities.get( 0 ).partitionId ); - context.fieldDistribution = new ColumnDistribution( table.id, table.getColumnIds(), partitionId, partitionId, List.of(), context.getSnapshot() ); + ColumnDistribution columnDistribution = new ColumnDistribution( table.id, table.getColumnIds(), partitionId, partitionId, List.of(), context.getSnapshot() ); + context.fieldDistribution = columnDistribution; + context.routedDistribution = columnDistribution.route(); // Only one builder available super.handleRelScan( builders.get( 0 ), context.getStatement(), entities.get( 0 ) );