473,804 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sql query timeout, expensive cast operation?

Ted
I need some tips to boost the performance on the following query.
The problem is that it times out once in a while, and then again runs
normally in most cases.
The clue is to compare a textual value stored as an image data type, but I
don't know if the cast operation could be done in another way.
Any tips?

SELECT DISTINCT pk_product FROM tbl_product P
JOIN tbl_product_con tent PC ON P.pk_product = PC.fk_product
JOIN tbl_content C ON PC.fk_content = C.pk_content
JOIN tbl_content_rel REL ON C.pk_content = REL.fk_content
JOIN tbl_filegroup FG ON REL.fk_filegrou p = FG.pk_filegroup
JOIN tbl_filegroup_f ile FF ON fg.pk_filegroup = FF.fk_filegroup
JOIN tbl_file F ON ff.fk_file = F.pk_file
WHERE
P.fk_product_ty pe = 45 AND
CAST(CAST(f.dat a AS VARBINARY) AS NVARCHAR(20)) = '1234'
/ted
Jul 23 '05 #1
1 2616
Ted (te*@organizer. net) writes:
I need some tips to boost the performance on the following query.
The problem is that it times out once in a while, and then again runs
normally in most cases.
The clue is to compare a textual value stored as an image data type, but I
don't know if the cast operation could be done in another way.
Any tips?

SELECT DISTINCT pk_product FROM tbl_product P
JOIN tbl_product_con tent PC ON P.pk_product = PC.fk_product
JOIN tbl_content C ON PC.fk_content = C.pk_content
JOIN tbl_content_rel REL ON C.pk_content = REL.fk_content
JOIN tbl_filegroup FG ON REL.fk_filegrou p = FG.pk_filegroup
JOIN tbl_filegroup_f ile FF ON fg.pk_filegroup = FF.fk_filegroup
JOIN tbl_file F ON ff.fk_file = F.pk_file
WHERE
P.fk_product_ty pe = 45 AND
CAST(CAST(f.dat a AS VARBINARY) AS NVARCHAR(20)) = '1234'


Since you only retrive one column, it's better to use EXISTS:

SELECT P.pk_product
FROM tbl_product P
WHERE P.fk_product_ty pe = 45
AND EXISTS
(SELECT tbl_product_con tent PC
JOIN tbl_content C ON PC.fk_content = C.pk_content
JOIN tbl_content_rel REL ON C.pk_content = REL.fk_content
JOIN tbl_filegroup FG ON REL.fk_filegrou p = FG.pk_filegroup
JOIN tbl_filegroup_f ile FF ON fg.pk_filegroup = FF.fk_filegroup
JOIN tbl_file F ON ff.fk_file = F.pk_file
WHERE P.pk_product = PC.fk_product
AND CAST(CAST(f.dat a AS VARBINARY) AS NVARCHAR(20)) = '1234')

That will save you the sorting operation for the DISTINCT.

Whether the convert operation is the culprit, I don't know, but
I would not really expect so. The timeouts could be due to that
under some circumstances, the optimzer finds a less good plan.
But the reason could also be blocking. Since the timeouts occur
only intermittently, my bets go for blocking.

Then again, the query you posted appears to be a styled version of the
real McCoy. If I were to see the actual code, I might change my bets.

In any case, it's a good idea to examing the query plan for the query.
You can do this from Query Analyzer.


--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9794
by: Philip Yale | last post by:
A colleague of mine has a query which fails to run under SQLAgent batch with the following error: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. (Error 242) The statement has been terminated. (Error 3621). The step failed. He can run the same query sucessfully via query analyzer (i.e. no errors, and it does what he wants)
3
6118
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection Timed out) I am using the Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000. In there first question there can be up to 27 answers. So I figured instead of making 27 different trips to the database I woulc just concatenate my...
4
9183
by: Saradhi | last post by:
Is there any way to estimate the time required to execute a T-SQL statement? I need to set the command time out by calculating the time for T-SQL statement. Can any one give an example?
5
13278
by: Jason | last post by:
Hi all I get the following error when executing a rather intense stored procedure from an ASPX page. I have tried: - Increasing timeouts on IIS 5.0 (all areas that even mention timeout) - use the "Connection Timeout=2400" string in the SqlConnection connections string - disabled connection pooling.
2
4597
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET Here's the scenario: 1. .NET Windows Client on a remote machine makes a web service call to update tables on a Web Server running SQL Server 2000. 2. The Update is updating about 1000 - 3000 records doing simple update statements like "Update...
3
13999
by: Nils Magnus Englund | last post by:
Hi, I've made a HttpModule which deals with user authentication. On the first request in a users session, it fetches data from a SQL Server using the following code: using (SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings)) {
4
13199
by: VB Programmer | last post by:
When I run my ASP.NET 2.0 web app on my dev machine it works perfect. When I precomile it to my web deployment project and then copy the debug files to my web server I get this problem when trying to login (obviously it's using ASPNETDB.mdf). Any ideas? Server Error in '/' Application. --------------------------------------------------------------------------------
1
4746
by: Steve | last post by:
I have a bit of "login authentication" code that in the event of a server error, connection error, etc will take a Looooooong time to timeout. I wanted to redesign it to call the DAL method in a separate thread (easy enough) w/ a callback for when it's done. The area I'm having trouble with is once I determine the timeout period has elapsed, how do I kill the thread safely? I asked a threading question here awhile ago and some kind...
3
3154
by: Chris McFarling | last post by:
What's the most efficient method to export the result set of a SQL query to a text file using ASP.NET? There could potentially be a few thousand rows.
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.