在一个表中有两个xml列是不是一件坏事? +在更新/插入/读取数据方面,这些xml列的速度有多慢?
在分析器中,这种插入通常需要0毫秒,但有时它会达到160毫秒:
declare @p8 xml
set @p8=convert(xml,N'<interactions><interaction correct="false" score="0"
id="0" gapid="0" x="61" y="225"><feedback/><element id="0" position="0"
elementtype="1"><asset/></element></interaction><interaction correct="false"
score="0" id="1" gapid="1" x="64" y="250"><feedback/><element id="0" position="0"
elementtype="1"><asset/></element></interaction><interaction correct="false"
score="0" id="2" gapid="2" x="131" y="250"><feedback/><element id="0" position="0"
elementtype="1"><asset/></element></interaction></interactions>')
declare @p14 xml
set @p14=convert(xml,N'<contentinteractions/>')
exec sp_executesql N'INSERT INTO
[dbo].[PackageSessionNodes]([dbo].[PackageSessionNodes].[PackageSessionId],
[dbo].[PackageSessionNodes].[TreeNodeId],[dbo].[PackageSessionNodes].[Duration],
[dbo].[PackageSessionNodes].[Score],[dbo].[PackageSessionNodes].[ScoreMax],
[dbo].[PackageSessionNodes].[Interactions],[dbo].[PackageSessionNodes].[BrainTeaser],
[dbo].[PackageSessionNodes].[DateCreated],
[dbo].[PackageSessionNodes].[CompletionStatus],
[dbo].[PackageSessionNodes].[ReducedScore],
[dbo].[PackageSessionNodes].[ReducedScoreMax],
[dbo].[PackageSessionNodes].[ContentInteractions])
VALUES (@ins_dboPackageSessionNodesPackageSessionId,
@ins_dboPackageSessionNodesTreeNodeId,
@ins_dboPackageSessionNodesDuration,
@ins_dboPackageSessionNodesScore,
@ins_dboPackageSessionNodesScoreMax,
@ins_dboPackageSessionNodesInteractions,
@ins_dboPackageSessionNodesBrainTeaser,
@ins_dboPackageSessionNodesDateCreated,
@ins_dboPackageSessionNodesCompletionStatus,
@ins_dboPackageSessionNodesReducedScore,
@ins_dboPackageSessionNodesReducedScoreMax,
@ins_dboPackageSessionNodesContentInteractions)
;
SELECT SCOPE_IDENTITY() as new_id
这是表格:
CREATE TABLE [dbo].[PackageSessionNodes](
[PackageSessionNodeId] [int] IDENTITY(1,1) NOT NULL,
[PackageSessionId] [int] NOT NULL,
[TreeNodeId] [int] NOT NULL,
[Duration] [int] NULL,
[Score] [float] NOT NULL,
[ScoreMax] [float] NOT NULL,
[Interactions] [xml] NOT NULL,
[BrainTeaser] [bit] NOT NULL,
[DateCreated] [datetime] NULL,
[CompletionStatus] [int] NOT NULL,
[ReducedScore] [float] NOT NULL,
[ReducedScoreMax] [float] NOT NULL,
[ContentInteractions] [xml] NOT NULL,
CONSTRAINT [PK_PackageSessionNodes] PRIMARY KEY CLUSTERED
(
[PackageSessionNodeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PackageSessionNodes] WITH CHECK ADD CONSTRAINT
[FK_PackageSessionNodes_PackageSessions] FOREIGN KEY([PackageSessionId])
REFERENCES [dbo].[PackageSessions] ([PackageSessionId])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[PackageSessionNodes] CHECK CONSTRAINT
[FK_PackageSessionNodes_PackageSessions]
GO
ALTER TABLE [dbo].[PackageSessionNodes] WITH CHECK ADD CONSTRAINT
[FK_PackageSessionNodes_TreeNodes] FOREIGN KEY([TreeNodeId])
REFERENCES [dbo].[TreeNodes] ([TreeNodeId])
GO
ALTER TABLE [dbo].[PackageSessionNodes] CHECK CONSTRAINT
[FK_PackageSessionNodes_TreeNodes]
GO
ALTER TABLE [dbo].[PackageSessionNodes] ADD CONSTRAINT
[DF_PackageSessionNodes_Score] DEFAULT ((-1)) FOR [Score]
GO
ALTER TABLE [dbo].[PackageSessionNodes] ADD CONSTRAINT
[DF_PackageSessionNodes_ScoreMax] DEFAULT ((-1)) FOR [ScoreMax]
GO
ALTER TABLE [dbo].[PackageSessionNodes] ADD CONSTRAINT
[DF_PackageSessionNodes_DateCreated] DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[PackageSessionNodes] ADD CONSTRAINT
[DF_PackageSessionNodes_ReducedScore] DEFAULT ((-1)) FOR [ReducedScore]
GO
ALTER TABLE [dbo].[PackageSessionNodes] ADD CONSTRAINT
[DF_PackageSessionNodes_ReducedScoreMax] DEFAULT ((-1)) FOR [ReducedScoreMax]
GO
答案 0 :(得分:1)
至少会有一些速度影响,因为当您将文本放入xml列时,系统会对其进行验证以确保其格式正确,并且可以折叠冗余标记和空格。但是这些操作非常快 - 进行这些转换不应该有太大的额外开销。
服务器上的锁定,索引问题或资源问题更有可能导致偶尔的插入速度变慢。
答案 1 :(得分:1)
在你的评论中,你说“没有xml列的同一个表”
如果您在Profiler中看到CPU偶尔出现峰值,则可能是页面拆分。将一大块XML数据插入分配给表的数据页可能会填满页面,因此需要进行拆分。没有XML的类似表显然具有更少的开销和更少的空间。
还有extra overhead存储LOB类型数据,而不是普通的旧varchar类型