Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.
Closed
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
25 changes: 19 additions & 6 deletions sql/plan/drop_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,39 @@ func (d *DropIndex) Schema() sql.Schema { return nil }
// Children implements the Node interface.
func (d *DropIndex) Children() []sql.Node { return []sql.Node{d.Table} }

func getTableName(node sql.Node) (string, error) {
if IsUnary(node) {
return getTableName(node.Children()[0])
}

n, ok := node.(sql.Nameable)
if !ok {
return "", ErrTableNotNameable.New()
}

return n.Name(), nil
}

// RowIter implements the Node interface.
func (d *DropIndex) RowIter(ctx *sql.Context) (sql.RowIter, error) {
db, err := d.Catalog.Database(d.CurrentDatabase)
if err != nil {
return nil, err
}

n, ok := d.Table.(sql.Nameable)
if !ok {
return nil, ErrTableNotNameable.New()
tableName, err := getTableName(d.Table)
if err != nil {
return nil, err
}

table, ok := db.Tables()[n.Name()]
table, ok := db.Tables()[tableName]
if !ok {
return nil, sql.ErrTableNotFound.New(n.Name())
return nil, sql.ErrTableNotFound.New(tableName)
}

index := d.Catalog.Index(db.Name(), d.Name)
if index == nil {
return nil, ErrIndexNotFound.New(d.Name, n.Name(), db.Name())
return nil, ErrIndexNotFound.New(d.Name, table.Name(), db.Name())
}
d.Catalog.ReleaseIndex(index)

Expand Down
2 changes: 1 addition & 1 deletion sql/plan/drop_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestDeleteIndex(t *testing.T) {
require.NotNil(idx)
catalog.ReleaseIndex(idx)

di := NewDropIndex("idx", NewResolvedTable(table))
di := NewDropIndex("idx", NewExchange(2, NewResolvedTable(table)))
di.Catalog = catalog
di.CurrentDatabase = "foo"

Expand Down