Repository: duckdb/duckdb (language: python)

Issue:
`USE` does not affect for the table referenced after the keyword ON for the `CREATE UNIQUE INDEX ... ON ...`
### What happens?

The `USE` command does not affect for the table referenced after the keyword ON for the `CREATE UNIQUE INDEX ... ON ...` statement.

```sql
create schema mydb;
use mydb;
create table mytable (i bigint primary key, s varchar(20) NOT NULL);
CREATE UNIQUE INDEX mytable_s ON mytable(s NULLS FIRST);
```
```
Catalog Error: Table with name mytable does not exist!
Did you mean "memory.mydb.mytable"?
```

This issue occurs in both `duckdb` command line and go-duckdb.

### To Reproduce

use `duckdb` command line

```sql
create schema mydb;
use mydb;
create table mytable (i bigint primary key, s varchar(20) NOT NULL);
CREATE UNIQUE INDEX mytable_s ON mytable(s NULLS FIRST);
```
```
Catalog Error: Table with name mytable does not exist!
Did you mean "memory.mydb.mytable"?
```

### OS:

macOS m1 arm

### DuckDB Version:

v1.0.0 1f98600c2c

### DuckDB Client:

duckdb cli

### Full Name:

Yusong Gao

### Affiliation:

ApeCloud

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

### Did you include all relevant data sets for reproducing the issue?

Yes

### Did you include all code required to reproduce the issue?

- [X] Yes, I have

### Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

- [X] Yes, I have
`USE` does not affect for the table referenced after the keyword ON for the `CREATE UNIQUE INDEX ... ON ...`
### What happens?

The `USE` command does not affect for the table referenced after the keyword ON for the `CREATE UNIQUE INDEX ... ON ...` statement.

```sql
create schema mydb;
use mydb;
create table mytable (i bigint primary key, s varchar(20) NOT NULL);
CREATE UNIQUE INDEX mytable_s ON mytable(s NULLS FIRST);
```
```
Catalog Error: Table with name mytable does not exist!
Did you mean "memory.mydb.mytable"?
```

This issue occurs in both `duckdb` command line and go-duckdb.

### To Reproduce

use `duckdb` command line

```sql
create schema mydb;
use mydb;
create table mytable (i bigint primary key, s varchar(20) NOT NULL);
CREATE UNIQUE INDEX mytable_s ON mytable(s NULLS FIRST);
```
```
Catalog Error: Table with name mytable does not exist!
Did you mean "memory.mydb.mytable"?
```

### OS:

macOS m1 arm

### DuckDB Version:

v1.0.0 1f98600c2c

### DuckDB Client:

duckdb cli

### Full Name:

Yusong Gao

### Affiliation:

ApeCloud

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

### Did you include all relevant data sets for reproducing the issue?

Yes

### Did you include all code required to reproduce the issue?

- [X] Yes, I have

### Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

- [X] Yes, I have


Discussion / hints:
I’ve fixed the issue and will submit a PR after `make allunit` completes.
I’ve fixed the issue and will submit a PR after `make allunit` completes.

Fix patch:
diff --git a/src/parser/parsed_data/create_index_info.cpp b/src/parser/parsed_data/create_index_info.cpp
index 8f74c05c7086..3d41ea4fea2a 100644
--- a/src/parser/parsed_data/create_index_info.cpp
+++ b/src/parser/parsed_data/create_index_info.cpp
@@ -4,7 +4,7 @@
 
 namespace duckdb {
 
-CreateIndexInfo::CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
+CreateIndexInfo::CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY, INVALID_SCHEMA) {
 }
 
 CreateIndexInfo::CreateIndexInfo(const duckdb::CreateIndexInfo &info)


Test patch:
diff --git a/test/sql/create/create_index_on_issue_13643.test b/test/sql/create/create_index_on_issue_13643.test
new file mode 100644
index 000000000000..7ae069d66b54
--- /dev/null
+++ b/test/sql/create/create_index_on_issue_13643.test
@@ -0,0 +1,21 @@
+# name: test/sql/create/create_index_on_issue_13643.test
+# description: Issue #13643 - USE not affecting tables referenced after the ON keyword in CREATE INDEX
+# group: [create]
+
+statement ok
+CREATE SCHEMA db0;
+
+statement ok
+USE db0;
+
+statement ok
+CREATE TABLE t0 (a BIGINT PRIMARY KEY, b INT, c INT);
+
+statement ok
+CREATE INDEX t0_idx ON t0 (b);
+
+statement ok
+CREATE UNIQUE INDEX t0_uidx ON t0 (c);
+
+statement ok
+CREATE UNIQUE INDEX t0_uidx2 ON db0.t0 (c);