Skip to content

Commit c9b4814

Browse files
20230818 noexpand version edition
1 parent 73531ff commit c9b4814

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

docs/relational-databases/query-processing-architecture-guide.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ The Query Optimizer treats an indexed view referenced in the `FROM` clause as a
381381

382382
You can prevent view indexes from being used for a query by using the `EXPAND VIEWS` query hint, or you can use the `NOEXPAND` table hint to force the use of an index for an indexed view specified in the `FROM` clause of a query. However, you should let the Query Optimizer dynamically determine the best access methods to use for each query. Limit your use of `EXPAND` and `NOEXPAND` to specific cases where testing has shown that they improve performance significantly.
383383

384-
The `EXPAND VIEWS` option specifies that the Query Optimizer not use any view indexes for the whole query.
384+
- The `EXPAND VIEWS` option specifies that the Query Optimizer not use any view indexes for the whole query.
385385

386-
When `NOEXPAND` is specified for a view, the Query Optimizer considers using any indexes defined on the view. `NOEXPAND` specified with the optional `INDEX()` clause forces the Query Optimizer to use the specified indexes. `NOEXPAND` can be specified only for an indexed view and can't be specified for a view not indexed.
386+
- When `NOEXPAND` is specified for a view, the Query Optimizer considers using any indexes defined on the view. `NOEXPAND` specified with the optional `INDEX()` clause forces the Query Optimizer to use the specified indexes. `NOEXPAND` can be specified only for an indexed view and can't be specified for a view not indexed. Prior to [!INCLUDE[ssSQL15_md](../../includes/sssql16-md.md)] Service Pack 1, automatic use of an indexed view by the query optimizer is supported only in specific editions of [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)]. Since, all editions support automatic use of an indexed view. [!INCLUDE [ssazure-sqldb](../includes/ssazure-sqldb.md)] and [!INCLUDE[ssazuremi_md](../includes/ssazuremi_md.md)] also support automatic use of indexed views without specifying the `NOEXPAND` hint.
387387

388388
When neither `NOEXPAND` nor `EXPAND VIEWS` is specified in a query that contains a view, the view is expanded to access underlying tables. If the query that makes up the view contains any table hints, these hints are propagated to the underlying tables. (This process is explained in more detail in View Resolution.) As long as the set of hints that exists on the underlying tables of the view are identical to each other, the query is eligible to be matched with an indexed view. Most of the time, these hints will match each other, because they are being inherited directly from the view. However, if the query references tables instead of views, and the hints applied directly on these tables aren't identical, then such a query isn't eligible for matching with an indexed view. If the `INDEX`, `PAGLOCK`, `ROWLOCK`, `TABLOCKX`, `UPDLOCK`, or `XLOCK` hints apply to the tables referenced in the query after view expansion, the query isn't eligible for indexed view matching.
389389

@@ -393,6 +393,8 @@ Generally, when the Query Optimizer matches an indexed view to a query, any hint
393393

394394
Hints aren't allowed in the definitions of indexed views. In compatibility mode 80 and higher, [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)] ignores hints inside indexed view definitions when maintaining them, or when executing queries that use indexed views. Although using hints in indexed view definitions won't produce a syntax error in 80 compatibility mode, they are ignored.
395395

396+
For more information, see [Table Hints (Transact-SQL)](../t-sql/queries/hints-transact-sql-table.md#using-noexpand).
397+
396398
### Resolve distributed partitioned views
397399

398400
The [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)] query processor optimizes the performance of distributed partitioned views. The most important aspect of distributed partitioned view performance is minimizing the amount of data transferred between member servers.

docs/relational-databases/views/create-indexed-views.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ JOIN Sales.SalesOrderHeader AS o
235235
ORDER BY OrderDate ASC;
236236
```
237237

238-
Finally, this example shows querying directly from the indexed view. On [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] Standard edition, you must use the `NOEXPAND` query hint to query the indexed view directly.
238+
Finally, this example shows querying directly from the indexed view. Prior to [!INCLUDE[ssSQL15_md](../../includes/sssql16-md.md)] Service Pack 1, automatic use of an indexed view by the query optimizer is supported only in specific editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. On [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] Standard edition, you must use the `NOEXPAND` query hint to query the indexed view directly. Since [!INCLUDE[ssSQL15_md](../../includes/sssql16-md.md)] Service Pack 1, all editions support automatic use of an indexed view. [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)] and [!INCLUDE[ssazuremi_md](../../includes/ssazuremi_md.md)] also support automatic use of indexed views without specifying the `NOEXPAND` hint. For more information, see [Table Hints (Transact-SQL)](../../t-sql/queries/hints-transact-sql-table.md#using-noexpand).
239239

240240
```sql
241241
--This query uses the indexed view directly, on Enterprise edition.

docs/t-sql/queries/hints-transact-sql-table.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ The query optimizer won't consider an index hint if the SET options don't have t
426426

427427
## <a id="using-noexpand"></a> Use NOEXPAND
428428

429-
`NOEXPAND` applies only to *indexed views*. An indexed view is a view with a unique clustered index created on it. If a query contains references to columns that are present both in an indexed view and base tables, and the query optimizer determines that using the indexed view provides the best method for executing the query, the query optimizer uses the index on the view. This functionality is called *indexed view matching*. Prior to [!INCLUDE[ssSQL15_md](../../includes/sssql16-md.md)] Service Pack 1, automatic use of an indexed view by the query optimizer is supported only in specific editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].
429+
`NOEXPAND` applies only to *indexed views*. An indexed view is a view with a unique clustered index created on it. If a query contains references to columns that are present both in an indexed view and base tables, and the query optimizer determines that using the indexed view provides the best method for executing the query, the query optimizer uses the index on the view. This functionality is called *indexed view matching*. Prior to [!INCLUDE[ssSQL15_md](../../includes/sssql16-md.md)] Service Pack 1, automatic use of an indexed view by the query optimizer is supported only in specific editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. Since, all editions support automatic use of an indexed view. [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)] and [!INCLUDE[ssazuremi_md](../../includes/ssazuremi_md.md)] also support automatic use of indexed views without specifying the `NOEXPAND` hint.
430+
431+
For more information, see [Query processing architecture guide](../../relational-databases/query-processing-architecture-guide.md#use-hints-with-indexed-views).
430432

431433
For a list of features that are supported by the editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], see:
432434

@@ -437,9 +439,6 @@ For a list of features that are supported by the editions of [!INCLUDE[ssNoVersi
437439

438440
However, for the query optimizer to consider indexed views for matching, or use an indexed view that is referenced with the `NOEXPAND` hint, the following SET options must be set to ON.
439441

440-
> [!NOTE]
441-
> [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)] supports automatic use of indexed views without specifying the `NOEXPAND` hint.
442-
443442
- ANSI_NULLS
444443
- ANSI_PADDING
445444
- ANSI_WARNINGS
@@ -452,7 +451,8 @@ However, for the query optimizer to consider indexed views for matching, or use
452451
Also, the NUMERIC_ROUNDABORT option must be set to OFF.
453452

454453
To force the query optimizer to use an index for an indexed view, specify the `NOEXPAND` option. This hint can be used only if the view is also named in the query. [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] doesn't provide a hint to force a particular indexed view to be used in a query that doesn't name the view directly in the FROM clause. However, the query optimizer considers using indexed views, even if they aren't referenced directly in the query. The [!INCLUDE[ssDEnoversion](../../includes/ssdenoversion-md.md)] will only automatically create statistics on an indexed view when a `NOEXPAND` table hint is used. Omitting this hint can lead to execution plan warnings about missing statistics that can't be resolved by creating statistics manually.
455-
During query optimization, the [!INCLUDE[ssDE-md](../../includes/ssde-md.md)] will use view statistics that were created automatically or manually when the query references the view directly and the `NOEXPAND` hint is used.
454+
455+
During query optimization, the [!INCLUDE[ssDE-md](../../includes/ssde-md.md)] will use view statistics that were created automatically or manually when the query references the view directly and the `NOEXPAND` hint is used.
456456

457457
## Use a table hint as a query hint
458458

0 commit comments

Comments
 (0)