AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-37243

Riley Major's questions

Martin Hope
Riley Major
Asked: 2023-03-30 22:39:21 +0800 CST

SQL Server 连接字符串 - MultiSubnetFailover True 或 Yes?

  • 5

数据库连接字符串中的 MultiSubnetFailover 选项控制客户端尝试连接到数据库服务器的方式,尤其是当多个 IP 可用时。

关于正确的连接字符串语法是否为以下内容存在冲突的文档:

MultiSubnetFailover=Yes

https://learn.microsoft.com/en-us/sql/connect/oledb/features/oledb-driver-for-sql-server-support-for-high-availability-disaster-recovery?view=sql-server-版本16

或者:

MultiSubnetFailover=True

https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/sqlclient-support-for-high-availability-disaster-recovery

是否同时支持“Yes”和“True”?还是因驾驶员而异?如果是后者,是否有哪些驱动程序支持哪些语法的列表?

2023年3月30日更新:

此 Microsoft 文档暗示“True”或“Yes”适用于另一个选项:

Persist Security Info 关键字的默认设置为 false。将其设置为true 或 yes允许在连接打开后从连接获取安全敏感信息,包括用户 ID 和密码。将持久安全信息设置为 false 以确保不受信任的源无法访问敏感的连接字符串信息。

https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax

(强调已添加)

sql-server
  • 2 个回答
  • 1372 Views
Martin Hope
Riley Major
Asked: 2021-06-17 07:10:51 +0800 CST

为什么主键上的集群键查找每次执行的估计行数很高?

  • 10

我们有一个带有 Key Lookup 的查询,它估计每次执行有数千行。据我了解,每次执行应该只有一行。我知道统计数据可能会产生误导,但优化器不明白主键是唯一的吗?

此查询中涉及的表具有以下形式的聚集主键:

/****** Object:  Index [PK_Table_Name]    Script Date: 6/16/2021 9:52:12 AM ******/
ALTER TABLE [dbo].[Table_Name] ADD  CONSTRAINT [PK_Table_Name] PRIMARY KEY CLUSTERED 
(
    [Table_Name_ID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO

据我了解,主键提供了对表中单行的唯一引用。

因此,对于它在非聚集索引中找到的每一行,它应该能够使用该索引对聚集索引的引用来检索它需要满足对它所作用的行的其余查询过滤所需的单行。(这是一个嵌套循环连接运算符。)

那么为什么它估计将近 4000 行将作为 Key Lookup 的一部分返回呢?(不是“所有执行”,大约 36,000,000 是 4000 行和它期望从非聚集索引查找中获得的 9000 行的乘积。)

查询计划显示每次执行键查找的大行

运行时统计数据显示该聚集索引查找的 2851 行和 2851 次执行,这是我所期望的。

运行时统计显示每次执行聚集索引查找的一行

如果它有帮助,这是在 Azure SQL 数据库中,具有@@version:

Microsoft SQL Azure (RTM) - 12.0.2000.8 
    Apr 29 2021 13:52:20 
    Copyright (C) 2019 Microsoft Corporation
sql-server query-performance
  • 1 个回答
  • 475 Views
Martin Hope
Riley Major
Asked: 2021-04-23 13:27:28 +0800 CST

SQL Server 2008 R2 是否总是因某些大文本操作而出现严重级别 20 错误?

  • 5

当我们在 SQL Server 2008 R2 实例上运行它时,每次都会导致严重性 20 错误。它在我们的 SQL Server 2016 实例上没有这个问题。

询问:

DECLARE @v varchar(MAX) = REPLICATE(CONVERT(varchar(max),'a'),524289);
SELECT @v = @v FROM(SELECT 1 AS a) AS b;

结果:

Location:    tmpilb.cpp:3256
Expression:  fNoReaderWriterConflict
SPID:        90
Process ID:  1576
Location:    tmpilb.cpp:3306
Expression:  fNoReaderWriterConflict
SPID:        90
Process ID:  1576
Msg 3624, Level 20, State 1, Line 4
A system assertion check has failed. Check the SQL Server error log for details. Typically, an assertion failure is caused by a software bug or data corruption. To check for database corruption, consider running DBCC CHECKDB. If you agreed to send dumps to Microsoft during setup, a mini dump will be sent to Microsoft. An update might be available from Microsoft in the latest Service Pack or in a QFE from Technical Support. 
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command.  The results, if any, should be discarded.

SELECT @@VERSION:

Microsoft SQL Server 2008 R2 (SP3) - 10.50.6000.34 (X64) 
    Aug 19 2014 12:21:34 
    Copyright (c) Microsoft Corporation
    Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)

SQLDump0002.txt(来自非生产服务器):

Computer type is Intel(R) Xeon(R) CPU           E5430  @ 2.66GHz.                                                
Bios Version is DELL   - 1                                                                                       
Phoenix ROM BIOS PLUS Version 1.10 2.5.0                                                                         
8 X64 level 8664, 2 Mhz processor (s).                                                                           
Windows NT 6.1 Build 7601 CSD Service Pack 1. 

Memory                               
MemoryLoad = 87%                     
Total Physical = 32762 MB            
Available Physical = 4058 MB         
Total Page File = 65524 MB           
Available Page File = 27332 MB       
Total Virtual = 8388607 MB           
Available Virtual = 8355194 MB       
**Dump thread - spid = 0, EC = 0x00000003EF7E5F00                                                       

 

这是此版本 SQL Server 2008 R2 中的错误吗?

更新:

  • 这确实会产生一组与故障转储相关的文件。它们的外行可读部分基本上重复了上面的错误结果。
  • 我们认识到 SQL Server 2008 R2 已经过时并且不再受支持。我们将进行升级。
  • 我们已经通过在 SELECT 语句之外设置大文本变量来解决这个问题。
  • 我们很好奇这是否发生在任何其他环境中,我们希望将其公开记录以防发生在其他人身上。
sql-server-2008-r2 errors
  • 2 个回答
  • 126 Views
Martin Hope
Riley Major
Asked: 2019-12-28 10:07:58 +0800 CST

如何修复 SSMS 18 中的错误编辑作业步骤属性?

  • 3

每当我尝试在 SQL Server Management Studio (SSMS) 版本 18 中编辑 SQL Server 代理作业步骤的属性时,应用程序都会引发错误并且我无法继续。我该如何解决这个错误?

UserVoice 帖子链接:

https://feedback.azure.com/forums/908035-sql-server/suggestions/37642465-ssms-18-0-job-properties-window-click-on-step-fa

SSMS 版本 18.4:

  • SQL Server 管理工作室 15.0.18206.0
  • Microsoft 分析服务客户端工具 15.0.1567.0
  • Microsoft 数据访问组件 (MDAC) 10.0.18362.1
  • 微软 MSXML 3.0 4.0 6.0
  • 微软 Internet Explorer 9.11.18362.0
  • 微软 .NET 框架 4.0.30319.42000
  • 操作系统 10.0.18362

完整的错误文本:

===================================

The system cannot find the file specified.

------------------------------
Program Location:

at Microsoft.SqlServer.Dts.Runtime.Application.get_LogProviderInfos()
at Microsoft.DataTransformationServices.DTSExecUI.Controls.LoggingCtrl..ctor(IDTSExecViewManager treePanel)
at Microsoft.SqlServer.Management.SqlManagerUI.DTSJobSubSystemDefinition.InitializeControls()
at Microsoft.SqlServer.Management.SqlManagerUI.DTSJobSubSystemDefinition..ctor(CDataContainer dataContainer, IMessageBoxProvider messageProvider)
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepSubSystems.CreateJobStepSubSystemSsis(AgentSubSystem agentSubSystem, CDataContainer dataContainer, JobStepData data, IMessageBoxProvider messageProvider)
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepSubSystems.CreateJobStepSubSystem(AgentSubSystem agentSubSystem, CDataContainer dataContainer, JobStepData data, IMessageBoxProvider messageProvider, IServiceProvider serviceProvider)
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepSubSystems..ctor(CDataContainer dataContainer, JobStepData data, IMessageBoxProvider messageProvider, IServiceProvider serviceProvider)
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepProperties.get_SubSystems()
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepProperties.FilterStepCombo(DatabaseEngineEdition engineEdition)
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepProperties.InitializeStepCombo()
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepProperties.InitializeData()
at Microsoft.SqlServer.Management.SqlManagerUI.JobStepProperties.OnInitialization()
at Microsoft.SqlServer.Management.SqlMgmt.ViewSwitcherControlsManager.SetView(Int32 index, TreeNode node)
at Microsoft.SqlServer.Management.SqlMgmt.ViewSwitcherControlsManager.SelectCurrentNode()
at Microsoft.SqlServer.Management.SqlMgmt.ViewSwitcherControlsManager.InitializeUI(ViewSwitcherTreeView treeView, ISqlControlCollection viewsHolder, Panel rightPane)
at Microsoft.SqlServer.Management.SqlMgmt.LaunchForm.InitializeForm(XmlDocument doc, IServiceProvider provider, ISqlControlCollection control)
at Microsoft.SqlServer.Management.SqlMgmt.LaunchForm..ctor(ISqlControlCollection control, IServiceProvider provider)
at Microsoft.SqlServer.Management.SqlManagerUI.JobSteps.OnDoubleClick(Object sender, MouseButtonDoubleClickedEventArgs args)
at Microsoft.SqlServer.Management.UI.Grid.GridControl.OnMouseButtonDoubleClicked(HitTestResult htArea, Int64 nRowIndex, Int32 nColIndex, Rectangle rCellRect, MouseButtons btn, GridButtonArea headerArea)
at Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid.OnMouseButtonDoubleClicked(HitTestResult htArea, Int64 rowIndex, Int32 colIndex, Rectangle cellRect, MouseButtons btn, GridButtonArea headerArea)
at Microsoft.SqlServer.Management.UI.Grid.GridControl.OnMouseDown(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at Microsoft.SqlServer.Management.UI.Grid.GridControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Microsoft.SqlServer.Management.SqlMgmt.RunningFormsTable.RunningFormsTableImpl.ThreadStarter.StartThread()

===================================

The system cannot find the file specified.

------------------------------
Program Location:

at Microsoft.SqlServer.Dts.Runtime.Wrapper.ApplicationClass.get_LogProviderInfos()
at Microsoft.SqlServer.Dts.Runtime.Application.get_LogProviderInfos()
ssms
  • 1 个回答
  • 1111 Views
Martin Hope
Riley Major
Asked: 2019-05-23 13:46:02 +0800 CST

如何检索从 UPDATE 语句的 OUTPUT 插入的行的标识值?

  • 2

当从语句OUTPUT中插入该行时,如何检索插入行的标识值?UPDATE既不@@IDENTITY也不SCOPE_IDENTITY()似乎设置正确。

考虑这段代码:

DECLARE @UpdateTable table (UpdateTableID int IDENTITY, UpdateTableValue int);
DECLARE @InsertTable table (InsertTableID int IDENTITY, UpdateTableValue1 int, UpdateTableValue2 int);
DECLARE @TestValue int = 5;
INSERT INTO @UpdateTable (UpdateTableValue) VALUES (1),(2),(3);
SELECT [@@IDENTITY] = @@IDENTITY, [SCOPE_IDENTITY()] = SCOPE_IDENTITY();

INSERT INTO @InsertTable (UpdateTableValue1, UpdateTableValue2)
SELECT
    UpdateTableValue1, UpdateTableValue2
FROM        (
                UPDATE      @UpdateTable
                SET         UpdateTableValue = UpdateTableValue + @TestValue
                OUTPUT      deleted.UpdateTableValue, inserted.UpdateTableValue
                WHERE       UpdateTableID = 2
            ) AS UpdateResults (UpdateTableValue1, UpdateTableValue2);

SELECT [@@IDENTITY] = @@IDENTITY, [SCOPE_IDENTITY()] = SCOPE_IDENTITY();

最后插入的行的标识值为 1,但@@IDENTITYand函数从执行最后一条语句之前SCOPE_IDENTITY()的原始值返回其原始值。INSERT

@@VERSION:

Microsoft SQL Azure (RTM) - 12.0.2000.8 2019 年 5 月 2 日 20:11:13 版权所有 (C) 2019 Microsoft Corporation

sql-server t-sql
  • 1 个回答
  • 2012 Views
Martin Hope
Riley Major
Asked: 2019-04-11 13:14:48 +0800 CST

T-SQL 显示 Azure SQL 托管实例与 Azure SQL 数据库

  • 2

重述:如何使用 T-SQL 确定实例是 Azure SQL 托管实例还是 Azure SQL 数据库?

azure-sql-database
  • 1 个回答
  • 550 Views
Martin Hope
Riley Major
Asked: 2019-03-09 14:56:44 +0800 CST

如何在 IBM DB2 SQL 中创建没有基础表的行?

  • 0

在 T-SQL 中,我可以执行以下操作:

SELECT      *
FROM        (SELECT 1 AS n UNION ALL SELECT 2 AS n) AS t;

在 IBM DB2 SQL 中,这会失败并显示:

[IBM][System i Access ODBC 驱动程序][DB2 for i5/OS]SQL0199 - 不需要关键字 UNION。有效令牌: , FROM INTO。

SELECT声明似乎需要一个子句FROM。事实上,一个简化的 SQL 语句,例如:

SELECT 1 AS n

还有错误:

[IBM][System i Access ODBC 驱动程序][DB2 for i5/OS]SQL0104 - 令牌无效。有效令牌: , FROM INTO。

有一个UNNEST 函数可以从数组创建行,但似乎数组必须已经由变量或参数之类的东西表示。

我知道我可以通过使用不可能的标准(例如 1 = 0)从任意表中执行操作来解决此问题SELECT,但这似乎是一个愚蠢的要求。

那么如何在没有基础表的情况下构造行呢?

(关键词:理货表;派生表)

db2
  • 2 个回答
  • 5995 Views
Martin Hope
Riley Major
Asked: 2017-09-20 09:04:41 +0800 CST

为什么在 SQL Server 2016 上使用 XML 的函数编译时间长?

  • 7

我们有将数据收集到 XML 中的内联函数,将派生的 XML 传递给其他函数,然后将其分解并重组为字符串。

(你的“你不应该在 T-SQL 中做那种事情”是另一天的讨论。)

这在 2005 和 2008 R2 中运行良好多年。我们现在升级到 2016 SP1。使用这些函数的查询在我们的生产服务器上运行不到一秒,现在在 2016 SP1 中运行得更快。那太好了,但是在 2016 SP1 上编译需要一个小时。严重地:

在此处输入图像描述

生产环境:

在此处输入图像描述

(它们都来自 SQL Sentry Plan Explorer。)

我们已经尝试使用 2008 (100) 和 2016 (130) 兼容级别的数据库(但我们还没有使用“Legacy Cardinality Estimation”和“Query Optimizer Fixes”设置,它们目前都是“OFF”)。我们试过使用QUERYTRACEON 9481,似乎没有效果。

同样,这与最终计划无关,因为它们都在很短的时间内运行。大约是制定计划所需的时间。

我们已经设法通过一组简化的代码在一定程度上重现了这个问题。从以下示例调用顶级函数的语句在 SQL Server 2016 (SP1-CU5) 上编译需要 30-60 秒,但在 SQL Server 2008 R2 (SP3) 上编译和运行只需不到一秒。

例子

/*

Create and populate table...

*/

CREATE TABLE TestXMLStuff (OrderID int, ProdLength int, ProdWidth int, ProdHeight int);
INSERT INTO TestXMLStuff (OrderID, ProdLength, ProdWidth, ProdHeight) VALUES
    (1, 10, 15, 20),
    (1, 15, 20, 25),
    (2, 20, 25, 30),
    (2, 25, 30, 35),
    (2, 30, 35, 40);
GO

/*

Function which accepts XML, shreds it and reforms it as a string...

*/


CREATE FUNCTION TestCalc
(   
    @T varchar(8000),
    @X xml
)
RETURNS TABLE 
AS
RETURN 
    WITH p AS
    (
        SELECT  
            LF = CHAR(13) + CHAR(10),
            Tab = CHAR(9),
            T = isNull(@T,'')
    ), pid AS
    (
        SELECT
            isNull(ProdInfoXMLTable.ProdInfoXML.query('(/ProdInfo)').value('(.)[1]','varchar(max)'),'') AS ProdInfoText
        FROM        (
                        SELECT
                            ProdInfoXML =
                                (
                                    SELECT
                                        ProdInfo = 
                                            CASE WHEN Products.ProdNum > 1 THEN '--' + p.LF ELSE '' END +
                                            'Product Number: ' + CONVERT(varchar(50),Products.ProdNum) + p.LF +
                                                CASE WHEN Products.ProdLength       = '' THEN '' ELSE p.Tab + 'Length: '                + Products.ProdLength       + p.LF END +
                                                CASE WHEN Products.ProdWidth        = '' THEN '' ELSE p.Tab + 'Width: '                 + Products.ProdHeight       + p.LF END +
                                                CASE WHEN Products.ProdHeight       = '' THEN '' ELSE p.Tab + 'Height: '                + Products.ProdHeight       + p.LF END
                                    FROM        (
                                                    SELECT
                                                        ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS ProdNum,
                                                        isNull(P.X.value('(./Length)[1]','varchar(500)'),'') AS ProdLength,
                                                        isNull(P.X.value('(./Width)[1]','varchar(500)'),'') AS ProdWidth,
                                                        isNull(P.X.value('(./Height)[1]','varchar(500)'),'') AS ProdHeight
                                                    FROM        @x.nodes('/Products/Product') AS P(X)
                                                ) AS Products
                                    CROSS JOIN  p
                                    FOR XML PATH(''), TYPE
                                )
                    ) AS ProdInfoXMLTable
    )
    SELECT
        Final = p.T + p.LF + p.LF + pid.ProdInfoText
    FROM        p
    CROSS JOIN  pid;

GO

/*

Function to create XML in the format required for TestCalc...

*/

CREATE FUNCTION TestGetXML
(   
    @N int
)
RETURNS TABLE 
AS
RETURN 
    WITH p AS
    (
        SELECT  
            N = isNull(@N,0)
    )
    SELECT
        ProdInfoXML =
            (
                SELECT
                    [Length] = ProdData.ProdLength,
                    [Width] = ProdData.ProdWidth,
                    [Height] = ProdData.ProdHeight
                FROM        TestXMLStuff ProdData
                WHERE       ProdData.OrderID = @N
                FOR XML PATH('Product'), ROOT('Products'), TYPE
            );
GO

/*

Function to join the other two functions, gathering the XML and feeding it to the string creator which shreds and reforms it...

*/

CREATE FUNCTION TestGetFromTableUsingFunc
(   
    @N int
)
RETURNS TABLE 
AS
RETURN 
    WITH p AS
    (
        SELECT  
            N = isNull(@N,0)
    )
    SELECT
        FinalResult = 'This is a ' + TestCalcResults.Final
    FROM        p
    CROSS APPLY TestGetXML
                (
                    p.N
                ) AS x
    CROSS APPLY TestCalc
                (
                    'test',
                    x.ProdInfoXML
                ) AS TestCalcResults;
GO

/*

Code to call the function. This is what takes around 60 seconds to compile on our 2016 system but basically no time on the 2008 R2 system.

*/

SELECT      *
FROM        TestXMLStuff
CROSS APPLY TestGetFromTableUsingFunc
            (
                OrderID
            )
OPTION      (RECOMPILE);
GO

@@version编译不是问题的生产:

Microsoft SQL Server 2008 R2 (SP3) - 10.50.6000.34 (X64)

测试@@version编译需要“永远”的地方:

Microsoft SQL Server 2016 (SP1-CU5) (KB4040714) - 13.0.4451.0 (X64) 

问题

  1. 为什么从 2008 R2 到 2016 年的编译时间会如此下降?

  2. 这个答案是否揭示了一个简单的解决方案来解决这个难题,而不是改变所有这些工作的方式?(我希望有神奇的跟踪标志或即将推出的 Microsoft 更新。)

(如果这是 SQL Server 2017,我会使用 JSON 来收集和传递数据,这似乎更快且开销更低,然后我会使用 JSON 函数来切碎并重组STRING_AGG为文本。但是,唉,那还不是可用的。)

根据Joe Obbish的提示,我使用以下代码收集了使用跟踪标志 8675时的结果:

DBCC TRACEON(3604)
SELECT      *
FROM        TestXMLStuff
CROSS APPLY TestGetFromTableUsingFunc
            (
                OrderID
            )
OPTION      (RECOMPILE, QUERYTRACEON 8675);
DBCC TRACEOFF(3604)

在 2008 R2 实例上,它花费了不到一秒的时间,并产生了这个:

DBCC execution completed. If DBCC printed error messages, contact your system administrator. End of simplification, time: 0.008 net: 0.008 total: 0.008 net: 0.008

end exploration, tasks: 597 no total cost time: 0.005 net: 0.005 total: 0.014 net: 0.014

end search(0),  cost: 2071.66 tasks: 2267 time: 0.005 net: 0.005 total: 0.02 net: 0.02

end exploration, tasks: 2703 Cost = 2071.66 time: 0.002 net: 0.002 total: 0.022 net: 0.022

end search(1),  cost: 1731.11 tasks: 3362 time: 0.004 net: 0.004 total: 0.026 net: 0.026

end exploration, tasks: 3363 Cost = 1731.11 time: 0 net: 0 total:
0.026 net: 0.026

end search(1),  cost: 1731.11 tasks: 3382 time: 0 net: 0 total: 0.026 net: 0.026

end exploration, tasks: 3413 Cost = 1731.11 time: 0 net: 0 total:
0.027 net: 0.027

end search(2),  cost: 1731.11 tasks: 3515 time: 0 net: 0 total: 0.027 net: 0.027

End of post optimization rewrite, time: 0.001 net: 0.001 total: 0.029 net: 0.029

End of query plan compilation, time: 0.001 net: 0.001 total: 0.03 net:
0.03


(5 row(s) affected) DBCC execution completed. If DBCC printed error messages, contact your system administrator.

在 2016 SP1-CU5 实例上,它花费了 1 分 11 秒并产生了这个:

DBCC execution completed. If DBCC printed error messages, contact your system administrator. End of simplification, time: 0.004 net: 0.004 total: 0.004 net: 0.004

end exploration, tasks: 612 no total cost time: 0.003 net: 0.003 total: 0.008 net: 0.008

end exploration, tasks: 613 no total cost time: 0 net: 0 total: 0.008 net: 0.008

end exploration, tasks: 2305 no total cost time: 0.002 net: 0.002 total: 0.011 net: 0.011

end exploration, tasks: 2306 no total cost time: 0 net: 0 total: 0.011 net: 0.011

end search(0),  cost: 4402.32 tasks: 2306 time: 0 net: 0 total: 0.011 net: 0.011

end exploration, tasks: 2738 Cost = 4402.32 time: 0.001 net: 0.001 total: 0.013 net: 0.013

end exploration, tasks: 2739 Cost = 4402.32 time: 0 net: 0 total:
0.013 net: 0.013

end exploration, tasks: 3466 Cost = 4402.32 time: 0.002 net: 0.002 total: 0.015 net: 0.015

end exploration, tasks: 3467 Cost = 4402.32 time: 0 net: 0 total:
0.015 net: 0.015

end search(1),  cost: 3938.19 tasks: 3467 time: 0 net: 0 total: 0.015 net: 0.015

end exploration, tasks: 3468 Cost = 3938.19 time: 0 net: 0 total:
0.015 net: 0.015

end exploration, tasks: 3469 Cost = 3938.19 time: 0 net: 0 total:
0.015 net: 0.015

end exploration, tasks: 3489 Cost = 3938.19 time: 0 net: 0 total:
0.015 net: 0.015

end exploration, tasks: 3490 Cost = 3938.19 time: 0 net: 0 total:
0.015 net: 0.015

end search(1),  cost: 3938.19 tasks: 3490 time: 0 net: 0 total: 0.015 net: 0.015

end exploration, tasks: 3521 Cost = 3938.19 time: 0 net: 0 total:
0.015 net: 0.015

end exploration, tasks: 3522 Cost = 3938.19 time: 0 net: 0 total:
0.015 net: 0.015

end exploration, tasks: 3625 Cost = 3938.19 time: 0 net: 0 total:
0.016 net: 0.016

end exploration, tasks: 3626 Cost = 3938.19 time: 0 net: 0 total:
0.016 net: 0.016

end search(2),  cost: 3938.19 tasks: 3626 time: 0 net: 0 total: 0.016 net: 0.016

End of post optimization rewrite, time: 0 net: 0 total: 0.016 net:
0.016

End of query plan compilation, time: 0.001 net: 0.001 total: 0.018 net: 0.018


(5 row(s) affected) DBCC execution completed. If DBCC printed error messages, contact your system administrator.

尽管发生了更多变化,但看起来经过的时间仅为 0.018(秒?),小于 2008 R2 上的 0.03。所以编译/优化/执行的这个阶段一定不会花这么长时间。但肯定是。


我们最终的 2016 生产实例将具有与当前生产的 2008 R2 相同的“硬件”。Test/Dev 2016 实例具有不同的规格,因此这些比较不是同类比较。产品是 78 演出。开发是 16 演出。但我在另一个 20 gig 的 2008 R2 盒子上测试过,速度很快。此外,我们还在谈论索引良好的少量数据。在编译过程中,IO 很少,但 CPU 很多。

我可以看到统计数据是影响真实(大)表的真实函数的问题,但在我人为的简化示例中,需要 1 分钟以上的时间才能对5个充满整数的行执行一些简单的 XML/文本操作。我可以更快地输入结果。:) 我相信我们在生产中有自动统计,而且我没有看到其他看似与统计相关的性能问题。另一个非生产 2008 R2 开发/测试环境(具有与 2016 开发/测试类似的陈旧生产副本)是 lickety-split。

sql-server optimization
  • 2 个回答
  • 1143 Views
Martin Hope
Riley Major
Asked: 2017-07-25 14:37:36 +0800 CST

扩展事件允许的最大绑定操作数是多少?

  • 14

如果您在事件会话中向事件添加“太多”操作,您将收到此错误:

消息 25639,级别 16,状态 23,第 1 行事件“[事件名称]”超出了允许的绑定操作数。

允许多少动作?它因事件而异吗?

根据实验,答案似乎是 27 sqlserver.rpc_completed。但我没有在任何Microsoft 文档中找到该编号。而且它似乎因事件而异,因为我能够获得 30 个sqlserver.sql_batch_completed。

失败的示例代码:

CREATE EVENT SESSION [Test] ON SERVER 
ADD EVENT sqlserver.rpc_completed(
    ACTION(
        package0.callstack,
        package0.collect_cpu_cycle_time,
        package0.collect_current_thread_id,
        package0.collect_system_time,
        package0.event_sequence,
        package0.last_error,
        package0.process_id,
        sqlos.cpu_id,
        sqlos.numa_node_id,
        sqlos.scheduler_address,
        sqlos.scheduler_id,
        sqlos.system_thread_id,
        sqlos.task_address,
        sqlos.task_elapsed_quantum,
        sqlos.task_resource_group_id,
        sqlos.task_resource_pool_id,
        sqlos.task_time,
        sqlos.worker_address,
        sqlserver.client_app_name,
        sqlserver.client_connection_id,
        sqlserver.client_hostname,
        sqlserver.client_pid,
        sqlserver.context_info,
        sqlserver.database_id,
        sqlserver.database_name,
        sqlserver.is_system,
        sqlserver.nt_username,
        sqlserver.plan_handle))
GO
DROP EVENT SESSION [Test] ON SERVER
GO

成功的示例代码(除最后一项外相同):

CREATE EVENT SESSION [Test] ON SERVER 
ADD EVENT sqlserver.rpc_completed(
    ACTION(
        package0.callstack,
        package0.collect_cpu_cycle_time,
        package0.collect_current_thread_id,
        package0.collect_system_time,
        package0.event_sequence,
        package0.last_error,
        package0.process_id,
        sqlos.cpu_id,
        sqlos.numa_node_id,
        sqlos.scheduler_address,
        sqlos.scheduler_id,
        sqlos.system_thread_id,
        sqlos.task_address,
        sqlos.task_elapsed_quantum,
        sqlos.task_resource_group_id,
        sqlos.task_resource_pool_id,
        sqlos.task_time,
        sqlos.worker_address,
        sqlserver.client_app_name,
        sqlserver.client_connection_id,
        sqlserver.client_hostname,
        sqlserver.client_pid,
        sqlserver.context_info,
        sqlserver.database_id,
        sqlserver.database_name,
        sqlserver.is_system,
        sqlserver.nt_username))
GO
DROP EVENT SESSION [Test] ON SERVER
GO

(我尝试了几个不同的动作,它似乎与包含哪些动作无关——但也许它基于动作名称的总字符数?)

我正在使用的完整操作列表:

package0.callstack,
package0.collect_cpu_cycle_time,
package0.collect_current_thread_id,
package0.collect_system_time,
package0.event_sequence,
package0.last_error,
package0.process_id,
sqlos.cpu_id,
sqlos.numa_node_id,
sqlos.scheduler_address,
sqlos.scheduler_id,
sqlos.system_thread_id,
sqlos.task_address,
sqlos.task_elapsed_quantum,
sqlos.task_resource_group_id,
sqlos.task_resource_pool_id,
sqlos.task_time,
sqlos.worker_address,
sqlserver.client_app_name,
sqlserver.client_connection_id,
sqlserver.client_hostname,
sqlserver.client_pid,
sqlserver.context_info,
sqlserver.database_id,
sqlserver.database_name,
sqlserver.is_system,
sqlserver.nt_username,
sqlserver.plan_handle,
sqlserver.query_hash,
sqlserver.query_hash_signed,
sqlserver.query_plan_hash,
sqlserver.query_plan_hash_signed,
sqlserver.request_id,
sqlserver.server_instance_name,
sqlserver.server_principal_name,
sqlserver.server_principal_sid,
sqlserver.session_id,
sqlserver.session_nt_username,
sqlserver.session_resource_group_id,
sqlserver.session_resource_pool_id,
sqlserver.session_server_principal_name

@@版本输出:

Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) 
    Oct 28 2016 18:17:30 
    Copyright (c) Microsoft Corporation
    Developer Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600: ) (Hypervisor)
sql-server sql-server-2016
  • 1 个回答
  • 1096 Views
Martin Hope
Riley Major
Asked: 2017-06-08 09:24:01 +0800 CST

为什么 GETUTCDATE 早于 SYSDATETIMEOFFSET?

  • 8

或者,微软是如何让时间旅行成为可能的?

考虑这段代码:

DECLARE @Offset datetimeoffset = sysdatetimeoffset();
DECLARE @UTC datetime = getUTCdate();
DECLARE @UTCFromOffset datetime = CONVERT(datetime,SWITCHOFFSET(@Offset,0));
SELECT
    Offset = @Offset,
    UTC = @UTC,
    UTCFromOffset = @UTCFromOffset,
    TimeTravelPossible = CASE WHEN @UTC < @UTCFromOffset THEN 1 ELSE 0 END;

@Offset设置为before @UTC,但它有时具有较晚的值。(我已经在 SQL Server 2008 R2 和 SQL Server 2016 上尝试过。你必须运行它几次才能发现可疑事件。)

这似乎不仅仅是四舍五入或缺乏精度的问题。(事实上​​,我认为舍入是偶尔“修复”问题的原因。)样本运行的值如下:

  • 抵消
    • 2017-06-07 12:01:58.8801139 -05:00
  • 世界标准时间
    • 2017-06-07 17:01:58.877
  • UTC 从偏移量:
    • 2017-06-07 17:01:58.880

因此日期时间精度允许 .880 作为有效值。

即使是Microsoft 的 GETUTCDATE 示例也显示 SYS* 值晚于旧方法,尽管被更早地选择:

SELECT 'SYSDATETIME()      ', SYSDATETIME();  
SELECT 'SYSDATETIMEOFFSET()', SYSDATETIMEOFFSET();  
SELECT 'SYSUTCDATETIME()   ', SYSUTCDATETIME();  
SELECT 'CURRENT_TIMESTAMP  ', CURRENT_TIMESTAMP;  
SELECT 'GETDATE()          ', GETDATE();  
SELECT 'GETUTCDATE()       ', GETUTCDATE();  
/* Returned:  
SYSDATETIME()            2007-05-03 18:34:11.9351421  
SYSDATETIMEOFFSET()      2007-05-03 18:34:11.9351421 -07:00  
SYSUTCDATETIME()         2007-05-04 01:34:11.9351421  
CURRENT_TIMESTAMP        2007-05-03 18:34:11.933  
GETDATE()                2007-05-03 18:34:11.933  
GETUTCDATE()             2007-05-04 01:34:11.933  
*/

我认为这是因为它们来自不同的底层系统信息。谁能确认并提供详细信息?

微软的 SYSDATETIMEOFFSET 文档说“SQL Server 通过使用 GetSystemTimeAsFileTime() Windows API 获取日期和时间值”(感谢 srutzky),但他们的GETUTCDATE 文档没有那么具体,只说“值来自操作系统运行 SQL Server 实例的计算机”。

(这并不完全是学术性的。我遇到了一个由此引起的小问题。我正在升级一些程序以使用 SYSDATETIMEOFFSET 而不是 GETUTCDATE,希望将来能获得更高的精度,但我开始得到奇怪的排序,因为其他程序是仍在使用 GETUTCDATE 并且偶尔在日志中“跳过”我转换的过程。)

sql-server datetime
  • 1 个回答
  • 4038 Views
Martin Hope
Riley Major
Asked: 2016-05-26 12:02:32 +0800 CST

如何将 SQL Server Unicode / NVARCHAR 字符串设置为表情符号或补充字符?

  • 34

我想根据其 Unicode 代码点将 Unicode 字符串变量设置为特定字符。

我想使用超过 65535 的代码点,但 SQL Server 2008 R2 数据库的排序规则为SQL_Latin1_General_CP1_CI_AS.

根据微软的 NCHAR 文档,该NCHAR函数采用如下整数:

整数表达式

当数据库的排序规则不包含补充字符 (SC) 标志时,这是一个从 0 到 65535(0 到 0xFFFF)的正整数。如果指定了超出此范围的值,则返回 NULL。有关补充字符的更多信息,请参阅排序规则和 Unicode 支持。

当数据库的排序规则支持补充字符 (SC) 标志时,这是一个从 0 到 1114111(0 到 0x10FFFF)的正整数。如果指定了超出此范围的值,则返回 NULL。

所以这段代码:

SELECT NCHAR(128512);

NULL在此数据库中返回。

我希望它返回与此相同的内容:

SELECT N'?';

如何在排序规则“不包含补充字符 (SC) 标志”的数据库中使用代码(不使用实际表情符号字符)将 Unicode 字符串变量(例如 nvarchar)设置为表情符号?

表情符号 Unicode 代码点的完整列表

(最终我希望任何角色都能工作。我只是选择了表情符号以方便参考。)

(虽然服务器是SQL Server 2008 R2,但我也很好奇以后版本有什么解决方案。)

假设没有办法,我可以在另一个具有适当排序规则的数据库中引用内联用户定义函数吗?

如何找到具有“补充字符”标志的排序规则?

这在我们的服务器上不返回任何记录:

SELECT * FROM sys.fn_helpcollations() 
WHERE name LIKE 'SQL%[_]SC';

似乎引入Latin1_General_100_CI_AS_SC的 SQL Server 2012 会起作用。您可以在较旧的实例上安装排序规则吗?

整理参考:

  • SQL Server 中的 char、nchar、varchar 和 nvarchar 有什么区别?
  • Microsoft 的补充字符整理信息
  • Microsoft 的 SQL Server 2008 R2 排序规则列表

有没有解释为什么,不管排序规则,SQL Server 可以从 ? 的角度理解和处理扩展字符NCHAR?

sql-server t-sql
  • 1 个回答
  • 43026 Views
Martin Hope
Riley Major
Asked: 2014-10-07 13:05:33 +0800 CST

为什么 SSAS 每隔几秒就会重新启动一次?

  • 1

我们有一个 SQL Server 2005 Analysis Server,本周末开始重新启动,似乎没有任何外部更改。

服务器目前的状态是,只要启用了SSAS服务,就会一直重启。如果该服务被手动禁用然后停止,该服务将不再循环。但是一旦启用,该服务将再次开始循环。

互联网搜索找到了一些这种行为的例子,但没有一个似乎适用的解决方案。请参见,例如:服务级别帐户 - SQL 2005 SSAS - 连接到 OLAP 时出错。另请参见,例如:我无法连接到 SSMS 中的分析服务...

Brent Ozar在 LessThanDot 上报告了一个类似的问题,但线程上没有解决方案,最后一个条目是 2009 年 3 月 27 日星期五下午 4:08。

这是 msmdsrv.log 文件的片段:

(10/6/2014 3:21:43 PM) Message: The flight recorder was started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210005)
(10/6/2014 3:21:43 PM) Message: Service started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210000)
(10/6/2014 3:22:40 PM) Message: Service stopped. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210001)
(10/6/2014 3:22:45 PM) Message: The flight recorder was started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210005)
(10/6/2014 3:22:45 PM) Message: Service started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210000)
(10/6/2014 3:23:41 PM) Message: Service stopped. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210001)
(10/6/2014 3:23:47 PM) Message: The flight recorder was started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210005)
(10/6/2014 3:23:47 PM) Message: Service started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210000)
(10/6/2014 3:24:41 PM) Message: Service stopped. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210001)
(10/6/2014 3:24:47 PM) Message: The flight recorder was started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210005)
(10/6/2014 3:24:47 PM) Message: Service started. (Source: \\?\S:\CubeLog\msmdsrv.log, Type: 1, Category: 289, Event ID: 0x41210000)

系统日志的事件查看器一遍又一遍地具有:

"The SQL Server Analysis Services (MSSQLSERVER) service was successfully sent a stop control."
"The SQL Server Analysis Services (MSSQLSERVER) service was successfully sent a start control."
"The SQL Server Analysis Services (MSSQLSERVER) service was successfully sent a stop control."
"The SQL Server Analysis Services (MSSQLSERVER) service was successfully sent a start control."
"The SQL Server Analysis Services (MSSQLSERVER) service was successfully sent a stop control."
"The SQL Server Analysis Services (MSSQLSERVER) service was successfully sent a start control."
"The SQL Server Analysis Services (MSSQLSERVER) service was successfully sent a stop control."
etc....

似乎没有创建 SQLDmprNNNN.mdmp 文件。没有我们知道的其他错误日志记录。

我们怎样才能找出问题所在?有没有一种方法可以判断是否有任何第三方服务或进程正在循环 SSAS 服务?

我们还在SQL Server Central上发布了这个问题。

sql-server ssas
  • 1 个回答
  • 1192 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve