Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions pkg/ddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4916,6 +4916,10 @@ func (e *executor) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast
if err != nil {
return errors.Trace(err)
}
if len(indexName.L) == 0 {
// It means that there is already an index exists with same name
return nil
}

tblInfo := t.Meta()
finalColumns := make([]*model.ColumnInfo, len(tblInfo.Columns), len(tblInfo.Columns)+len(hiddenCols))
Expand Down
22 changes: 22 additions & 0 deletions tests/integrationtest/r/table/index.result
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,25 @@ drop table if exists t;
create table t (a int, b int, k varchar(255), primary key (a, b), key k (k));
insert into t values (1, 1, 'abc ');
drop table t;
drop table if exists t;
create table t (
pid char(64) NOT NULL,
another_id int NOT NULL,
field varchar(255),
PRIMARY KEY (`pid`) /*T![clustered_index] CLUSTERED */,
KEY `idx` (`another_id`)
);
CREATE INDEX if not exists idx ON t (`another_id`);
show warnings;
Level Code Message
Note 1061 Duplicate key name 'idx'
show create table t;
Table Create Table
t CREATE TABLE `t` (
`pid` char(64) NOT NULL,
`another_id` int NOT NULL,
`field` varchar(255) DEFAULT NULL,
PRIMARY KEY (`pid`) /*T![clustered_index] CLUSTERED */,
KEY `idx` (`another_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
drop table t;
14 changes: 14 additions & 0 deletions tests/integrationtest/t/table/index.test
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@ drop table if exists t;
create table t (a int, b int, k varchar(255), primary key (a, b), key k (k));
insert into t values (1, 1, 'abc ');
drop table t;

# Test Issue 61265
drop table if exists t;
create table t (
pid char(64) NOT NULL,
another_id int NOT NULL,
field varchar(255),
PRIMARY KEY (`pid`) /*T![clustered_index] CLUSTERED */,
KEY `idx` (`another_id`)
);
CREATE INDEX if not exists idx ON t (`another_id`);
show warnings;
show create table t;
drop table t;