diff --git a/src/traft/node.rs b/src/traft/node.rs index 7a6b99d4c0b057007c1ce904f5e01fcea6f61fca..1f8883057fb757491e92ce5f413c1f3a75801ad0 100644 --- a/src/traft/node.rs +++ b/src/traft/node.rs @@ -1641,7 +1641,7 @@ impl NodeImpl { let bucket_id_def = IndexDef { table_id: id, id: 1, - name: "bucket_id".into(), + name: format!("{}_bucket_id", name), ty: IndexType::Tree, opts: vec![IndexOption::Unique(false)], parts: vec![Part::field(bucket_id_index) diff --git a/test/int/test_ddl.py b/test/int/test_ddl.py index abfecea40468763dfe2cadf87e03f5112ddca3f4..e2ede79bfd0d17a52fdaa04353f0eea99d3b631d 100644 --- a/test/int/test_ddl.py +++ b/test/int/test_ddl.py @@ -460,7 +460,7 @@ def test_ddl_create_sharded_space(cluster: Cluster): pico_bucket_id_def = [ space_id, 1, - "bucket_id", + "stuff_bucket_id", "tree", [dict(unique=False)], [[1, "unsigned", None, False, None]], @@ -474,7 +474,7 @@ def test_ddl_create_sharded_space(cluster: Cluster): tt_bucket_id_def = [ space_id, 1, - "bucket_id", + "stuff_bucket_id", "tree", dict(unique=False), [[1, "unsigned", None, False, None]], @@ -589,9 +589,15 @@ def test_ddl_create_table_abort(cluster: Cluster): ) assert i1.call("box.space._space:get", space_id) is not None - assert get_index_names(i1, space_id) == [f"{space_name}_pkey", "bucket_id"] + assert get_index_names(i1, space_id) == [ + f"{space_name}_pkey", + f"{space_name}_bucket_id", + ] assert i2.call("box.space._space:get", space_id) is not None - assert get_index_names(i2, space_id) == [f"{space_name}_pkey", "bucket_id"] + assert get_index_names(i2, space_id) == [ + f"{space_name}_pkey", + f"{space_name}_bucket_id", + ] # Wake the instance so that governor finds out there's a conflict # and aborts the ddl op. @@ -768,7 +774,7 @@ def test_ddl_create_table_from_snapshot_at_boot(cluster: Cluster): tt_bucket_id_def = [ space_id, 1, - "bucket_id", + "stuff_bucket_id", "tree", dict(unique=False), [[1, "unsigned", None, False, None]], diff --git a/test/int/test_sql.py b/test/int/test_sql.py index c9479ccdf6ed8b75674f30c59f7de1d9599b4f14..cef81d36993feeff2c8b15fd842b84964ece1a7d 100644 --- a/test/int/test_sql.py +++ b/test/int/test_sql.py @@ -3932,3 +3932,47 @@ def test_cte(cluster: Cluster): """ ) assert data["rows"] == [[1]] + + +def test_unique_index_name_for_sharded_table(cluster: Cluster): + cluster.deploy(instance_count=1) + i1 = cluster.instances[0] + table_names = ["T", "T2"] + + # Initialize two sharded table + for table_name in table_names: + ddl = i1.sql( + f""" + create table {table_name} (a int not null, b int, primary key (a)) + distributed by (b) + option (timeout = 3) + """ + ) + assert ddl["row_count"] == 1 + + for table_name, other_table_name in zip(table_names, reversed(table_names)): + with pytest.raises( + ReturnError, + match=f"""index {table_name}_bucket_id already exists with a different signature""", + ): + # try to create existing index + i1.sql( + f""" create index "{table_name}_bucket_id" + on "{table_name}" (a) option (timeout = 3) """ + ) + + with pytest.raises( + ReturnError, + match=f"""index {other_table_name}_bucket_id already exists""", + ): + # try to create non existing index with existing name + i1.sql( + f""" create index "{other_table_name}_bucket_id" + on "{table_name}" (a) option (timeout = 3) """ + ) + + # ensure that index on field bucket_id of sharded table exists + data = i1.sql( + f""" select * from "_pico_index" where "name" = '{table_name}_bucket_id' """ + ) + assert data["rows"] != []