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

Add indexes to MonetDB #528

Merged
merged 3 commits into from
Dec 28, 2024
Merged
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
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
Loading