间歇性提示noexpand无效

时间:2015-11-26 09:36:53

标签: sql sql-server

我们在Linux上运行一些XMPP服务器,它们使用FreeTDS连接到MS SQL 2014数据库服务器以加载名单。加载名单是索引视图上的选择,而选择使用noexpand提示,看起来像这样:

"history" : [
        {
            "timestamp" : "2015-10-26 14:39:15", 
            "event" : "Creation", 
            "createdby" : "Ws", 
            "data" : [
                {
                    "crm_base_contact_id" : "1847", 
                    "crm_imported_files_id" : ""
                }
            ]
        }, 
        {
            "timestamp" : "2015-10-26 15:12:28", 
            "event" : "Task", 
            "createdby" : "Auto-Filter", 
            "data" : [
                {
                    "Campaign ID" : "219", 
                    "Campaign Name" : "ASA", 
                    "Task ID" : "2541639", 
                    "Filter Name" : "ASA", 
                    "Filter ID" : "826"
                }
            ]
        }, 
        {
            "event_id" : ObjectId("5656b3655b9e5c8812000007"), 
            "timestamp" : "2015-11-26 08:23:17", 
            "event" : "Session", 
            "createdby" : "ABC", 
            "data" : [
                {
                    "Campaign ID" : "219", 
                    "Task ID" : "2541639", 
                    "viopCalls" : [
                        {
                            "timestamp" : "2015-11-26 08:25:42", 
                            "CallID" : "46", 
                            "Duration" : NumberInt(5), 
                            "TelNumber" : "0685356189"
                        }, 
                        {
                            "timestamp" : "2015-11-26 08:26:13", 
                            "CallID" : "45", 
                            "Duration" : NumberInt(3), 
                            "TelNumber" : "0685356189"
                        }
                    ]
                }
            ]             
        }
    ], 


Expected output : Duration : 8

我们会在这样的XMPP服务器日志中遇到错误:

  

[FreeTDS] [SQL Server]在对象'dbo.vIdxRosterUsers'上提示'noexpand'   无效。

它可能是10000个查询中的一个。

有没有人知道为什么SQL服务器会间歇性地抱怨在索引视图上使用noexpand提示?

添加视图及其索引的源代码:

SELECT * 
FROM dbo.[vIdxRosterUsers] WITH (NOEXPAND)
WHERE jid = 'alpha.4663@localhost'

2 个答案:

答案 0 :(得分:1)

对于此视图dbo。[vIdxRosterUsers]对此 jid 创建唯一的(聚集或非聚集的)索引,以运行查询。需要注意的是,表上的索引列和视图上的索引列是完全分开的,具有索引表,但是没有索引的视图将导致noexpand无效

答案 1 :(得分:0)

一个小想法......删除视图,添加计算列和过滤索引

ALTER TABLE dbo.friend
    ADD jid AS 'fr.' + CAST(f.friendactorid AS VARCHAR(20)) + '@localhost' PERSISTED    
GO

CREATE UNIQUE NONCLUSTERED INDEX [IX_rosterusers_user_jid] 
  ON dbo.friend ([username], [jid]) WHERE f.[status] = 2 
  WITH (FILLFACTOR = 90) ON [PRIMARY] 
GO