473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

SQL 2000 dies on JOIN query

Hello all.

I have quite disturbing situation where I am not happy about the way how SQL
handles the query. Situation is related to using user function in INNER JOIN
select. Although the problem occured in more complex situation the query can
be simplified to following example with same results:

There is an user function, that can be as simple as:

FUNCTION IsItSo (@text1 nvarchar(255), @text2 nvarchar(255))
RETURNS integer

BEGIN

if isnull(@text1,'')=isnull(@text2,'')
return 1
else
return 0

return 0
END

It can be any function returning integer, this is just for example.
Then there is a query as simple as that:
SELECT person, formula FROM
(
SELECT
a.person, v.code AS formula
FROM rows1 AS a
INNER JOIN rows2 AS v ON a.type=v.type
AND dbo.IsItSo(a.type,v.type)=1
)
as formulas
tables rows1 and rows2 can contain as little as two columns for this
example - rows1 have [person] and [type], rows2 [code] and [type]. All
columns are of nvarchar type.

So the AND clause after INNER JOIN is an obvious mistake. That is not the
problem, problem is how SQL reacts. On SQL 2000 SP4 the result for running
the query is following error:
Server: Msg 913, Level 16, State 8, Line 1
Could not find database ID 101. Database may not be activated yet or may be
in transition.

On SQL 2000 SP3 the result is even more dramatic - SQL service will consume
100% of all available processors and become unresponsive. Only solution is
to restart either SQL service or the server.


My question is if this self-destructive behavior of SQL server can be
prevented by some configuration parameters or patches. I am a bit annoyed by
the fact that developer can kill the server by little bit of poor
programming that is syntactically acceptable for server.
One more curious bit - the section of the query located between parenthesis
can be run separately without any ill effects and get actual meaningful
results:
SELECT
a.person, v.code AS formula
FROM rows1 AS a
INNER JOIN rows2 v ON a.type=v.type
AND dbo.IsItSo(a.type,v.type)=1

Aug 22 '06 #1
3 4124
Martini,

why do you want to do things like this? UDFs in WHERE clause are
usually performance killers. Isn't it simpler and faster to do just as
follows:

SELECT
a.person, v.code AS formula
FROM rows1 AS a
INNER JOIN rows2 v ON a.type=v.type
AND isnull(a.col1,'')=isnull(v.col2,'')

Aug 22 '06 #2
Martini (ma*****@online.ee) writes:
I have quite disturbing situation where I am not happy about the way how
SQL handles the query. Situation is related to using user function in
INNER JOIN select. Although the problem occured in more complex
situation the query can be simplified to following example with same
results:
...
So the AND clause after INNER JOIN is an obvious mistake. That is not the
problem, problem is how SQL reacts. On SQL 2000 SP4 the result for running
the query is following error:
Server: Msg 913, Level 16, State 8, Line 1
Could not find database ID 101. Database may not be activated yet or may
be in transition.

On SQL 2000 SP3 the result is even more dramatic - SQL service will
consume 100% of all available processors and become unresponsive. Only
solution is to restart either SQL service or the server.

My question is if this self-destructive behavior of SQL server can be
prevented by some configuration parameters or patches. I am a bit
annoyed by the fact that developer can kill the server by little bit of
poor programming that is syntactically acceptable for server.
Obviously this is a bug, but without a complete script that demonstrates
the problem, it's difficult to suggest workarounds. (Except as Alexander
says, avoid the UDF altogether.) It would also be interesting to see
if the problem appears on SQL 2005.

I did try to compose a repro from your post, but my query did not fail.

A complete repro script must either create tables itself, or refer
to known tables, such as system tables or tables in Northwind or pubs.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 22 '06 #3
Martini,

You appear to be encountering this known bug:

http://support.microsoft.com/default...b;en-us;819264

Steve Kass
Drew University

Martini wrote:
Hello all.

I have quite disturbing situation where I am not happy about the way how SQL
handles the query. Situation is related to using user function in INNER JOIN
select. Although the problem occured in more complex situation the query can
be simplified to following example with same results:

There is an user function, that can be as simple as:

FUNCTION IsItSo (@text1 nvarchar(255), @text2 nvarchar(255))
RETURNS integer

BEGIN

if isnull(@text1,'')=isnull(@text2,'')
return 1
else
return 0

return 0
END

It can be any function returning integer, this is just for example.
Then there is a query as simple as that:
SELECT person, formula FROM
(
SELECT
a.person, v.code AS formula
FROM rows1 AS a
INNER JOIN rows2 AS v ON a.type=v.type
AND dbo.IsItSo(a.type,v.type)=1
)
as formulas
tables rows1 and rows2 can contain as little as two columns for this
example - rows1 have [person] and [type], rows2 [code] and [type]. All
columns are of nvarchar type.

So the AND clause after INNER JOIN is an obvious mistake. That is not the
problem, problem is how SQL reacts. On SQL 2000 SP4 the result for running
the query is following error:
Server: Msg 913, Level 16, State 8, Line 1
Could not find database ID 101. Database may not be activated yet or may be
in transition.

On SQL 2000 SP3 the result is even more dramatic - SQL service will consume
100% of all available processors and become unresponsive. Only solution is
to restart either SQL service or the server.


My question is if this self-destructive behavior of SQL server can be
prevented by some configuration parameters or patches. I am a bit annoyed by
the fact that developer can kill the server by little bit of poor
programming that is syntactically acceptable for server.
One more curious bit - the section of the query located between parenthesis
can be run separately without any ill effects and get actual meaningful
results:
SELECT
a.person, v.code AS formula
FROM rows1 AS a
INNER JOIN rows2 v ON a.type=v.type
AND dbo.IsItSo(a.type,v.type)=1


Aug 23 '06 #4

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

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
3
by: Dan Berlin | last post by:
I have two tables: T1 : Key as bigint, Data as char(20) - size: 61M records T2 : Key as bigint, Data as char(20) - size: 5M records T2 is the smaller, with 5 million records. They both have...
9
by: wiredog | last post by:
I am struggling rewriting my query from MS Access' IIF, Then to SQL Servers TSQL language. I am hoping some one can give me some guidance. I believe I have the first portion of the query correct...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
0
by: pj | last post by:
/* Make two tables, then find that a left join between them works, unless you add a view on top of one table -- if you add a view and use it, the left join fails -- rather, it acts as an inner join...
1
by: Stefan V. | last post by:
Hello! I am trying to convert a query written for SQL Server 2000 database tables, to a MS Access query. Here is what I have in SQL Server: SELECT t2.*, CASE WHEN t2.QType = '3' THEN...
1
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table ...
2
by: ILCSP | last post by:
Hello, I'm in the process of changing our 'normal' Access 2000 update queries to Update Pass Through Queries. We have a SQL server 2000 database and we're using an Access 2000 database as our...
15
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.