Open History to see the last commit
1---
2id: optimizeExpressionWithIndexes
3title: optimizeExpressionWithIndexes
4---
5
6# Function: optimizeExpressionWithIndexes()
7
8```ts
9function optimizeExpressionWithIndexes<T, TKey>(expression, collection): OptimizationResult<TKey>;
10```
11
12Defined in: [packages/db/src/utils/index-optimization.ts:196](https://github.com/TanStack/db/blob/main/packages/db/src/utils/index-optimization.ts#L196)
13
14Optimizes a query expression using available indexes to find matching keys
15
16## Type Parameters
17
18### T
19
20`T` *extends* `object`
21
22### TKey
23
24`TKey` *extends* `string` \| `number`
25
26## Parameters
27
28### expression
29
30[`BasicExpression`](../@tanstack/namespaces/IR/type-aliases/BasicExpression.md)
31
32### collection
33
34[`CollectionLike`](../interfaces/CollectionLike.md)\<`T`, `TKey`\>
35
36## Returns
37
38`OptimizationResult`\<`TKey`\>