Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ There are a few ways to deploy a static-index from the Client API:

##### Auto-indexes:

* An auto-index is created by the server when making a filtering query that doesn't specify which index to use.
* When a dynamic query filters on fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that the word filter may be mistakenly associated with filter clause. Maybe we could rather use phrases like this? "When querying dynamically by fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed."

Learn more in [Creating auto indexes](../../../../../indexes/creating-and-deploying.mdx#auto-indexes).

</Admonition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import CodeBlock from '@theme/CodeBlock';

**PutIndexesOperation** is used to insert indexes into a database.

<Admonition type="note" title="Auto-indexes">

When a dynamic query filters on fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed.
Learn more in [Creating auto indexes](../../../../../indexes/creating-and-deploying.mdx#auto-indexes).

</Admonition>

### Syntax

<TabItem value="put_1_0" label="put_1_0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ There are a few ways to deploy a static-index from the Client API:

##### Auto-indexes:

* An auto-index is created by the server when making a filtering query that doesn't specify which index to use.
* When a dynamic query filters on fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed.
Learn more in [Creating auto indexes](../../../../../indexes/creating-and-deploying.mdx#auto-indexes).

</Admonition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ There are a few ways to deploy a static-index from the Client API:

#### Auto index:

* An auto-index is created by the server when making a filtering query that doesn't specify which index to use
* When a dynamic query filters on fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed.
* Learn more in [auto indexes](../../../../../indexes/creating-and-deploying.mdx#auto-indexes)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ There are a few ways to deploy a static-index from the Client API:

#### Auto index:

* An auto-index is created by the server when making a filtering query that doesn't specify which index to use
* When a dynamic query filters on fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed.
* Learn more in [auto indexes](../../../../../indexes/creating-and-deploying.mdx#auto-indexes)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CodeBlock from '@theme/CodeBlock';
* **Filter** documents based on compare-exchange values.

* Dynamic queries are queries that do not rely on a predefined static index.
When you run a dynamic query with a filtering condition, RavenDB automatically creates an auto-index to serve it.
When a dynamic query filters on fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed.
Learn more about dynamic queries in the [Query overview](../../querying/overview.mdx).

* In this article:
Expand All @@ -34,7 +34,7 @@ import CodeBlock from '@theme/CodeBlock';
* the number of guests (from the compare-exchange item's value), and
* the room number (from the document field).

* No auto-index is created in this case, since the query doesn’t apply any filters.
* No auto-index is created in this case, since the query doesn’t apply any filtering or sorting.

<Tabs groupId='languageSyntax'>
<TabItem value="Query" label="Query">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CodeBlock from '@theme/CodeBlock';
* **Filter** documents based on compare-exchange values.

* Dynamic queries are queries that do not rely on a predefined static index.
When you run a dynamic query with a filtering condition, RavenDB automatically creates an auto-index to serve it.
When a dynamic query filters on fields other than the document ID, or sorts the results, RavenDB uses a suitable existing auto-index or creates one if needed.
Learn more about dynamic queries in the [Query overview](../../querying/overview.mdx).

* In this article:
Expand All @@ -34,7 +34,7 @@ import CodeBlock from '@theme/CodeBlock';
* the number of guests (from the compare-exchange item's value), and
* the room number (from the document field).

* No auto-index is created in this case, since the query doesn’t apply any filters.
* No auto-index is created in this case, since the query doesn’t apply any filtering or sorting.

<Tabs groupId='languageSyntax'>
<TabItem value="Query" label="Query">
Expand Down
6 changes: 3 additions & 3 deletions docs/indexes/content/_creating-and-deploying-csharp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public static void Main(string[] args)

* Auto-indexes are created when all of the following conditions are met:
* A query is issued without specifying an index (a dynamic query).
* The query includes a filtering condition.
* The query filters on fields other than the document ID, or sorts the results (`order by`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group by clause also creates an auto index

* No suitable auto-index exists that can satisfy the query.
* Creation of auto-indexes has not been disabled.

Expand All @@ -446,15 +446,15 @@ public static void Main(string[] args)
* Note: dynamic queries can be issued either when [querying](../../studio/database/queries/query-view.mdx#query-view) or when [patching](../../documents/patching-documents/patch-multiple-documents/patch-view.mdx#patch-configuration).

* Over time, RavenDB automatically adjusts and merges auto-indexes to efficiently serve your queries.
For more details, see [Query a collection - with filtering (dynamic query)](../../querying/overview.mdx#dynamicQuery).
For more details, see [Query a collection - with filtering or sorting (dynamic query)](../../querying/overview.mdx#2-query-a-collection---with-filtering).

</ContentFrame>
<ContentFrame>

### Naming convention

* Auto-indexes are easily identified by their names, which start with the `Auto/` prefix.
* Their name also includes the name of the queried collection and a list of fields used in the query predicate to filter matching results.
* Their name also includes the name of the queried collection and a list of the fields the query uses to filter or sort the results.
* For example, issuing the following query:

<Tabs groupId='languageSyntax'>
Expand Down
10 changes: 8 additions & 2 deletions docs/indexes/content/_creating-and-deploying-java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,21 @@ Since RavenDB 4.0, **all** index updates are side-by-side by default. The new in

## **Auto indexes**

Auto-indexes are **created** when queries that do **not specify an index name** are executed and, after in-depth query analysis, **no matching AUTO index is found** on the server-side.
* Auto-indexes are created when all of the following conditions are met:
* A query is issued without specifying an index (a dynamic query).
* The query filters on fields other than the document ID, or sorts the results (`order by`).
* No suitable auto-index exists that can satisfy the query.
* Creation of auto-indexes has not been disabled.

For more details, see [Query a collection - with filtering or sorting (dynamic query)](../../querying/overview.mdx#2-query-a-collection---with-filtering).

<Admonition type="note" title="">
The query optimizer doesn't take into account the static indexes when it determines what index should be used to handle a query.
</Admonition>

### Naming convention

Auto-indexes can be recognized by the `Auto/` prefix in their name. Their name also contains the name of a collection that was queried, and list of fields that were required to find valid query results.
Auto-indexes can be recognized by the `Auto/` prefix in their name. Their name also includes the name of the queried collection and a list of the fields the query uses to filter or sort the results.

For instance, issuing a query like this

Expand Down
6 changes: 3 additions & 3 deletions docs/indexes/content/_creating-and-deploying-nodejs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -296,22 +296,22 @@ async function main() \{
* Indexes **created by the server** are called `dynamic` or `auto` indexes.
* Auto-indexes are created when all of the following conditions are met:
* A query is issued without specifying an index (a dynamic query).
* The query includes a filtering condition.
* The query filters on fields other than the document ID, or sorts the results (`order by`).
* No suitable auto-index exists that can satisfy the query.
* Creation of auto-indexes has not been disabled.
* For such queries, RavenDB's Query Optimizer searches for an existing auto-index that can satisfy the query.
If no suitable auto-index is found, RavenDB will either create a new auto-index or optimize an existing auto-index.
(Static-indexes are not taken into account when determining which auto-index should handle the query).
* Note: dynamic queries can be issued either when [querying](../../studio/database/queries/query-view.mdx#query-view) or when [patching](../../documents/patching-documents/patch-multiple-documents/patch-view.mdx#patch-configuration).
* Over time, RavenDB automatically adjusts and merges auto-indexes to efficiently serve your queries.
For more details, see [Query a collection - with filtering (dynamic query)](../../querying/overview.mdx#dynamicQuery).
For more details, see [Query a collection - with filtering or sorting (dynamic query)](../../querying/overview.mdx#2-query-a-collection---with-filtering).

</Admonition>
<Admonition type="note" title="">

##### Naming convention
* Auto-indexes are easily identified by their names, which start with the `Auto/` prefix.
* Their name also includes the name of the queried collection and a list of fields used in the query predicate to filter matching results.
* Their name also includes the name of the queried collection and a list of the fields the query uses to filter or sort the results.
* For example, issuing the following query:
<Tabs groupId='languageSyntax'>
<TabItem value="Query" label="Query">
Expand Down
48 changes: 29 additions & 19 deletions docs/querying/content/_overview-csharp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import Panel from '@site/src/components/Panel';
We differentiate between the following **3 query scenarios**:

1. [Query an existing index](../../querying/overview.mdx#1-query-an-existing-index)
2. [Query a collection - with filtering](../../querying/overview.mdx#2-query-a-collection---with-filtering)
2. [Query a collection - with filtering or sorting](../../querying/overview.mdx#2-query-a-collection---with-filtering)
3. [Query a collection - query full collection | query by ID](../../querying/overview.mdx#3-query-a-collection---query-full-collection--query-by-id)

For each scenario, a different index type is used, as described below.
Expand All @@ -75,22 +75,23 @@ For each scenario, a different index type is used, as described below.
* You can specify which **STATIC-index** the query will use.

* Static indexes are defined by the user, as opposed to auto-indexes that are created by the server
when querying a collection with some filtering applied. See [Static-index vs Auto-index](../../studio/database/indexes/indexes-overview.mdx#auto-indexes--vs--static-indexes).
when querying a collection with some filtering or sorting applied. See [Static-index vs Auto-index](../../studio/database/indexes/indexes-overview.mdx#auto-indexes--vs--static-indexes).

* Example RQL: &nbsp; `from index "Employees/ByFirstName" where FirstName == "Laura"`
See more examples in [querying an index](../../indexes/querying/query-index.mdx).

</Admonition>
<Admonition type="note" title="">

### 2. Query a collection - with filtering
### 2. Query a collection - with filtering or sorting {#2-query-a-collection---with-filtering}

* **Query type**: Dynamic Query
**Index used**: Auto-index

* When querying a collection without specifying an index and with some filtering condition
(other than just the document ID) the query-optimizer will analyze the query to see if an **AUTO-index**
that can answer the query already exists, i.e. an auto-index on the collection queried with index-fields that match those queried.
* When querying a collection without specifying an index, and the query either filters by some condition
(other than just the document ID) or sorts the results (`order by`), the query-optimizer will analyze the query
to see if an **AUTO-index** that can answer the query already exists,
i.e. an auto-index on the collection queried with index-fields that match the fields the query filters and sorts by.

* If such auto-index (Not a static one...) is found, it will be used to fetch the results.

Expand All @@ -109,8 +110,17 @@ For each scenario, a different index type is used, as described below.

* Over time, an optimal set of indexes is generated by the query optimizer to answer your queries.

* Example RQL: &nbsp; `from Employees where FirstName == "Laura"`
* Sorting alone is enough to require an auto-index.
A query that has an `order by` clause but no filtering condition is served by an auto-index, not by the raw collection.
This applies to any `order by` clause, including `order by id()` and `order by random()`.

* Example RQL - filtering: &nbsp; `from Employees where FirstName == "Laura"`
See more examples [below](../../querying/overview.mdx#session-query).

* Example RQL - sorting with no filtering: &nbsp; `from Employees order by FirstName`
If the _Employees_ collection has no auto-index yet, this query creates the `Auto/Employees/ByFirstName` auto-index.
See more examples in [Sort query results](../../querying/sorting-query-results/sort-query-results.mdx).

* Note: Counters and Time series are an exception to this flow.
Dynamic queries on counters and time series values don't create auto-indexes.
However, a static-index can be defined on [Time series](../../document-extensions/timeseries/indexing.mdx) and [Counters](../../document-extensions/counters/indexing.mdx).
Expand All @@ -125,7 +135,7 @@ For each scenario, a different index type is used, as described below.

* Full collection query:

* When querying a collection without specifying an index and with no filtering condition,
* When querying a collection without specifying an index, with no filtering condition and no sorting (`order by`),
then all documents from the specified collection are returned.

* RavenDB uses the raw collection documents in its **internal storage indexes** as the source for this query.
Expand All @@ -135,7 +145,7 @@ For each scenario, a different index type is used, as described below.

* Query by document ID:

* When querying a collection filtering only by document ID or IDs,
* When querying a collection filtering only by document ID or IDs, with no sorting (`order by`),
then similar to the full collection query, no auto-index is created.

* On the server side, this type of query opens a single read transaction and extracts the documents directly from the raw collection storage.
Expand Down Expand Up @@ -166,7 +176,7 @@ For each scenario, a different index type is used, as described below.
<TabItem value="Method-syntax" label="Method-syntax">
```csharp
// This is a Full Collection Query
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

List<Employee> allEmployees = session
.Query<Employee>() // Query for all documents from 'Employees' collection
Expand All @@ -178,7 +188,7 @@ List<Employee> allEmployees = session
<TabItem value="Method-syntax_async" label="Method-syntax_async">
```csharp
// This is a Full Collection Query
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

List<Employee> allEmployees = await asyncSession
.Query<Employee>() // Query for all documents from 'Employees' collection
Expand All @@ -190,7 +200,7 @@ List<Employee> allEmployees = await asyncSession
<TabItem value="Query-syntax" label="Query-syntax">
```csharp
// This is a Full Collection Query
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

// Query for all documents from 'Employees' collection
IRavenQueryable<Employee> query = from employee in session.Query<Employee>()
Expand All @@ -204,7 +214,7 @@ List<Employee> allEmployees = query.ToList();
<TabItem value="Query-syntax_async" label="Query-syntax_async">
```csharp
// This is a Full Collection Query
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

// Query for all documents from 'Employees' collection
IRavenQueryable<Employee> query = from employee in asyncSession.Query<Employee>()
Expand All @@ -218,7 +228,7 @@ List<Employee> allEmployees = await query.ToListAsync();
<TabItem value="RQL" label="RQL">
```sql
// This RQL is a Full Collection Query
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

from "Employees"
```
Expand Down Expand Up @@ -391,7 +401,7 @@ from "Employees" where FirstName == "Robert"
<TabItem value="Method-syntax" label="Method-syntax">
```csharp
// Query collection - page results
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

List<Product> products = session
.Query<Product>()
Expand All @@ -405,7 +415,7 @@ List<Product> products = session
<TabItem value="Method-syntax_async" label="Method-syntax_async">
```csharp
// Query collection - page results
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

List<Product> products = await asyncSession
.Query<Product>()
Expand All @@ -419,7 +429,7 @@ List<Product> products = await asyncSession
<TabItem value="Query-syntax" label="Query-syntax">
```csharp
// Query collection - page results
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

IRavenQueryable<Product> query = (from product in session.Query<Product>()
select product)
Expand All @@ -434,7 +444,7 @@ List<Product> products = query.ToList();
<TabItem value="Query-syntax_async" label="Query-syntax_async">
```csharp
// Query collection - page results
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

IRavenQueryable<Product> query = (from product in asyncSession.Query<Product>()
select product)
Expand All @@ -449,7 +459,7 @@ List<Product> products = await query.ToListAsync();
<TabItem value="RQL" label="RQL">
```sql
// Query collection - page results
// No auto-index is created since no filtering is applied
// No auto-index is created since no filtering or sorting is applied

from "Products" limit 5, 10 // skip 5, take 10
```
Expand Down
Loading
Loading