Skip to content

Commit

Permalink
Allow indexes on MonetDB (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens authored Dec 28, 2024
1 parent 21b64d6 commit 031355d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/org/polypheny/db/adapter/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.polypheny.db.adapter;


import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializer;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,7 +55,7 @@ public DataStore( final long adapterId, final String uniqueName, final Map<Strin
public abstract List<FunctionalIndexInfo> getFunctionalIndexes( LogicalTable catalogTable );


public record IndexMethodModel( String name, String displayName ) {
public record IndexMethodModel( @JsonProperty String name, @JsonProperty String displayName ) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,62 @@ public void updateColumnType( Context context, long allocId, LogicalColumn newCo

@Override
public String addIndex( Context context, LogicalIndex index, AllocationTable allocation ) {
throw new GenericRuntimeException( "MonetDB adapter does not support adding indexes" );
PhysicalTable physical = adapterCatalog.fromAllocation( allocation.id );
String physicalIndexName = getPhysicalIndexName( physical.id, index.id );

StringBuilder builder = new StringBuilder();
builder.append( "CREATE " );
if ( index.unique ) {
builder.append( "UNIQUE INDEX " );
} else {
builder.append( "INDEX " );
}

builder.append( dialect.quoteIdentifier( physicalIndexName ) )
.append( " ON " )
.append( dialect.quoteIdentifier( physical.namespaceName ) )
.append( "." )
.append( dialect.quoteIdentifier( physical.name ) );

builder.append( "(" );
boolean first = true;
for ( long columnId : index.key.fieldIds ) {
if ( !first ) {
builder.append( ", " );
}
first = false;
builder.append( dialect.quoteIdentifier( getPhysicalColumnName( columnId ) ) );
}
builder.append( ")" );

executeUpdate( builder, context );

return physicalIndexName;
}


@Override
public void dropIndex( Context context, LogicalIndex index, long allocId ) {
throw new GenericRuntimeException( "MonetDB adapter does not support dropping indexes" );
PhysicalTable table = adapterCatalog.fromAllocation( allocId );

StringBuilder builder = new StringBuilder();
builder.append( "DROP INDEX " );
builder.append( dialect.quoteIdentifier( index.physicalName + "_" + table.id ) );
executeUpdate( builder, context );
}


@Override
public List<IndexMethodModel> getAvailableIndexMethods() {
// According to the MonetDB documentation, MonetDB takes create index statements only as an advice and often freely
// neglects them. Indexes are created and removed automatically. We therefore decided to not support manually creating
// indexes on MonetDB.
return ImmutableList.of();
// neglects them. Indexes are created and removed automatically.
return ImmutableList.of( new IndexMethodModel( "advisory", "ADVISORY ONLY" ) );
}


@Override
public IndexMethodModel getDefaultIndexMethod() {
throw new GenericRuntimeException( "MonetDB adapter does not support adding indexes" );
return getAvailableIndexMethods().get( 0 );
}


Expand Down

0 comments on commit 031355d

Please sign in to comment.