Quantcast
Channel: SQL Server Database Engine forum
Viewing all 15911 articles
Browse latest View live

Low performance in ApexSql recovery

$
0
0

Hi every one,

I have server for recovering data with apexsql recovery software.the configuration of server is :

Hardware

Core 2.0 GHz CPU ( 2 Socket + 2 Core ) 8 GB memory

100 GB disk space

SQL Server

SQL Server 2016

OS

Windows Server 2016

Software

.NET Framework 4.7.2 

I have problem when I used apexsql recovery for recoveringdata from full backup file. The software works slowly .    I have some error in performance monitoring of server :

how can I  increse performance of apexsql recovery for large databases???








version store space not being released

$
0
0

This morning I tried to shrink a DB file after dropping about 70g of data from it. I ran DBCC SHRINKFILE(1,x) where x was the size I wanted to shrink to. X was slightly larger than the used space in the file.  It ran for approx 3 hours and never completed. I cancelled it because it there is a production DB on this server and my tempdb space was filling up due to version store (this non-prod DB has read committed snapshot isolation enabled). The session I ran shrinkfile on (and subsequently cancelled) disconnected long ago however 4 hours later none of the version store has been released. Is there something I can do to force it to be released short of restarting the server?



Chuck

There is insufficient system memory in resource pool 'internal' to run this query - SQL 2014 SP3

$
0
0

Hi All,

I'm running SQL 2014 SP3 and after July 2019 patching I'm seeing lots of errors relating to memory issues i.e.  There is insufficient system memory in resource pool 'internal' to run this query

This is causing alot of problems executing basic queries and backups are failing

The server itself has plenty of available memory and max memory is set to 65 GB. I noticed from a monitoring tool that we use we observed and a severe degradation in the maximum workspace memory and a massive increase in pages allocated to memoryclerk_SOSNODE.  This all occurred after installed July 2019 updates KB4504418, KB4507448, KB506996 & KB507005

Do you think the updates have caused a memory leak, We are planning to install SP3 CU3 later this week

Below is the output from DBCC MEMORYSTATUS

Process/System Counts                   Value

---------------------------------------- --------------------

Available Physical Memory               165309018112

Available Virtual Memory                140583747022848

Available Paging File                   201184542720

Working Set                             1112621056

Percent of Committed Memory in WS       99

Page Faults                             9545792

System physical memory high             1

System physical memory low              0

Process physical memory low             1

Process virtual memory low              0

(10 row(s) affected)

Memory Manager                          KB

---------------------------------------- -----------

VM Reserved                             149521168

VM Committed                            1172256

Locked Pages Allocated                  64049508

Large Pages Allocated                   0

Emergency Memory                        1024

Emergency Memory In Use                 16

Target Committed                        67108872

Current Committed                       65221768

Pages Allocated                         63602752

Pages Reserved                          -852016

Pages Free                              125264

Pages In Use                            63571528

Page Alloc Potential                    181896

NUMA Growth Phase                       2

Last OOM Factor                         1

Last OS Error                           0

(16 row(s) affected)

Memory node Id = 0                      KB

---------------------------------------- -----------

VM Reserved                             117265664

VM Committed                            1170680

Locked Pages Allocated                  31385924

Pages Allocated                         31137760

Pages Free                              46824

Target Committed                        33554424

Current Committed                       32556608

Foreign Committed                       0

Away Committed                          0

Taken Away Committed                    0

(10 row(s) affected)

Memory node Id = 1                      KB

---------------------------------------- -----------

VM Reserved                             32255440

VM Committed                            1556

Locked Pages Allocated                  32663584

Pages Allocated                         32464992

Pages Free                              78440

Target Committed                        33554424

Current Committed                       32665144

Foreign Committed                       0

Away Committed                          0

Taken Away Committed                    0

(10 row(s) affected)

Memory node Id = 64                     KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            20

Locked Pages Allocated                  0

(3 row(s) affected)

MEMORYCLERK_SQLGENERAL (node 0)         KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         20568

(6 row(s) affected)

MEMORYCLERK_SQLGENERAL (node 1)         KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         352

(6 row(s) affected)

MEMORYCLERK_SQLGENERAL (Total)          KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         20920

(6 row(s) affected)

MEMORYCLERK_SQLBUFFERPOOL (node 0)      KB

---------------------------------------- -----------

VM Reserved                             13634884

VM Committed                            524288

Locked Pages Allocated                  287548

SM Reserved                             0

SM Committed                            0

Pages Allocated                         1378936

(6 row(s) affected)

MEMORYCLERK_SQLBUFFERPOOL (node 1)      KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         146128

(6 row(s) affected)

MEMORYCLERK_SQLBUFFERPOOL (Total)       KB

---------------------------------------- -----------

VM Reserved                             13634884

VM Committed                            524288

Locked Pages Allocated                  287548

SM Reserved                             0

SM Committed                            0

Pages Allocated                         1525064

(6 row(s) affected)

MEMORYCLERK_SQLQUERYEXEC (node 0)       KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         280

(6 row(s) affected)

MEMORYCLERK_SQLOPTIMIZER (node 0)       KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         1848

(6 row(s) affected)

MEMORYCLERK_QUERYDISKSTORE (node 0)     KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         1432

(6 row(s) affected)

MEMORYCLERK_SQLUTILITIES (node 0)       KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         248

(6 row(s) affected)

MEMORYCLERK_SQLUTILITIES (node 1)       KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         16

(6 row(s) affected)

MEMORYCLERK_SQLUTILITIES (Total)        KB

---------------------------------------- -----------

VM Reserved                             0

VM Committed                            0

Locked Pages Allocated                  0

SM Reserved                             0

SM Committed                            0

Pages Allocated                         264

(6 row(s) affected)


implicit RTRIM

$
0
0

Hello,

I would just like to point out a strange behavior of SqlServer. In some contexts makes an RTRIM not requested, which leads to absurd behaviors such as the following.

COMPARISON (operator "="). Example:
select case when C1    = C2    then'TRUE'else'false'end EQUAL_1
,      case when C1+C1 = C2+C2 then'TRUE'else'false'end EQUAL_2
from( select 'A' C1, 'A ' C2 )t;
--EQUAL_1 gives "TRUE" , so the 2 fields C1 and C2 are equal
--EQUAL_2 gives "false", so if I double the 2 fields they became DIFFERENT!


UNION.  As a consequence (X UNION Y) differs from (Y UNION X) ... UNION should be a commutative operator. Example:
select len( (select'A 'union select'A' )+'.');--gives 3
select len( (select'A' union select'A ')+'.');--gives 2

After a database restore there are a 4 tables that are missing

$
0
0

After a database restore there are a 4 tables that are missing.

How could this happen?

The tables do not have that much data:

name                                        rows

AA_tbl_Velocity                        7499275            

ATSCore                                   19328              

inv_com_custexceptions             9        

inv_com_salespersonrates         51                 

SQL server patching practice

$
0
0

I am wondering how everyone does in their environment, my situation is, we have SQL servers hosting vendor's application databases, many of them are due for patching, but we need vendor's agreement to do the patching, however, vendor normally prefer no change at all, so patching are behind, is there anyone with similar situation? how do you handle it?

Finding columns to join from database that has no relationships between tables designated

$
0
0

Hello -

I am working with a database that does not have a database diagram.  When I try to create one, it doesn't show any relationships at all.  

I need to join tables.  Looking for matching columns in tables is like the ol' needle in a haystack.

Any suggestions will be appreciated!

junior mint

SQL alwayON on machines with two SQL instances

$
0
0

I have two SQL servers with two instances each (2012 and 2016), both machine are in windows 2012 fail over cluster. I am able to have the named instance (2016) created Alwayson group and the listener with a port 5023. it works fine. but I cannot get the default instance to have the AlwaysON group working, the AlwaysOn group created and the listener created on 5022(later tried 5024....), but the secondary always shows disconnected. I tried swap the two nodes for primary and secondary, no luck.

replica_server_nameendpoint_urlconnected_state_desclast_connect_error_descriptionlast_connect_error_numberlast_connect_error_timestamp
mySecondaryServer    TCP://mySecondaryServer.esclhin.on.ca:5024DISCONNECTEDNULLNULLNULL

myPrimaryServer TCP://myPrimaryServer .esclhin.on.ca:5024CONNECTEDNULLNULLNULL

Does it support two instances on a machine for AlwaysON group?


How to find logs to show why an application alters and drops a database but unable to create it only on a specific day in sql server?

$
0
0
I have SQL Job that runs a SPROC everyday. Basically what it does is to sync our Production database to our Offline database.
The SPROC Alter, Drop then Create the database on those servers, 200 in total.
1st step is it creates an Offline database. Then it pushes it down to the servers. Which the individual server will run a task, C:\Windows\system32>schtasks /run /s
The tasks on the servers have identical script.
The SQL Job doesn't fail because it was able to push the last step to the servers. The server tasks were successful to all but one.
The issue here is that every Saturday morning instead of finishing the task by Creating the database, it does not and I don't have the logs that will tell me why.

The screenshot below is what's suppose to happen except the one lined is what's missing for that server that's having this issue.

SQL Server 2016 remote access denied

$
0
0

I have two VM with an SQL server on each and I need to connect to both SQL servers from each machine, either from SSMS and with PowerShell script.
Also, today I don't manage to do that I'm always getting "Access Denied" from both server when trying to connect to the remote one.

  • Here is my setup.
    • Windows Server 2012 R2
    • Sql Server 2016 Dev edition
    • SSMS v18.2
    • Both machines are in the AD Domain,
    • I'm using on both machine my AD account which is member of the local Admin group of each server
    • The access to Administrative shares is working properly.
    • My account is member of the sysadmin Server Roles of both SQL server, and owner of the DB I need to reach.
    • Both server have the "Allow remote connections to this server" checked.
    • Both SQL server service are running under my AD account.
    • Both Server have the Firewall disable to make sure this is not due to Firewall restriction.

Any idea what I'm missing ?


Matthieu

Backup and restore a partition of a database

$
0
0
In a partitioned database, can we backup a partition and restore it?

TDE- question!

$
0
0

Hi All,

We have SQL server 2016 and windows server 2016, we have generated the private key with openssl and get  certificate signed with our local security team,then we have imported/exported the certificate to the say ABC server then created the master key and certificate.

Now we have to change the Host Name from(say ex) ABC to XYZ.

what pre steps should be taken for this to acheieve in an well manner, worrying about more it was imported to server & created private/certificate in master as well.

As of now the server is not live on production but some databases which we restored apps team is using for their testing prior to the actual migration.

I appreciate your help on this.


Regards, S_NO "_"

SQL Database Error 924 – Database is already open and can only have one user at a time

$
0
0

In a Java-application I am working on, I have an updater, which updates the db structure whenever a new version is started for the first time. 
This updater is executed in single user mode, to ensure no one is working on the db in the meantime. 
During this update, I have to request meta data and this request sometimes leads to the Error 924. 
This bug occurs only since I upgraded the mssql-jdbc driver to 6.3.3 or later and I therefor opened an issue on theirGithub page
However, during the discussion in this issue, it turned out, that neither the driver nor our code opens a new connection. Even the SQL Server Profiler logs only one connection. 
During my research, I found an article, which states, that SINGLE_USER can only be used if AUTO_UPDATE_ASYNC is turned OFF. That's the case in my database, but since async jobs on the SQL Server seem to cause problems with single user mode, my guess is, that some statements used by the driver to load the meta data (starting with Line 988) are executed asynchronously. This presumption is reinforced by the fact, that the error only occurs, if the database is stored on a HDD drive. On SSD drives everything works fine, which sounds like some kind of race condition. 
Our current workaround for this is to catch this error and retry the statement after 3 seconds, until it works. Usually it takes about 5 retries or 15 seconds.

Is there some setting in the SQL Server I am missing or what else could cause this issue?

cross db union all - will each select run in parallel or serially?

$
0
0

Hi we have 20 databases sitting on the same 2017 standard instance. We are thinking about issuing 20 selects separated by union all to extract data from each.

Will the selects run in parallel (and results be brought back together) or serially?  I'm a bit limited at the moment in terms of proving this out myself with a datetime in each select.

Replication - Subscriber DB changing Drive

$
0
0

hi,

we have ServerA  -  DatabaseA  for  subscriber  ( transaction replication)

DatabaseA  is in Drive  D:

we plan to  move this database into F: (which is high-throughput drive).

how to accomplish this without affect Replication setup?


Parsing Cluster Diagnostic files (SQLDiag)

$
0
0

On 1 SQL 2014 I started to receive cluster diagnostic files in the log folder way more often then before . I need the XQuery to parse the events, but I feel pretty novice to XQuery.

from https://docs.microsoft.com/en-us/sql/sql-server/failover-clusters/windows/view-and-read-failover-cluster-instance-diagnostics-log?view=sql-server-2014

I ran specified query from the site (into a temp table first)

SELECT 

xml_data.value('(event/@name)[1]','varchar(max)')AS'Name' 

,xml_data.value('(event/@package)[1]','varchar(max)')AS'Package' 

,xml_data.value('(event/@timestamp)[1]','datetime')AS'Time' 

,xml_data.value('(event/data[@name=''state'']/value)[1]','int')AS'State' 

,xml_data.value('(event/data[@name=''state_desc'']/text)[1]','varchar(max)')AS'State Description' 

,xml_data.value('(event/data[@name=''failure_condition_level'']/value)[1]','int')AS'Failure Conditions' 

,xml_data.value('(event/data[@name=''node_name'']/value)[1]','varchar(max)')AS'Node_Name' 

,xml_data.value('(event/data[@name=''instancename'']/value)[1]','varchar(max)')AS'Instance Name' 

,xml_data.value('(event/data[@name=''creation time'']/value)[1]','datetime')AS'Creation Time' 

,xml_data.value('(event/data[@name=''component'']/value)[1]','varchar(max)')AS'Component' 

,xml_data.value('(event/data[@name=''data'']/value)[1]','varchar(max)')AS'Data' 

,xml_data.value('(event/data[@name=''info'']/value)[1]','varchar(max)')AS'Info'

,xml_data

INTO #ServerStats 

FROM 

 (SELECTobject_nameAS'event' 

  ,CONVERT(xml,event_data)AS'xml_data' 

 FROM sys.fn_xe_file_target_read_file('C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\SQLNODE1_MSSQLSERVER_SQLDIAG_0_129936003752530000.xel',NULL,NULL,NULL)  

)  

AS XEventData; 

BUT I NEED TO DRILL DOWN INSIDE THE EVENTS COMPONENTS AND READ THE DATA NODES VALUES FROM XML

--LOOKING AT THE xml_data which does not get parsed properly

select*from #ServerStatswhere component ='events'ORDER BYTime;

Question: is there a hyperlink or blog that I can use for XQuery Cluster Diagnostic files for events? Also from where I can get the schema?

Thank you,


Transaction getting failed due to databases is going frequently in recovering state

$
0
0

Hi,

We are using SQL Server Enterprise Evaluation 2016 (13.0.1601.5). Databases is going frequently in recovering state for 30-40 sec and coming back Online. 

Due to this transactions are getting failed and application facing connection timeout issue. Requesting you to please assist for the same.

Database Recovery Model is SIMPLE.

Regards,

Nikhil P Desai



SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.)

$
0
0
Hello Experts,

        We have SQL Server 2012 on Windows server 2012 Failover cluster(VM).  Few days back we have installed Anti virus on Cluster nodes and got the error SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.) Later we removed antivirus on both nodes. After couple of days again we started getting the same error and sql services are goes to stopped state. And if i perform failover then sql services are starting . Then after couple of hours later again it went to stopped state with the same error. This happened quite frequently in Node2 but on Node 1 it is happening very rarely.  Both nodes has different service packs and Windows CU.

Initially we thought it could be AV and now we completely removed still we are facing the same issue. 

Please help me to solve this nightmare issue.  



system error log

1:20:30 am

BackupIoRequest::ReportIoError: write failure on backup device 'G:\Backup\Dif_bkp\SCMDB_backup_2019_08_14_010128_7899718.bak'. Operating system error 170(The requested resource is in use.).

1:20:30 am

SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.) encountered.

1:20:30 am 

The log for database 'msdb' is not available. Check the event log for related error messages. Resolve any errors and restart the database.

1:20:30 am 

The system failed to flush data to the transaction log. Corruption may occur in VolumeId: G:, DeviceName: \Device\HarddiskVolume5.
({Device Busy}
The device is currently busy.)

1:20:31 am 

The system failed to flush data to the transaction log. Corruption may occur in VolumeId: H:, DeviceName: \Device\HarddiskVolume3.
({Device Busy}
The device is currently busy.)

SQL Server Errorlog- 

Date,Source,Severity,Message
08/14/2019 07:21:10,spid6s,Unknown,SQL Server shutdown has been initiated
08/14/2019 07:21:10,spid6s,Unknown,Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup<c/> repair it<c/> or rebuild it. For more information about how to rebuild the master database<c/> see SQL Server Books Online.
08/14/2019 07:21:10,spid6s,Unknown,Operating system error 170(The requested resource is in use.) on file "H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf" during FixupLogTail.
08/14/2019 07:21:10,spid6s,Unknown,Error: 5159<c/> Severity: 24<c/> State: 13.
08/14/2019 07:21:10,spid6s,Unknown,SQLServerLogMgr::FixupLogTail: Operating system error 170(The requested resource is in use.) encountered.
08/14/2019 07:21:10,spid6s,Unknown,Error: 17053<c/> Severity: 16<c/> State: 1.
08/14/2019 07:21:10,spid6s,Unknown,fcb status 0x42<c/> handle 0x00000000000007A8<c/> size 224 pages
08/14/2019 07:21:10,spid6s,Unknown,blankSize 0x3c0000<c/> blkOffset 0x11a<c/> fileSeqNo 884<c/> totBytesWritten 0x0
08/14/2019 07:21:10,spid6s,Unknown,SQLServerLogMgr::FixupLogTail (failure): alignBuf 0x000000001163E000<c/> writeSize 0xc00<c/> filePos 0x63400
08/14/2019 07:21:10,spid6s,Unknown,374 transactions rolled forward in database 'master' (1:0). This is an informational message only. No user action is required.
08/14/2019 07:21:10,spid6s,Unknown,Starting up database 'master'.
08/14/2019 07:21:10,Server,Unknown,Software Usage Metrics is disabled.
08/14/2019 07:21:10,Server,Unknown,CLR version v4.0.30319 loaded.
08/14/2019 07:21:10,Server,Unknown,Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
08/14/2019 07:21:10,Server,Unknown,Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
08/14/2019 07:21:10,Server,Unknown,Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
08/14/2019 07:21:10,Server,Unknown,This instance of SQL Server last reported using a process ID of 11160 at 8/14/2019 7:21:08 AM (local) 8/14/2019 3:21:08 AM (UTC). This is an informational message only; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Using conventional memory in the memory manager.
08/14/2019 07:21:09,Server,Unknown,Detected 49151 MB of RAM. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
08/14/2019 07:21:09,Server,Unknown,SQL Server detected 1 sockets with 4 cores per socket and 4 logical processors per socket<c/> 4 total logical processors; using 4 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Command Line Startup Parameters:<nl/>-s "MSSQLSERVER"
08/14/2019 07:21:09,Server,Unknown,Registry startup parameters: <nl/>-d H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\master.mdf<nl/>-e H:\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG<nl/>-l H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
08/14/2019 07:21:09,Server,Unknown,The service account is 'account\sqlservice'. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Logging SQL Server messages in file 'H:\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG'.
08/14/2019 07:21:09,Server,Unknown,Authentication mode is MIXED.
08/14/2019 07:21:09,Server,Unknown,System Manufacturer: 'VMware<c/> Inc.'<c/> System Model: 'VMware Virtual Platform'.
08/14/2019 07:21:09,Server,Unknown,Server process ID is 5280.
08/14/2019 07:21:09,Server,Unknown,All rights reserved.
08/14/2019 07:21:09,Server,Unknown,(c) Microsoft Corporation.
08/14/2019 07:21:09,Server,Unknown,Microsoft SQL Server 2012 (SP4) (KB4018073) - 11.0.7001.0 (X64) <nl/>Aug 15 2017 10:23:29 <nl/>Copyright (c) Microsoft Corporation<nl/>Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)



Thank you

Sai Nadh

looking for a technique to make date range joins perform better

$
0
0

Hi we run 2017 standard.  I've come across this challenge in the past but never solicited help on the matter.

Often, I come across situations where individual records in table A match only a SINGLE record in table B based on
a datetime range in table B that covers a single datetime column from table A.  And indices dont seem capable of making
the match as efficient as other business scenarios where a datetime range isnt involved.

What do i mean? Lets say table A is the incident table (see index also) shown in the code block and it has 30.5 million
records that are newer (start datetime) than 2 years ago.  and about 27 million older than 2 years ago. 

And table B is the job table (see index also, notice no physical pk defined) shown in the code block and it has 3.3 million
records of which about 1.7 million jobs get a match as explained below.  I should mention that presently endtime is null on jobs that arent finished yet.

It would be great if the following query would run much faster than 8-10 minutes.  I suspect if the match criteria
involved only 1 or 2 column equivalents, it would.  But date ranges seem to perform poorly.  I verified that the indexes
shown in the code block are being used in the execution plan.   And that the execution plans seems to be doing an index scan rather than seek which at these volumes kind of makes sense to me.  Now that I look at the NC on the jobs table, I have to admit that I don't know what we were thinking.

select count(*) from
(

SELECT
       inc.pk,
       inc.StartTime,
       inc.EndTime,
       inc.machine

FROM dbo.incidents inc (NOLOCK)
JOIN dbo.jobs job (NOLOCK) ON inc.machine = job.machine  
                          AND inc.StartTime >= job.StartTime
                          AND (inc.StartTime < job.EndTime OR job.EndTime IS NULL)
                          AND job.building = inc.building
                          AND (job.EndTime >= DATEADD(MONTH, -24, GETDATE()) OR job.EndTime IS NULL)

WHERE
inc.StartTime >= DATEADD(MONTH,-24,GETDATE())
) x

USE [mydatabase]


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[incident](
	
	[Id01] [int] NULL,
	[EndTime] [datetime] NULL,
	[Id02] [int] NULL,
	[machine] [int] NULL,
	[Id03] [int] NULL,
	[Id04] [int] NULL,
	[Id05] [int] NULL,
	[Id06] [int] NULL,
	[Id07] [int] NULL,
	[StartTime] [datetime] NULL,
	[pk] [int] NOT NULL,
	[Id08] [int] NULL,
	[building] [varchar](25) NOT NULL,
	
 CONSTRAINT [PK_incident] PRIMARY KEY CLUSTERED 
(
	[pk] ASC,
	[building] 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

USE [mydatabase]
GO

CREATE NONCLUSTERED INDEX [IDX_Incident_NCI02] ON [dbo].[Incident]
(
	[StartTime] ASC
)
INCLUDE ( 	[id01],
	[End_Time],
	
	[machine],
	[id02],
	[id03],
	[id04],
	[id05],
	[id06],
	[id07]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



USE [mydatabase]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[jobs](
	[Id01] [int] NULL,
	[EndTime] [datetime] NULL,
	[Id02] [int] NULL,
	[machine] [int] NULL,
	[jobId] [int] NOT NULL,--<-------------------this and building are unique
	[StartTime] [datetime] NULL,
	[building] [varchar](25) NOT NULL,
) ON [PRIMARY]
GO

USE [mydatabase]
GO

SET ANSI_PADDING ON
GO

CREATE NONCLUSTERED INDEX [IDX_Jobs_NCI02] ON [dbo].[Jobs]
(
	[StartTime] ASC,
	[EndTime] ASC,
	[machine] ASC,
	[building] ASC
)
INCLUDE ( 	[id02]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO


Different Execution plan and performance issues in SQL 2017 compare to SQL 2012

$
0
0

Hello All,

We have recently migrated SQL2012 express edition to SQL 2017 express edition and observed some of queries having performance issues in SQL 2017.

We have compared execution plan and found that both versions generate different execution plan. As Microsoft claim SQL 2017 is faster than earlier version of SQL server but we get reverse result.

Right now, we have used “LEGACY_CARDINALITY_ESTIMATION” hints and applied temporary solution.

Anyone has idea :-

How can we apply permanent solution?

How can we proof SQL 2017 is faster compare to SQL 2012?


Viewing all 15911 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>