apache / apache/shardingsphere

Drop index fails when create index does not specify an index name

Open
#23,929 1 comment 0 reactions 1 assignee Claimed by @FlyingZC View on GitHub
feature: sharding type: bug
Dominant language
Java
Stars
20.8k
Forks
6.9k
Avg merge
11h 38m
Merged PRs (30d)
326

Description

## Bug Report
### Which version of ShardingSphere did you use?
master.

### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
proxy.

### Expected behavior
Drop index successfully when create index does not specify an index name

### Actual behavior
Drop index failed.

### Reason analyze (If you can)
Maybe the index rewrite does not handle the case without index name.

### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
```sql
-- 1.create index without index name
alter table t_order add index(order_id);

-- 2.show create table t_order;

| t_order | CREATE TABLE `t_order` (
`order_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`status` varchar(45) DEFAULT NULL,
KEY `order_id` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

-- 3.drop index with index name `order_id`
alter table t_order drop index order_id;
ERROR 1091 (42000): Can't DROP 'order_id_t_order_0'; check that column/key exists
```

proxy config
```yaml
databaseName: sharding_db

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: x
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: x
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1

rules:
- !SHARDING
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_inline
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
t_order_item:
actualDataNodes: ds_${0..1}.t_order_item_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_item_inline
keyGenerateStrategy:
column: order_item_id
keyGeneratorName: snowflake
bindingTables:
- t_order,t_order_item
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: database_inline
defaultTableStrategy:
none:

shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: ds_${user_id % 2}
database_id_inline:
type: INLINE
props:
algorithm-expression: ds_${id % 2}
t_order_inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
t_order_item_inline:
type: INLINE
props:
algorithm-expression: t_order_item_${order_id % 2}

keyGenerators:
snowflake:
type: SNOWFLAKE

```

### Example codes for reproduce this issue (such as a github link).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.