开发者

Database Schema Ambiguous Index Hint Issue

开发者 https://www.devze.com 2023-02-12 16:14 出处:网络
I\'ve just been importing a database to my Visual Studio Project using the Sql Server 2008 Database开发者_Python百科 Project. After resolving many issues highlighted by Visual Studio i am now left wit

I've just been importing a database to my Visual Studio Project using the Sql Server 2008 Database开发者_Python百科 Project. After resolving many issues highlighted by Visual Studio i am now left with just 2 both relating to hinting index's. The 2 warnings (with the causing statements) are

SELECT a.FI, a.GD 
FROM [RME].[dbo].[BP_RN] a with(index(idx_GD))
WHERE GD.STWithin(@Geometry) = 1

SQL04151: Procedure: [dbo].[sp_TNFRME] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [dbo].[BP_RN].[idx_GD] or [dbo].[idx_GD].

and

SELECT a.I
FROM [dbo].[N] a with(index(idx_G))
WHERE a.G.STIntersects(@Geometry) = 1

SQL04151: Procedure: [dbo].[sp_DIOQE] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [dbo].[idx_G] or [dbo].[N].[idx_G].

The reason i have listed both seperatly is because the first is querying a seperate database and i wasn't sure if this means it needs to be resolved in a different way.

Anyway my question is how do I resolve this error or fully qualify the hint so it is no longer ambiguous?

Thanks


there is a hack to get rid of the warning in Visual Studio 2010 Ultimate without getting rid of the hint, but you have to change the hint to use the index_id instead of the name of the index.

This worked with an example table that contained 3 spatial data columns with an index on each.

The spatial indexes were created in a database project in VS2010 Ultimate, from the schema view, after navigating to the indexes folder of the table, right-clicking the indexes folder and selecting add spatial index.

The index_id of each spatial index depends on the order in which spatial indexes are created for the same table-not on the order of creation of any other indexes.

The index creation order between spatial indexes depends on the order from top to bottom in which they appear in the schema view indexes folder, so basically alphanumeric dictionary order.

The index_id values for spatial indexes always start at 384000 and increase by 1 for each additionally created index, in the order in which it's created.

For the example with 3 spatial indexes, I created names like:

  1. TABLEPREFIX_SPATIAL384000_COLUMNNAME1
  2. TABLEPREFIX_SPATIAL384001_COLUMNNAME2
  3. TABLEPREFIX_SPATIAL384002_COLUMNNAME3

Dropping and re-creating indexes also produced the same index_id for each index.

So, then I replaced:

WITH(INDEX(TABLEPREFIX_SPATIAL384000_COLUMNNAME1))

with:

WITH(INDEX(384000))

Visual studio compiled without complaint, and the query ran as intended using the correct index hint.

CAVEAT: If you have to upgrade an existing database, you'll have to drop/create, not rename, and you'll have to do it in the right order. It's not a very nice workaround, but it will get rid of the warning

I tried a slightly better-looking approach using an sql command variable like:

WITH(INDEX([$(my_geographic_index_name)]))

Unfortunately this also produced the undesired warning.

Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消