Skip to content

Commit

Permalink
Prevent caching of version numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Hafner committed Jan 11, 2025
1 parent ba0fea4 commit 5b48ff9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -57,7 +63,7 @@ public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) {

@Override
public AlgNode copy( AlgTraitSet traitSet, List<AlgNode> 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 ) );
}


Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,6 +115,7 @@ public static <T> Pair<Bindable<T>, 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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand All @@ -57,7 +57,7 @@ public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) {

@Override
public AlgNode copy( AlgTraitSet traitSet, List<AlgNode> inputs ) {
return new LogicalDocIdentifier( version, entity, getCluster(), traitSet, sole( inputs ) );
return new LogicalDocIdentifier( entity, getCluster(), traitSet, sole( inputs ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
}


Expand All @@ -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<AlgNode> inputs) {
return new LogicalLpgIdentifier(version, entity, getCluster(), traitSet, sole(inputs) );
public AlgNode copy( AlgTraitSet traitSet, List<AlgNode> inputs ) {
return new LogicalLpgIdentifier( entity, getCluster(), traitSet, sole( inputs ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand All @@ -54,7 +54,7 @@ public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) {

@Override
public AlgNode copy( AlgTraitSet traitSet, List<AlgNode> inputs ) {
return new LogicalRelIdentifier(version, entity, getCluster(), traitSet, sole( inputs ), getRowType() );
return new LogicalRelIdentifier( entity, getCluster(), traitSet, sole( inputs ), getRowType() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -417,7 +416,6 @@ public AlgNode visit( LogicalLpgModify modify ) {
case INSERT:
AlgNode input = modify1.getInput();
LogicalLpgIdentifier identifier = LogicalLpgIdentifier.create(
transaction.getSequenceNumber(),
modify1.getEntity(),
input
);
Expand Down Expand Up @@ -548,7 +546,6 @@ public AlgNode visit( LogicalDocumentModify modify ) {
case INSERT:
AlgNode input = modify1.getInput();
LogicalDocIdentifier identifier = LogicalDocIdentifier.create(
transaction.getSequenceNumber(),
modify1.getEntity(),
input
);
Expand Down

0 comments on commit 5b48ff9

Please sign in to comment.