Creating and Managing Indexes

Indexes provide quick access to data without searching through an entire database. With SQL Server 2005, you can create indexes on tables, views, and columns. By creating indexes on tables, you can search through the data in a table quickly. By creating indexes on views, you can generate a result set of the view that is stored and indexed in the database. By creating indexes on computed columns, you can evaluate expressions and index the results (if certain criteria are met).

Indexes are separate from tables, and you can configure them automatically using the Database Tuning Advisor. This section examines the techniques you will use to work with indexes.

Understanding Indexes

Indexes, like tables, use pages. The structure of index pages is similar to the structure used for table data pages. Index pages are 8 KB (8,192 bytes) in size and have a 96-byte header. But unlike data pages, they do not have row offsets. Each index has a corresponding row in the sys.indexes catalog view with an index ID value (index_id) of 1 for clustered indexes or 2–250 for nonclustered indexes. An index ID value of 255 indicates large object data such as image, ntext, text, varchar(max), nvarchar(max), varbinary(max), or xml data. (Large object data types cannot be index key columns; varchar(max), nvarchar(max), varbinary(max), and xml data types can be included columns, however.)

SQL Server maintains indexes using a BTree structure, which is a basic tree structure consisting of a root node, intermediate level nodes, and leaf nodes. Because indexes use a tree structure, you can search them quickly and efficiently. Without the tree structure, SQL Server would need to read each table data page in the database in turn, searching for the correct record.

To put this in perspective, consider a simple table in which each data page contains a single row. In this case, if SQL Server searches for data in row 800 and there is no index, SQL Server may have to search 799 other rows before finding the right row. With a tree structure, SQL Server navigates the nodes down the index searching for the row that matches the corresponding index key. In the best-case scenario, in which the index keys have been arranged in a full tree, the number of nodes that need to be searched is proportional to the height of the tree. For example, 27,000 rows may be represented by 30 levels of nodes, and if so, SQL Server would have to navigate a maximum of 15 nodes to find the matching row.

Note

Note

You may have noticed that I simplified this example to demonstrate the power of indexing. Nevertheless, indexing can improve performance by orders of magnitude, and accessing a database without indexing can seem extremely slow. You must be careful, however; indexing the wrong information also can make the database perform slowly, which is why it is so important to select the most referenced/used column in the table to index.

In SQL Server 2005, indexing performance has been enhanced in many ways:

  • Index operations can be performed online, and online indexing depends on the amount of memory allocated for indexing. Online indexing makes it possible for users to access table data and use other indexes on a table while an index is being created, modified, or dropped.

  • Columns that are not part of the index key can be included in nonclustered indexes to improve query performance by making all the required data available without the need to access the table data rows. These included columns can exceed the index size limitations of 16 key columns and the maximum key size of 900 bytes.

  • Both row-level and page-level index locks are allowed when accessing the index. If you allow row locks, page locks, or both, the Database Engine determines when the locks are used.

  • The maximum degree of parallelism can be set using MAXDOP. This controls the number of parallel operations when creating, alerting, or dropping an index.

  • Indexes can be partitioned on value ranges using existing partition schemes. When you partition a nonunique, clustered index, the Database Engine adds the partitioning column to the list of clustered index keys if it is not already specified. When you partition a nonunique, nonclustered index, the Database Engine adds the partitioning column as a nonkey (included) column of the index if it is not already specified.

SQL Server 2005 supports two types of indexing:

  • Clustered indexes

  • Nonclustered indexes

SQL Server 2005 also supports a special type of index for XML data. An XML index can be either a nonclustered index (the default) or a clustered index. A clustered index is created for XML data from the clustering key of the user table and an XML node identifier. Each table can have up to 249 XML indexes. You will learn more about XML indexes in the subsection titled "Using XML Indexes" later in this chapter.

You can create clustered and nonclustered indexes on almost any column. Exceptions include common language runtime (CLR) user-defined types and very large object data types—you cannot create indexes on these data types. If you want to create indexes on computed columns, you must ensure the computed column expression always returns the same result for a specific set of inputs. Although you can create an index on any other type of column, you should always select the index column carefully. Selecting the correct column to index improves response time dramatically. Selecting the wrong column to index actually can degrade response time. For more information about which column to index, use the Database Tuning Advisor.

Using Clustered Indexes

A clustered index stores the actual table data pages at the leaf level, and the table data is physically ordered around the key. A table can have only one clustered index, and when this index is created, the following events also occur:

  • Table data is rearranged.

  • New index pages are created.

  • All nonclustered indexes within the database are rebuilt .

As a result, there are many disk I/O operations and extensive use of system and memory resources. So if you plan to create a clustered index, make sure you have enough free space, equal to at least 1.5 times the amount of data in the table. The extra free space ensures that you have enough space to complete the operation efficiently.

Normally, you create a clustered index on a primary key. You can, however, create a clustered index on any named column, such as cust_lname or cust_id. When you create a clustered index, the values you are indexing should be unique. If the values are not unique, SQL Server creates secondary sort keys on rows that have duplicates of their primary sort keys.

Using Nonclustered Indexes

In a nonclustered index, pages at the leaf level contain a bookmark that tells SQL Server where to find the data row corresponding to the key in the index. If the table has a clustered index, the bookmark indicates the clustered index key. If the table does not have a clustered index, the bookmark is an actual row locator.

When you create a nonclustered index, SQL Server creates the required index pages but does not rearrange table data, and other indexes for the table are not deleted. Each table can have up to 249 nonclustered indexes.

Using XML Indexes

As mentioned earlier, an XML index is a special type of index that can be either clustered or nonclustered. Before you can create an XML index, there must be a clustered index based on the primary key of the user table, and this key is limited to 15 columns. Two types of XML indexes can be created: primary and secondary. Each xml column in a table can have one primary XML index and one or more secondary XML indexes. However, there must be a primary XML index before a secondary XML index can be created on a column, and you cannot create a primary XML index on a computed xml column.

Also note that an XML index can only be created on a single xml column. You cannot create an XML index on a non-xml column, nor can you create a relational index on an xml column. You cannot create an XML index on an xml column in a view, on a table-valued variable with xml columns, or on an xml type variable. Finally, the SET options must be the same as those required for indexed views and computed-column indexes. This means ARITHABORT must be set to ON when an XML index is created and when inserting, deleting, or updating values in the xml column.

Determining Which Columns Should Be Indexed

Now that you know how indexes work, you can focus on which columns you should index. Ideally, you will select columns for indexing based on the types of queries executed on the database. SQL Server Profiler can help you determine the types of queries being run. You use SQL Profiler to create a trace that contains a good snapshot of activities performed by users on the database.

You can examine this trace manually to see what types of queries are executed, or you can use the trace file as a saved workload file in the Database Engine Tuning Advisor. Regardless of which method you use, keep in mind that the maximum length of all key columns that comprise an index is 900 bytes. This means that the total size in bytes of all columns must be 900 or less. (Columns that are not part of the index key can be included, and these included columns can exceed the index size limitations of 16 key columns and maximum key size of 900 bytes.) Table 9-4 offers some guidelines about the kinds of tables and columns that can be successfully indexed and those that do not result in useful indexes.

Table 9-4. Guidelines for Selecting Tables and Columns to Index

Index

Do Not Index

Tables with lots of rows

Tables with few rows

Columns that are often used in queries

Columns that are rarely used in queries

Columns that have a wide range of values and have a high likelihood of rows being selected in a typical query

Columns that have a wide range of values and have a low likelihood of rows being selected in a typical query

Columns used in aggregate functions

Columns that have a large byte size

Columns used in GROUP BY queries

Tables with many modifications but few actual queries

Columns used in ORDER BY queries

 

Columns used in table joins

 

Table 9-5 provides suggestions for the types of columns that should use clustered or nonclustered indexes.

Table 9-5. Guidelines for Using Clustered and Nonclustered Indexes

Use Clustered Index for

Use Nonclustered Index for

Primary keys that are searched for extensively, such as account numbers

Primary keys that are sequential identifiers, such as identity columns

Queries that return large result sets

Queries that return small result sets

Columns used in many queries

Columns used in aggregate functions

Columns with strong selectivity

Foreign keys

Columns used in ORDER BY or GROUP BY queries

 

Columns used in table joins

 

Indexing Computed Columns and Views

With SQL Server 2005, you can index computed columns and views as well as tables. Indexes on computed columns and views involve storing results in the database for future reference. With computed columns, the column values are calculated and then used to build the keys stored in the index. With views, the result set is stored by creating a clustered index on the view. In both cases, the stored results are valid only if all connections referring to the results can generate an identical result set, which puts specific restrictions on how you can create indexes on computed columns and views.

You must establish connections referring to the results using specific SET options, and these options must have the same settings. The options you must set are as follows:

  • ANSI_NULLS must be set ON.

  • ANSI_PADDING must be set ON.

  • ANSI_WARNINGS must be set ON.

  • ARITHABORT must be set ON.

  • CONCAT_NULL_YIELDS_NULL must be set ON.

  • QUOTED_IDENTIFIER must be set ON.

  • NUMERIC_ROUNDABORT must be set OFF.

Furthermore, all operations referencing the view must use the exact same algorithm to build the view result set, including:

  • The CREATE INDEX statement that builds the initial result set or is used to calculate the initial keys.

  • Any subsequent INSERT, UPDATE, or DELETE statements that affect the data used to build the view result set or are used to calculate keys.

  • All queries for which the query optimizer must determine if the indexed view is useful.

Viewing Index Properties

Both tables and views can have indexes. In SQL Server Management Studio, you can view indexes associated with a table or view by completing the following steps:

  1. In SQL Server Management Studio, select a database, and then expand the Tables or Views node as appropriate.

  2. Select a table or view and expand its node to list the objects it contains.

  3. Expand the Indexes node to list the indexes associated with the selected table or view (if any).

  4. Right-click an index, and then select Properties from the shortcut menu to open the Index Properties dialog box shown in Figure 9-7. This dialog box has several pages that you can select to view and manage index properties, including:

    • General. Shows general properties, including the index name and type. You can change the index type and add or remove key columns.

    • Options. Allows you to set options for rebuilding the index, recomputing statistics, using row or page locks, setting the fill factor, and determining maximum degree of parallelism.

    • Included Columns. Allows you to view and manage the included columns (with nonclustered indexes.)

    • Storage. Lists the current storage configuration. Allows you to configure filegroups and partition schemes.

    • Fragmentation. Lists the index fragmentation data, which you can use to determine if you need to reorganize or rebuild the index.

    • Extended Properties. Lists extended properties. Allows you to add or remove extended properties.

    Index Properties dialog box

    Figure 9-7. Index Properties dialog box

Using the sp_statistics stored procedure, you can examine the indexes for a specific table or view. To do this, you simply specify the name of the table or view whose indexes you want to examine, as shown in the following example:

USE OrderSystemDB
EXEC sp_statistics Sales.Customers

Creating Indexes

Only the owner of a table or view can create indexes on that table or view. You can create indexes with a wizard in the SQL Server Management Studio or with the Transact-SQL CREATE INDEX command. To create indexes with the wizard, complete the following steps:

  1. In SQL Server Management Studio, connect to the server instance containing the database in which you want to work.

  2. In Object Explorer, expand the Databases node, and then select a database and expand it to show the database’s resource nodes.

  3. Expand the Tables or Views node as appropriate. Right-click the table or view for which you are creating the index, and then select Modify from the shortcut menu.

  4. On the Table Designer menu, select Indexes/Keys to display the Indexes/Keys dialog box shown in Figure 9-8.

    The Indexes/Keys dialog box

    Figure 9-8. The Indexes/Keys dialog box

  5. Any current primary/unique keys and indexes are listed in the left pane of the dialog box, and you can manage the properties of any of the keys by selecting it and making the necessary changes. To add an index, click Add.

  6. Click in the Columns text box, and then click the button to the right of the Columns box. This displays the Index Columns dialog box shown in Figure 9-9.

    The Index Columns dialog box

    Figure 9-9. The Index Columns dialog box

  7. Under Column Name, select the column(s) you want to include in the index. You can only select columns that have valid data types for indexing.

  8. Each column can have a separate sort order for the index. By default, the sort order is set to Ascending. You can set the sort order to Descending.

  9. When you have finished selecting columns to index, click OK to close the Index Columns dialog box.

  10. If you want to ensure that data entered into this index is unique, set the option Is Unique to Yes. This ensures the uniqueness of values stored in the index. You cannot set this option for XML indexes.

  11. Type should be set to Index by default. Use the text boxes provided to type the index name and description. You can use up to 128 characters for the index name. Ideally, the index name should be short and easy to associate with its purpose, such as [Index for Cust ID].

  12. Set the option Create As Clustered to Yes to create a clustered index on the columns selected. Otherwise, a nonclustered index is created. Remember that you can have only one clustered index per table, so if the table already has a clustered index, this option is shaded and you cannot select it.

  13. To specify the storage location for the index, expand the Data Space Specification node, and then use the Filegroup Or Partition Schema drop-down list to specify the filegroup.

  14. To set the fill parameters, expand the Fill Specification node. Set the Fill Factor to 0 (the default value) to let SQL Server use an optimized fill, as described in the section titled "Setting the Index Fill" in Chapter 6. Refer to this same section for information about setting the Fill Factor to a different value to set a specific index fill.

  15. If you want to ignore duplicate keys, set the option Ignore Duplicates Keys to Yes. When this option is on, any attempt to insert rows that violate the unique index fails with a warning, and the rows are not inserted. Whether this option is set on or off, however, SQL Server does not allow you to create a unique index on columns that already have duplicate values. Columns that are used in a unique index should be set so they do not allow nulls. Furthermore, you cannot use the Ignore Duplicates Keys option with XML indexes or indexes created on views.

  16. Optionally, turn on automatic statistics updating by setting the option Re-Compute Statistics to Yes. If you set Re-Compute Statistics to No, out-of-date statistics are not automatically recomputed.

  17. When you are finished configuring the index, click Close. Select File | Save or press Ctrl+S to save the table, which in turn saves the index you created.

Use the Transact-SQL CREATE INDEX command to create indexes with the syntax shown in Example 9-10.

Example 9-10. CREATE INDEX Syntax

Syntax Relational Index

CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name 
    ON <object> ( column [ ASC | DESC ] [ ,...n ] ) 
    [ INCLUDE ( column_name [ ,...n ] ) ]  
    [ WITH ( <relational_index_option> [ ,...n ] ) ] 
    [ ON { partition_scheme_name ( column_name )      
         | filegroup_name  
         | default   
         } ]
[ ; ]
<object> ::=
{ [ database_name. [ schema_name ] . | schema_name. ]  
        table_or_view_name }

<relational_index_option> ::=
{ PAD_INDEX  = { ON | OFF } 
  | FILLFACTOR = fillfactor
  | SORT_IN_TEMPDB = { ON | OFF } 
  | IGNORE_DUP_KEY = { ON | OFF } 
  | STATISTICS_NORECOMPUTE = { ON | OFF } 
  | DROP_EXISTING = { ON | OFF } 
  | ONLINE = { ON | OFF }  
  | ALLOW_ROW_LOCKS = { ON | OFF } 
  | ALLOW_PAGE_LOCKS = { ON | OFF } 
  | MAXDOP = max_degree_of_parallelism }

Syntax XML Index

CREATE [ PRIMARY ] XML INDEX index_name   
    ON <object> ( xml_column_name ) 
    [ USING XML INDEX xml_index_name       
        [ FOR { VALUE | PATH | PROPERTY } ] 
    [ WITH ( <xml_index_option> [ ,...n ] ) ]
[ ; ]

<object> ::=
{ [ database_name. [ schema_name ] . | schema_name. ]     
        table_name }

<xml_index_option> ::=
{ PAD_INDEX  = { ON | OFF } 
  | FILLFACTOR = fillfactor
  | SORT_IN_TEMPDB = { ON | OFF } 
  | STATISTICS_NORECOMPUTE = { ON | OFF }
  | DROP_EXISTING = { ON | OFF } 
  | ALLOW_ROW_LOCKS = { ON | OFF } 
  | ALLOW_PAGE_LOCKS = { ON | OFF }
  | MAXDOP = max_degree_of_parallelism }

Managing Indexes

After you create an index, you may need to change its properties, rename it, or delete it. You handle these tasks in SQL Server Management Studio by completing the following steps:

  1. In SQL Server Management Studio, select a database, and then expand the Tables or Views node as appropriate.

  2. Select a table or view and expand its node to list the objects it contains.

  3. Expand the Indexes node to list the indexes associated with the selected table or view.

  4. Right-click an index. You can now:

    • Select Properties to view the index properties, including details on space usage and fragmentation.

    • Select Rename to rename an index.

    • Select Rebuild to rebuild the index. In the Rebuild Indexes dialog box, use the Total Fragmentation and Index Status values to help you determine whether or not to proceed. Click OK to proceed with the rebuild. Click Cancel to exit without performing the rebuild. SQL Server 2005 performs online index rebuilds and reorganizations.

    • Select Reorganize to reorganize the index. In the Reorganize Indexes dialog box, check the total fragmentation of the index to determine if the index needs to be reorganized. By default, both regular data and large object data are reorganized. Clear the Compact Large Object Column Data option if you only want to compact regular index data. Click OK to proceed with the reorganization. Click Cancel to exit without performing the reorganization.

    • Select Delete to drop the index (as long as it is not a primary key or unique constraint).

You can also manage indexes with the Transact-SQL commands ALTER INDEX and DROP INDEX. Unfortunately, you must use these commands cautiously because there are several limitations to these commands. For example, you cannot drop an index that was created by defining a primary key or unique constraints. You must instead drop the constraint with ALTER TABLE. Example 9-11 shows the syntax for ALTER INDEX and Example 9-12 shows the syntax for DROP INDEX.

Example 9-11. ALTER INDEX Syntax

Syntax

ALTER INDEX { index_name | ALL }  
    ON <object>   
    { REBUILD [ [ WITH ( <rebuild_index_option> [ ,...n ] ) ]  
      | [ PARTITION = partition_number        
           [ WITH ( <single_partition_rebuild_index_option> [ ,...n ] 
) ] ] ]  
    | DISABLE 
    | REORGANIZE    
        [ PARTITION = partition_number ] 
        [ WITH ( LOB_COMPACTION = { ON | OFF } ) ] 
    | SET ( <set_index_option> [ ,...n ] ) }
[ ; ]

<object> ::=
{ [ database_name. [ schema_name ] . | schema_name. ]     
        table_or_view_name }

<rebuild_index_option > ::=
{ PAD_INDEX  = { ON | OFF } 
  | FILLFACTOR = fillfactor  
  | SORT_IN_TEMPDB = { ON | OFF }  
  | IGNORE_DUP_KEY = { ON | OFF }  
  | STATISTICS_NORECOMPUTE = { ON | OFF }  
  | ONLINE = { ON | OFF }  
  | ALLOW_ROW_LOCKS = { ON | OFF }  
  | ALLOW_PAGE_LOCKS = { ON | OFF }  
  | MAXDOP = max_degree_of_parallelism }

<single_partition_rebuild_index_option> ::=
{ SORT_IN_TEMPDB = { ON | OFF } 
  | MAXDOP = max_degree_of_parallelism }

<set_index_option>::=
{ ALLOW_ROW_LOCKS= { ON | OFF }
  | ALLOW_PAGE_LOCKS = { ON | OFF }
  | IGNORE_DUP_KEY = { ON | OFF }
  | STATISTICS_NORECOMPUTE = { ON | OFF } }

Example 9-12. DROP INDEX Syntax

Syntax

DROP INDEX
{ <drop_relational_or_xml_index> [ ,...n ]
| <drop_backward_compatible_index> [ ,...n ] }

<drop_relational_or_xml_index> ::= 
    index_name ON <object>
    [ WITH ( <drop_clustered_index_option> [ ,...n ] ) ]

<drop_backward_compatible_index> ::= 
    [ owner_name. ] table_or_view_name.index_name

<object> ::=
{ [ database_name. [ schema_name ] . | schema_name. ]     
        table_or_view_name }

<drop_clustered_index_option> ::=
{ MAXDOP = max_degree_of_parallelism  
    | ONLINE = { ON | OFF }  
  | MOVE TO { partition_scheme_name ( column_name )     
            | filegroup_name      
            | "default"      
            } }

Using the Database Engine Tuning Advisor

The Database Engine Tuning Advisor is one of the best tools a database administrator can use to facilitate the indexing and optimization process. But before you start this wizard, you should create a trace containing a representative snapshot of database activity. You will use this snapshot as the workload file in the Database Engine Tuning Advisor. For specific pointers on creating a trace file, see the subsection titled "Creating and Managing Performance Monitor Logs" in Chapter 13. To use the Database Engine Tuning Advisor, complete the following steps:

  1. In SQL Server Management Studio, select Database Engine Tuning Advisor on the Tools menu. Use the Connect To Server dialog box to connect to the server you want to use.

  2. The Database Engine Tuning Advisor opens to start a new session, as shown in Figure 9-10. On the Workload tab, type a name for the session, such as Personnel DB Check. Using the Database For Workload Analysis drop-down list provided, select a database to which Database Tuning Advisor will connect for analyzing the workload.

    The Database Engine Tuning Advisor

    Figure 9-10. The Database Engine Tuning Advisor

    • If you saved the trace data to a file, select File on the Workload panel, and then click the Browse For A Workload File button (the binoculars icon). Next, use the Select Workload File dialog box to select the trace file you previously created, and then click Open.

    • If you saved the trace data to a table, select Table on the Workload panel, and then click the Browse For A Workload Table button (the binoculars icon). Next, use the Select Workload Table dialog box to specify which SQL Server to connect to and the source table to use.

  3. Select the database you want to analyze. You can analyze multiple databases as well as individual tables within specific databases if you want. In most cases, you will want to examine a single database and possibly a subset of tables to reduce the analysis time. Because you are using a trace file, the analysis does not have to be performed on the server where the database(s) you are tuning is located.

  4. Select the tables to analyze. If you select a database for tuning, all tables are selected for tuning by default. Click in the appropriate cell under Selected Tables to display a list of tables in the selected database. Select the check box for the associated table you want added or click the Name check box to add all tables.

  5. Select the Tuning Options tab, as shown in Figure 9-11. You can limit the tuning time by setting a specific stop time. By default, the stop time is approximately one hour from the time you created the session.

    The Tuning Options tab of the Database Tuning Advisor

    Figure 9-11. The Tuning Options tab of the Database Tuning Advisor

  6. From the Physical Design Structures (PDS) To Use In Database options, select the type of structures that you want the tuning wizard to recommend. The options are as follows:

    • Indexes and Indexed Views. The Database Engine Tuning Advisor will recommend both clustered and nonclustered indexes as well as indexed views to improve performance.

    • Indexes. The Database Engine Tuning Advisor will recommend clustered and nonclustered indexes to improve performance.

    • Indexed Views. The Database Engine Tuning Advisor will recommend only indexed views to improve performance.

    • Nonclustered Indexes. The Database Engine Tuning Advisor will recommend only nonclustered indexes to improve performance.

    • Evaluate Utilization of Existing PDS Only. The Database Engine Tuning Advisor will not recommend options for improving performance and instead will only analyze the usage of existing structures.

    Note

    Note

    This option cannot be used with the Keep All Exiting PDS option under Physical Design Structure To Keep In Database.

  7. Use the Partitioning Strategy To Employ options to determine if the Database Engine Tuning Advisor should consider partitioning strategies. The options are as follows:

    • No Partitioning. The Database Engine Tuning Advisor will not consider any partitioning strategies.

    • Aligned Partitioning. Newly recommended structures will be partition-aligned to make partitions easy to maintain. (This option cannot be used with the Keep Indexes Only option under Physical Design Structure To Keep In Database.)

    • Full Partitioning. Newly recommended structures will be partitioned to provide the best performance for the workload.

  8. Use the Physical Design Structures To Keep In Database options to determine which (if any) existing structures will be considered for removal from the database. The options are as follows:

    • Do Not Keep Any Existing PDS. The Database Engine Tuning Advisor will consider all existing structures for possible removal from the database.

    • Keep All Existing PDS. The Database Engine Tuning Advisor will not consider any existing structures for possible removal from the database.

    • Keep Aligned Partitioning. The Database Engine Tuning Advisor will retain existing partitioned-aligned structures, and any recommended new structures will be aligned with the existing partitioning scheme. (Aligned Partitioning must also be selected as the Partitioning Strategy To Employ option).

    • Keep Indexes Only. The Database Engine Tuning Advisor will keep existing clustered and nonclustered indexes. All other structures will be considered for possible removal from the database.

    • Keep Clustered Indexes Only. The Database Engine Tuning Advisor will keep existing clustered indexes. All other structures will be considered for possible removal from the database.

    Note

    Note

    If you have selected a strong, representative snapshot of database activity in the trace, you will probably want to select an option other than Keep All Existing PDS and let the Database Engine Tuning Advisor make the appropriate suggestions for you to ensure that existing structures do not conflict with the recommendations the wizard may make.

  9. Click the Advanced Options button to set advanced options, as shown in Figure 9-12. The advanced options are as follows:

    • Define Max. Space For Recommendations (MB). Sets the maximum space that can be used by recommended structures. The default value depends on the database and structures selected.

    • Max. Columns Per Index. Sets the maximum number of columns that can be used in a single index. The default is 1,024, which allows all the columns in a table to be considered.

    • Online Index Recommendations. Sets the type of indexing recommendations. By default, the Database Engine Tuning Advisor uses recommendations that require the server to be taken offline. Alternately, you can elect to generate online recommendations when possible or to generate only online recommendations. Online recommendations can be performed when the server is online.

    Advanced Options for the Database Engine Tuning Advisor

    Figure 9-12. Advanced Options for the Database Engine Tuning Advisor

  10. Click OK to close the Advanced Options dialog box. When you are ready to proceed, click the Start Analysis button or press F5. The Database Engine Tuning Advisor will begin analyzing your workload file. Progress is shown on the Progress tab. You can click Stop Analysis to stop the analysis at any time.

  11. When it has finished the analysis, the wizard displays recommendations on the Recommendations tab, shown in Figure 9-13. The recommendations are listed in two separate panels, Partition Recommendations and Index Recommendations. You can view a tuning summary and tuning reports on the Reports tab of the Database Engine Tuning Advisor. Be sure to note the percentage of estimated improvement by making the recommended changes. In the example shown in the figure, the estimated improvement is 0%, which can be an indicator that the trace file may not accurately reflect the database workload

    The Recommendations tab

    Figure 9-13. The Recommendations tab

  12. You can now:

    • Select Save Recommendations on the Actions menu to save the recommended changes as an SQL script file. You can review or edit the script using a text editor and schedule a job to implement the changes later.

    • Select Apply Recommends on the Actions menu to apply the recommendations or schedule the recommendations to be applied later. In the Apply Recommendations, select Apply Now or Schedule For Later as appropriate, and then click OK. If you schedule for later, you can set the run date and time as well.

  13. If you choose to apply the changes, the status of each change is displayed in the Applying Recommendations dialog box. The status of each change should be listed as Success. If you see a failure status, read the related error message to determine why the change failed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset