Navision 4.0 SP1 and Index Management

Some times ago I've written a post on how to improve code performances of your Navision-based solution with the new 4.0 SP1 release. Today I want to signal two interesting properties about index management but that are not so visible (I'm observing that lots of Navision developers don't know their existence).

With Navision 4.0 SP1, if you open a table with Object Designer and check its keys, you can see two new properties: Clustered and SQLIndex.

These are new interesting properties useful for a better index management.

With the Clustered property, you can determine whether or not the index is clustered.

With the SQLIndex property, you can define the fields that are used in the corresponding index on SQL Server. If the key in question is not the primary key and you use the SQLIndex property to define the index on SQL Server, the index that is created contains exactly the fields that you specify and will not necessarily be a unique index. It will only be a unique index if it contains all of the primary key fields.

Here a brief considerations on how to determine the best choice for the Clustered property of your index (a brief resume from one of my favourite SQL guides):

A nonclustered index is analogous to an index in a textbook. The data is stored in one place, the index in another, with pointers to the storage location of the data. The items in the index are stored in the order of the index key values, but the information in the table is stored in a different order (which can be dictated by a clustered index). If no clustered index is created on the table, the rows are not guaranteed to be in any particular order. SQL Server searches for a data value by searching the nonclustered index to find the location of the data value in the table and then retrieves the data directly from that location. This makes nonclustered indexes the optimal choice for exact match queries because the index contains entries describing the exact location in the table of the data values being searched for in the queries.

A clustered index determines the physical order of data in a table (it's analogous for example to a telephone directory, where data are sorted by last name). Because the clustered index dictates the physical storage order of the data in the table, a table can contain only one clustered index. A clustered index is particularly efficient on columns that are often searched for ranges of values (after the row with the first value is found using the clustered index, rows with subsequent indexed values are guaranteed to be physically adjacent) or for finding a specific row when the indexed value is unique.

Must be noted that PRIMARY KEY constraints create clustered indexes automatically if no clustered index already exists on the table and it is important to define the clustered index key with as few columns as possible.

So, when using a clustered or a nonclustered index? Generally I can say this:

Use a nonclustered index for:

  • Queries that do not return large result sets;
  • Columns frequently involved in search conditions of a query (WHERE clause) that return exact matches;
  • Applications for which joins and grouping are frequently required. Create multiple nonclustered indexes on columns involved in join and grouping operations, and a clustered index on any foreign key columns;
  • Covering all columns from one table in a given query.

Use a clustered index for:

  • Queries that return large result sets;
  • Columns that are accessed sequentially;
  • Queries that return a range of values using operators such as BETWEEN, >, >=, <, and <=;
  • Columns that are frequently accessed by queries involving join or GROUP BY clauses (typically these are foreign key columns). An index on the column(s) specified in the ORDER BY or GROUP BY clause eliminates the need for SQL Server to sort the data because the rows are already sorted (this improves query performance);
  • where very fast single row lookup is required, typically by means of the primary key. Create a clustered index on the primary key.

These are general recommendation that can help you to have a more efficient and performant SQL Server system and with Navision 4 SP1 you have the power to improve your performance control.

Print | posted on Thursday, January 05, 2006 2:20 PM

Comments on this post

# re: Navision 4.0 SP1 and Index Management

Requesting Gravatar...
Hi Stefano,

Cool with a Navision blog

Nice summary of the new SQL functions. What I always wonder though, is when and why I should use the functions.
Take SQLIndex - why would I use that? Is there any advantage over not maintaining the index in SQL and the create the "target" index as a new key?

I would have loved support for the INCLUDE function added to Create Index in SQL2005 - I've done some testing and in some cases, like when using item tracking, modifying indexes to use INCLUDE will give up to 30% better performance.

Cheers,
Lars
Cheers,
Lars
Left by Lars on Jan 17, 2006 8:12 PM

# re: Navision 4.0 SP1 and Index Management

Requesting Gravatar...
I think that mantaining the index directly with SQL Server indexing function is the best choice (you can check their performance and the fragmentation). However this new function helps the Navision admin to work with index more in depth that before.
Left by Stefano Demiliani on Jan 21, 2006 10:43 AM

# Dynamics NAV index management with SQL Server 2005

Requesting Gravatar...
Left by STEFANO DEMILIANI WeBlog on Sep 11, 2006 1:37 PM

# re: Navision 4.0 SP1 and Index Management

Requesting Gravatar...
i highly discourage using tables without clustered indexes and the reason is to avoid having FID PN RN in non-clustered indexes leaf-nodes.

If a table has a clustered index then all other indexes of that table in their leaf-nodes will have values of clustered index fields instead of FID PN RN.

Left by Lucas on Jun 27, 2008 2:15 PM

# replica jewelry

Requesting Gravatar...

Requesting Gravatar...
i highly discourage using tables without clustered indexes and the reason is to avoid having FID PN RN in non-clustered indexes leaf-nodes.
Left by replica jewelry on Apr 29, 2010 4:12 AM

# re: Navision 4.0 SP1 and Index Management

Requesting Gravatar...
fdfdsafdsafsa
Left by Brand Lee on May 11, 2010 6:01 AM

# re: Navision 4.0 SP1 and Index Management

Requesting Gravatar...
ies about index management but that are not so visible (I'm observing that lots of Navision developers don't know their existence).

With Navision 4.0 SP1, if you open a table with Object Designer and check its keys, you can see two new properties: Clustered an
Left by wholesale laptop adapter on May 23, 2010 2:36 PM

# re: Navision 4.0 SP1 and Index Management

Requesting Gravatar...
I would have loved support for the INCLUDE function added to Create Index in SQL2005 - I've done some testing and in some cases, like when using item tracking, modifying indexes to use INCLUDE will give up to 30% better performance.
Left by clothing manufacturer on Mar 28, 2011 4:48 PM

Your comment:

 (will show your gravatar)
 
Please add 5 and 4 and type the answer here: