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

ERROR 1105 (HY000): Error: index already exists #901

Closed
coconutLatte opened this issue Mar 23, 2022 · 1 comment · Fixed by #910
Closed

ERROR 1105 (HY000): Error: index already exists #901

coconutLatte opened this issue Mar 23, 2022 · 1 comment · Fixed by #910
Assignees

Comments

@coconutLatte
Copy link

coconutLatte commented Mar 23, 2022

func NewMysqlServer(db sql.Database) (*MysqlConfig, *server.Server, error) {
	port, err := util.GetFreePort()
	if err != nil {
		return nil, nil, fmt.Errorf("get free port failed, %w", err)
	}
	engine := sqle.NewDefault(
		sql.NewDatabaseProvider(
			createTestDatabase(),
			information_schema.NewInformationSchemaDatabase(),
		))
	config := server.Config{
		Protocol: "tcp",
		Address:  "127.0.0.1:" + strconv.Itoa(port),
		Auth:     auth.NewNativeSingle("user", "pass", auth.AllPermissions),
	}

	s, err := server.NewDefaultServer(config, engine)
	if err != nil {
		return nil, nil, fmt.Errorf("new mysql server failed, %w", err)
	}

	return &MysqlConfig{
		User:     "user",
		Password: "pass",
		Address:  config.Address,
	}, s, nil
}

func createTestDatabase() *memory.Database {
	const (
		dbName    = "test"
		tableName = "mytable"
	)

	db := memory.NewDatabase(dbName)
	table := memory.NewTable(tableName, sql.Schema{
		{Name: "name", Type: sql.Text, Nullable: false, Source: tableName},
		{Name: "email", Type: sql.Text, Nullable: false, Source: tableName},
		{Name: "phone_numbers", Type: sql.JSON, Nullable: false, Source: tableName},
		{Name: "created_at", Type: sql.Timestamp, Nullable: false, Source: tableName},
	})

	db.AddTable(tableName, table)
	ctx := sql.NewEmptyContext()

	rows := []sql.Row{
		sql.NewRow("John Doe", "john@doe.com", []string{"555-555-555"}, time.Now()),
		sql.NewRow("John Doe", "johnalt@doe.com", []string{}, time.Now()),
		sql.NewRow("Jane Doe", "jane@doe.com", []string{}, time.Now()),
		sql.NewRow("Evil Bob", "evilbob@gmail.com", []string{"555-666-555", "666-666-666"}, time.Now()),
	}

	for _, row := range rows {
		table.Insert(ctx, row)
	}

	return db
}

Hi
after init and start mysql server like above, I try to create a table has two unique fields while it goes an error;

mysql> CREATE TABLE `node_roles` (`node_id` bigint NOT NULL UNIQUE,`role` bigint NOT NULL UNIQUE);
ERROR 1105 (HY000): Error: index already exists

run this ok in other mysql.

I don't know if the mysql version too low or some config not correct...
Please help me. Thanks!

@zachmu
Copy link
Member

zachmu commented Mar 23, 2022

This is a bug. @VinaiRachakonda, please follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants