tags:

views:

150

answers:

1

Background

I'm writing an adapter for ESE to .NET and LINQ in a Google Code project called eselinq. One important function I can't seem to figure out is how to get a list of indexes defined for a table. I need to be able to list available indexes so the LINQ part can automatically determine when indexes can be used. This will allow much more efficient plans for user queries if appropriate indexes can be found.

There are two related functions for querying index information: JetGetTableIndexInfo and JetGetIndexInfo. These only differ in how the related table is specified (name or tableid). It sounds like these would support the function I want but all the info levels seem to require that I already have a certain index to query information for. The only exception is JET_IdxInfoCount, but that only counts how many indexes are present.

JET_IdxInfo with its JET_INDEXLIST sounds plausible but it only lists the columns on a specific index.

Alternatives

I am aware that I could get the index information another way, like annotations on .NET types corresponding to database tables, or by requiring a index mapping be provided ahead of time. I think there's enough introspection implemented to make everything else work out of the box without the user supplying extra information, except for this one function.

Another option may be to examine the system tables to find related index objects, but this is would mean depending on an undocumented interface.

To satisfy this question, I want a supported method of enumerating the indexes (just the name would be sufficient) on a table.

+1  A: 

You are correct about JetGetTableIndexInfo and JetGetIndexInfo and JET_IdxInfo. The twist is that the data is returned in a somewhat complex: a temporary table is returned containing a row for the index and then a row for each column in the table. To just get the index names you will need to skip the column rows (the column count is given by the value of the columnidcColumn column in the first row).

For a .NET example of how to decipher this, look at the ManagedEsent project. In the MetaDataHelpers.cs file there is a method called GetIndexInfoFromIndexlist that extracts all the data from the temporary table.

Laurion Burchall
Ok, looked up GetTableIndexes in MetaDataHelpers.cs from ManagedEsent. Looks like you can get info on all indexes by passing an empty string to JetGetIndexInfo's index name parameter? It'd be nice if that was documented. In that case, I should be able to adjust Index::CollectInformation in EseObjects to work on all indexes. I'll try it and report back. Thanks!
Chris Smith
It works! Accepted. New eselinq patch: http://code.google.com/p/eselinq/source/detail?r=218a86ab67acc5818e938aa59e179708978ce97c
Chris Smith