Skip to content

Commit d0ea131

Browse files
committed
Add joins hints docs
1 parent abfcdd6 commit d0ea131

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/content/docs/select.mdx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,15 @@ await db.select()
830830
.where(eq(users.name, 'David'));
831831
```
832832

833+
You can also use this option on any join you want
834+
835+
```ts
836+
await db.select()
837+
.from(users)
838+
.leftJoin(posts, eq(posts.userId, users.id), { useIndex: usersTableNameIndex })
839+
.where(eq(users.name, 'David'));
840+
```
841+
833842
### Ignore Index
834843

835844
The `IGNORE INDEX` hint tells the optimizer to avoid using specific indexes for the query. MySQL will consider all other indexes (if any) or perform a full table scan if necessary.
@@ -849,6 +858,16 @@ await db.select()
849858
.where(eq(users.name, 'David'));
850859
```
851860

861+
You can also use this option on any join you want
862+
863+
```ts
864+
await db.select()
865+
.from(users)
866+
.leftJoin(posts, eq(posts.userId, users.id), { useIndex: usersTableNameIndex })
867+
.where(eq(users.name, 'David'));
868+
```
869+
870+
852871
### Force Index
853872

854873
The `FORCE INDEX` hint forces the optimizer to use the specified index(es) for the query. If the specified index cannot be used, MySQL will not fall back to other indexes; it might resort to a full table scan instead.
@@ -866,4 +885,13 @@ const usersTableNameIndex = index('users_name_index').on(users.name);
866885
await db.select()
867886
.from(users, { forceIndex: usersTableNameIndex })
868887
.where(eq(users.name, 'David'));
869-
```
888+
```
889+
890+
You can also use this option on any join you want
891+
892+
```ts
893+
await db.select()
894+
.from(users)
895+
.leftJoin(posts, eq(posts.userId, users.id), { useIndex: usersTableNameIndex })
896+
.where(eq(users.name, 'David'));
897+
```

0 commit comments

Comments
 (0)