From 5b48ff96ff2e13027ad8d85e4ba335466202127e Mon Sep 17 00:00:00 2001 From: Tobias Hafner Date: Sat, 11 Jan 2025 09:56:15 +0100 Subject: [PATCH] Prevent caching of version numbers --- .../db/algebra/core/common/Identifier.java | 4 +--- .../enumerable/EnumerableIdentifier.java | 14 ++++++++++---- .../enumerable/EnumerableIdentifierRule.java | 2 +- .../enumerable/EnumerableInterpretable.java | 2 ++ .../document/LogicalDocIdentifier.java | 10 +++++----- .../logical/lpg/LogicalLpgIdentifier.java | 19 +++++++++++-------- .../relational/LogicalRelIdentifier.java | 10 +++++----- .../transaction/locking/AlgTreeRewriter.java | 3 --- 8 files changed, 35 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java b/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java index c71189605d..f8db2a7825 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java @@ -28,12 +28,10 @@ public class Identifier extends SingleAlg { protected final Entity entity; - protected final long version; - protected Identifier( AlgCluster cluster, AlgTraitSet traits, long version, Entity entity, AlgNode input ) { + protected Identifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input ) { super( cluster, traits, input ); this.entity = entity; - this.version = version; } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java index cfe3765372..8ed0b7e775 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java @@ -42,12 +42,18 @@ public class EnumerableIdentifier extends Identifier implements EnumerableAlg { - protected EnumerableIdentifier( AlgCluster cluster, AlgTraitSet traits, long version, Entity entity, AlgNode input ) { - super( cluster, traits, version, entity, input ); + protected EnumerableIdentifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input ) { + super( cluster, traits, entity, input ); assert getConvention() instanceof EnumerableConvention; } + @Override + public boolean isImplementationCacheable() { + return false; + } + + @Override public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { double dRows = mq.getTupleCount( getInput() ); @@ -57,7 +63,7 @@ public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { @Override public AlgNode copy( AlgTraitSet traitSet, List inputs ) { - return new EnumerableIdentifier( inputs.get( 0 ).getCluster(), traitSet, version, entity, inputs.get( 0 ) ); + return new EnumerableIdentifier( inputs.get( 0 ).getCluster(), traitSet, entity, inputs.get( 0 ) ); } @@ -70,7 +76,7 @@ public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { Expression input_ = builder.append( "input", result.block() ); Expression entityId_ = Expressions.constant( entity.getId() ); - Expression version_ = Expressions.constant( version ); + Expression version_ = Expressions.constant( implementor.map.get(IdentifierUtils.VERSION_KEY), long.class); Expression identification_ = null; switch ( input.getModel() ) { case RELATIONAL -> { diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifierRule.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifierRule.java index 382d495014..1057a63333 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifierRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifierRule.java @@ -41,7 +41,7 @@ public AlgNode convert( AlgNode alg ) { final Identifier identifier = (Identifier) alg; final AlgTraitSet traits = identifier.getTraitSet().replace( EnumerableConvention.INSTANCE ); final AlgNode input = convert(identifier.getInput(), identifier.getInput().getTraitSet().replace( EnumerableConvention.INSTANCE )); - return new EnumerableIdentifier( identifier.getCluster(), traits, identifier.getVersion(), identifier.getEntity(), input ); + return new EnumerableIdentifier( identifier.getCluster(), traits, identifier.getEntity(), input ); } } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableInterpretable.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableInterpretable.java index f90c1f279c..91b67793d7 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableInterpretable.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableInterpretable.java @@ -71,6 +71,7 @@ import org.polypheny.db.runtime.Typed; import org.polypheny.db.runtime.Utilities; import org.polypheny.db.transaction.Statement; +import org.polypheny.db.transaction.locking.IdentifierUtils; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.Pair; import org.polypheny.db.util.Util; @@ -114,6 +115,7 @@ public static Pair, String> toBindable( EnumerableAlg alg, EnumerableAlg.Prefer prefer, Statement statement ) { + parameters.put( IdentifierUtils.VERSION_KEY, statement.getTransaction().getSequenceNumber() ); EnumerableAlgImplementor algImplementor = new EnumerableAlgImplementor( alg.getCluster().getRexBuilder(), parameters ); final ClassDeclaration expr = algImplementor.implementRoot( alg, prefer ); diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocIdentifier.java index 94f2911e53..df08953160 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocIdentifier.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocIdentifier.java @@ -29,15 +29,15 @@ public class LogicalDocIdentifier extends Identifier implements DocumentAlg { - protected LogicalDocIdentifier( long version, Entity entity, AlgCluster cluster, AlgTraitSet traits, AlgNode input ) { - super( cluster, traits, version, entity, input ); + protected LogicalDocIdentifier( Entity entity, AlgCluster cluster, AlgTraitSet traits, AlgNode input ) { + super( cluster, traits, entity, input ); } - public static LogicalDocIdentifier create( long version, Entity document, final AlgNode input ) { + public static LogicalDocIdentifier create( Entity document, final AlgNode input ) { final AlgCluster cluster = input.getCluster(); final AlgTraitSet traits = input.getTraitSet(); - return new LogicalDocIdentifier( version, document, cluster, traits, input ); + return new LogicalDocIdentifier( document, cluster, traits, input ); } @@ -57,7 +57,7 @@ public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { @Override public AlgNode copy( AlgTraitSet traitSet, List inputs ) { - return new LogicalDocIdentifier( version, entity, getCluster(), traitSet, sole( inputs ) ); + return new LogicalDocIdentifier( entity, getCluster(), traitSet, sole( inputs ) ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgIdentifier.java index 67fd2be07d..9abebbd62f 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgIdentifier.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgIdentifier.java @@ -20,7 +20,6 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.common.Identifier; import org.polypheny.db.algebra.core.lpg.LpgAlg; -import org.polypheny.db.algebra.logical.document.LogicalDocIdentifier; import org.polypheny.db.algebra.metadata.AlgMetadataQuery; import org.polypheny.db.catalog.entity.Entity; import org.polypheny.db.plan.AlgCluster; @@ -29,14 +28,16 @@ import org.polypheny.db.plan.AlgTraitSet; public class LogicalLpgIdentifier extends Identifier implements LpgAlg { - protected LogicalLpgIdentifier( long version, Entity entity, AlgCluster cluster, AlgTraitSet traits, final AlgNode input ) { - super(cluster, traits, version, entity, input ); + + protected LogicalLpgIdentifier( Entity entity, AlgCluster cluster, AlgTraitSet traits, final AlgNode input ) { + super( cluster, traits, entity, input ); } - public static LogicalLpgIdentifier create(long version, Entity graph, final AlgNode input) { - final AlgCluster cluster = input.getCluster(); + + public static LogicalLpgIdentifier create( Entity graph, final AlgNode input ) { + final AlgCluster cluster = input.getCluster(); final AlgTraitSet traits = input.getTraitSet(); - return new LogicalLpgIdentifier( version, graph, cluster, traits, input ); + return new LogicalLpgIdentifier( graph, cluster, traits, input ); } @@ -46,15 +47,17 @@ public NodeType getNodeType() { return NodeType.VALUES; } + @Override public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { double dRows = mq.getTupleCount( getInput() ); return planner.getCostFactory().makeCost( dRows, 0, 0 ); } + @Override - public AlgNode copy(AlgTraitSet traitSet, List inputs) { - return new LogicalLpgIdentifier(version, entity, getCluster(), traitSet, sole(inputs) ); + public AlgNode copy( AlgTraitSet traitSet, List inputs ) { + return new LogicalLpgIdentifier( entity, getCluster(), traitSet, sole( inputs ) ); } } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelIdentifier.java index 0b0074b0cb..9a377d07f6 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelIdentifier.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/relational/LogicalRelIdentifier.java @@ -32,16 +32,16 @@ @Getter public class LogicalRelIdentifier extends Identifier implements RelAlg { - protected LogicalRelIdentifier( long version, Entity entity, AlgCluster cluster, AlgTraitSet traits, AlgNode input, AlgDataType rowType ) { - super( cluster, traits, version, entity, input ); + protected LogicalRelIdentifier( Entity entity, AlgCluster cluster, AlgTraitSet traits, AlgNode input, AlgDataType rowType ) { + super( cluster, traits, entity, input ); this.rowType = rowType; } - public static LogicalRelIdentifier create(long version, Entity table, final AlgNode input, AlgDataType rowType ) { + public static LogicalRelIdentifier create( Entity table, final AlgNode input, AlgDataType rowType ) { final AlgCluster cluster = input.getCluster(); final AlgTraitSet traits = input.getTraitSet(); - return new LogicalRelIdentifier( version, table, cluster, traits, input, rowType ); + return new LogicalRelIdentifier( table, cluster, traits, input, rowType ); } @@ -54,7 +54,7 @@ public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { @Override public AlgNode copy( AlgTraitSet traitSet, List inputs ) { - return new LogicalRelIdentifier(version, entity, getCluster(), traitSet, sole( inputs ), getRowType() ); + return new LogicalRelIdentifier( entity, getCluster(), traitSet, sole( inputs ), getRowType() ); } } diff --git a/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java b/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java index b19b3da688..6f57781013 100644 --- a/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java +++ b/core/src/main/java/org/polypheny/db/transaction/locking/AlgTreeRewriter.java @@ -373,7 +373,6 @@ public AlgNode visit( LogicalRelModify modify ) { case INSERT: AlgNode input = modify1.getInput(); LogicalRelIdentifier identifier = LogicalRelIdentifier.create( - transaction.getSequenceNumber(), modify1.getEntity(), input, input.getTupleType() @@ -417,7 +416,6 @@ public AlgNode visit( LogicalLpgModify modify ) { case INSERT: AlgNode input = modify1.getInput(); LogicalLpgIdentifier identifier = LogicalLpgIdentifier.create( - transaction.getSequenceNumber(), modify1.getEntity(), input ); @@ -548,7 +546,6 @@ public AlgNode visit( LogicalDocumentModify modify ) { case INSERT: AlgNode input = modify1.getInput(); LogicalDocIdentifier identifier = LogicalDocIdentifier.create( - transaction.getSequenceNumber(), modify1.getEntity(), input );