Showing posts with label slow. Show all posts
Showing posts with label slow. Show all posts

Wednesday, March 21, 2012

Many left joins and slow performance

I am combining several columns and tables and I am wondering if there is a way to improve performance, for instance can I write an implicit join version of the following code, rather than having these explicit joins?

objCmd = new OleDbCommand ("SELECT MAmunicipalities.*, MAcitytown.*, countiesalias1.countyname, countiesalias1.countylinktitle AS clink1, countiesalias2.countyname, countiesalias2.countylinktitle AS clink2, countiesalias3.countyname, countiesalias3.countylinktitle AS clink3 FROM (MAmunicipalities LEFT OUTER JOIN MAcitytown ON MAmunicipalities.citytown = MAcitytown.citytown) LEFT OUTER JOIN MAcounties AS countiesalias1 ON MAcitytown.county1 = countiesalias1.countyname LEFT OUTER JOIN MAcounties AS countiesalias2 ON MAcitytown.county2 = countiesalias2.countyname LEFT OUTER JOIN MAcounties AS countiesalias3 ON MAcitytown.county3 = countiesalias3.countyname WHERE MAmunicipalities.municipality='plymouth'", objConn);

Sadly, I have even more joins left to add as well as other columns to add to the SELECT statement and more aliases to add as well. Any thoughts would be greatly appreciated.

So far, this appears to be a five table JOIN. That in itself 'shouldn't be a preformance issue.

Judicious usage of TABLE aliases would make the code a bit more readible (and maintainable).

And it is widely considered a 'best practice' to specifically identify columns instead of using [ SELECT * ].

For Example:

Code Snippet

SELECT
m.*,
c.*,
c1.CountyName,
c1.CountyLinkTitle AS cLink1,
c2.CountyName,
c2.CountyLinkTitle AS cLink2,
c3.CountyName,
c3.CountyLinkTitle AS cLink3
FROM MaMunicipalities m
LEFT JOIN MaCityTown c
ON m.CityTown = c.CityTown
LEFT JOIN MaCounties c1
ON c.County1 = c1.CountyName
LEFT JOIN MaCounties c2
ON c.County2 = c2.CountyName
LEFT JOIN MaCounties c3
ON c.County3 = c3.CountyName
WHERE m.Municipality = 'plymouth'

Are there additional tables to JOIN, or is it additional JOINs to the same tables (like with MaCounties above)?

|||I have additional tables to join. Right now it is taking between 10 and 15 seconds for a page to load using the code that is posted. I have indexed columns within those tables which has helped somewhat but it is still taking way too long. I suspect that having varchars being joined instead of ints is also contributing to the problem. Would a stored procedure help?|||

A stored procedure may help some -but its doubtful that it would provide the kind of improvement you really need.

As you suspect, the major issue is most likely the varchar() fields used for the JOINs.

One of the most significant things that help with speed on JOINs is the 'width' of an index. An integer field is 4 bytes. A varchar() field is as many bytes as characters (nvarchar() is double that.) The 'wider' the index, the fewer entries on an index page, therefore the more pages that have to be 'crawled' through and read to find the data.

Ideally, your CityTown and CountyName values would be integer values (CityTownID and CountyNameID).

I suggest that you explore using the Database Tuning Advisor to get assistance in fine tuning the indexes.

Refer to Books Online, Topic: 'Database Engine Tuning Advisor'

Monday, February 20, 2012

Management Studio very slow to startup

I'm trying to troubleshoot a strange issue. Here are some specifics...

+ just set up a brand new 64bit server (Windows 2003 R2 64 bit O/S and SQL 2005 64 bit, Std Edition); SQL is the only thing running on this server.

+ installed this new server in our AD domain; set up custom domain-level accounts for the SQL Service, Agent, and Integrations Services service accounts, following the BOL help topics "Setting up Windows Service Accounts."

+ I use RDP (remote desktop) to connect to the SQL Server server machine just fine. Once I'm RDP'd into the SQL2005 box, I fire up SQL Mgmt Studio there... it takes well over a couple of minutes before it even finishes rendering the first screen to connect to any instances. Once it finally does come up, I can connect to the (local) db using Windows Auth or the sa account w/out any delay or issue.

+ on my own workstation (an XP Pro laptop), I can open up SQL Mgmt Studio, and it opens up quickly (well, as quickly as Mgmt Studio or Visual Studio probably can these days ... <g>) and also connect to that new SQL2005 box w/out issue.

I am completely baffled as to why it SQL Mgmt studio would take so long to open up on the very server SQL is running, much less a brand new 64 bit server! Any information on what it's trying to do might be helpful... It's almost like it's trying to authenticate or connect to something and timing out, although no errors are displayed and there's nothing in the event logs. It's odd to me though, as at that point (just opening up the application), it doesn't seem like it should be attempting anything like that.

-- Margo Noreen

One issue that can cause this problem is that if the server does not have access to the internet, then the .NET framework can't access the crl.microsoft.com website to verify that the digital signatures used to sign the binaries for managed applications are valid. Each certificate check has a 15 second timeout in the .NET runtime implementation. Depending on what features are installed, this can add up to a minute of start up time for Management Studio.

There are a couple workarounds:

1) Configure a proxy server to allow access to http://crl.microsoft.com from your server
2) Configure your firewall to return a failure status quickly when it blocks access to the http://crl.microsoft.com website
3) Disable checks for certificate revocation. You can do this using Internet Explorer by opening the Interet Options dialog, going to the Advanced Page, and then unchecking the "Check for publisher's certificate revocation" checkbox. There are fraudulently signed binaries in the wild that can make virus-infected applications look like they were published by Microsoft. Disabling this check should probably not be done on machines with internet access.

Hope this helps,
Steve

Management Studio Very slow to open

Hi,

I've had this problem with a VM and now on the Live box. I installed Windows Server 2003 SP1, then install SQL server 2005 and applied service pack 1.

As an administrator Management Studio takes approximately 2 seconds to open. However, if I log in to windows with any other local user account Manangement Studio takes approximately 1.5 minutes to open.

The whole interface is slow unless I use the administrator account to log into windows.

If anyone has a solution I would be very greatful as this is a new build for our production environment.

Thanks in advance.

Iain

Not sure if this will help, but if you have a look at internet explorer, on tools, internet options, advanced, security, check for publishers certificate revocation. I believe the default is enabled (ticked). On out NON-INTERNET facing DB machines, we have disabled that, and see a significant improvement in SSMS 'opening' time. I have heard that SSMS 'calls home' to check soemthing, and that by disabling this option, it no longer does this.

As I have it, the reason it can take so long is that on a non-internet facing machine, it waits for a timeout there.... true or not true ? I'm not sure, but I do know we are seeing a significant improvement

|||

https://blogs.msdn.com/euanga/archive/2006/07/11/662053.aspx

|||Thanks very much for post. I'm teaching it on XPsp2 machines and the timeout was about 10 mins. Very annoying and this fix sorted it straight away takes 1 second to open now. :)

Management Studio slow?

Hi,

I am testing SQL Server 2005 June CTP on 32-bit & 64-bit Intel servers and so far SQL Server Management Studio appears to be very slow and response times are very poor (compared to that SQL Server 2000 Enterprise Manager).

Are there others that have noticed this performance problem?

Thanks,
PKYes, still is in SP1|||I suggest upgrading to the RTM or even SP1 versions, the June CTP code is a year old at this point and there was a bunch of perf work done at the end of the release.

Management Studio slow?

Hi,

I am testing SQL Server 2005 June CTP on 32-bit & 64-bit Intel servers and so far SQL Server Management Studio appears to be very slow and response times are very poor (compared to that SQL Server 2000 Enterprise Manager).

Are there others that have noticed this performance problem?

Thanks,
PKYes, still is in SP1|||I suggest upgrading to the RTM or even SP1 versions, the June CTP code is a year old at this point and there was a bunch of perf work done at the end of the release.