Showing posts with label explain. Show all posts
Showing posts with label explain. Show all posts

Wednesday, March 21, 2012

fuzzy lookup

Hi Friends,

Can some body briefly explain me what is the difference between fuzzy lookup and fuzzy grouping?

thanks and regards

Ruther wrote:

Hi Friends,

Can some body briefly explain me what is the difference between fuzzy lookup and fuzzy grouping?

thanks and regards

One is a lookup, the other is a group by? The fuzzy grouping is good for finding duplicates while the lookup is good for finding matches.|||

If the fuzzy lookup is analogous to the regular LOOKUP component in SSIS then Fuxxy Grouping is most analogous to the AGGREGATE component.

Under the covers the Fuzzy Grouping does the same as the Fuzzy Lookup, it then groups the data according to the looked up value (I think).

BOL will have all the answers.

-Jamie

sql

Monday, March 19, 2012

Funny error during runs

Can any one please help explain why this error has happened, it is not a normal error of SSIS,

"SSIS Debug host has encountered a problem and needs to close. We are sorry for the inconvenience"

It has 2 buttons Debug and Close, this error happened in the middle of a script task.

This is a classic Microsoft problem. I face this problem often.

These are the scenarios on which I usually get this probelm:

1. If there is less memory on the client system where VB studio is open, and trying lot of mouse clicks frequently.

2. It is observed more when in Debug mode, when you try to scroll using the middle wheel of the mouse.

After I upgraded my desktop RAM to 3GB, and often system restart at the start of the day, I observed this error is less.

Also always saving and building frequently of the packages will help to retain your work. Other than these, there is no real solution from what I observed.

Friday, March 9, 2012

function problem, referring to another function

I'm trying to create a couple of functions and am running into a problem
that I cannot explain. This uses Northwind database.
First of all, this one works:
---
ALTER FUNCTION fnCustomers
(
@.Initial VARCHAR(1)
)
RETURNS @.Cust TABLE
(
CustomerID VARCHAR(100)
)
AS
BEGIN
INSERT @.Cust
SELECT CustomerID from Customers where CustomerID LIKE '%' + @.INITIAL +
'%'
RETURN
END
---
and I can execute this:
SELECT * from dbo.fnCustomers('A')
and get results. Cool.
Now I want to extend this with another function that counts the results from
the first function:
---
ALTER FUNCTION fnCustomersCount
(
@.Initial VARCHAR(1)
)
RETURNS VARCHAR(10)
AS
BEGIN
DECLARE @.CustCount INT
SELECT @.CustCount = CustomerID
FROM fnCustomers(@.Initial)
GROUP BY CustomerID
RETURN @.CustCount
END
---
But thatdoesn't seem to work.
Select * from fnCustomersCount ('A')
gives me an error: Invalid object name 'fnCustomersCount'.
what am I doing wrong?Hello, mrmagoo
When invoking scalar UDF-s, you must use the UDF in an expression (not
in the FROM clause) and you must specify the object owner, like this:
SELECT dbo.fnCustomersCount ('A')
And by the way, why does your function return a varchar(10) instead of
an int ?
Razvan|||Try dbo.fnCustomersCount
Regards
Roji. P. Thomas
http://toponewithties.blogspot.com
"mrmagoo" <-> wrote in message
news:eHB%23no%23SGHA.4900@.TK2MSFTNGP09.phx.gbl...
> I'm trying to create a couple of functions and am running into a problem
> that I cannot explain. This uses Northwind database.
> First of all, this one works:
> ---
> ALTER FUNCTION fnCustomers
> (
> @.Initial VARCHAR(1)
> )
> RETURNS @.Cust TABLE
> (
> CustomerID VARCHAR(100)
> )
> AS
> BEGIN
> INSERT @.Cust
> SELECT CustomerID from Customers where CustomerID LIKE '%' + @.INITIAL +
> '%'
> RETURN
> END
> ---
> and I can execute this:
> SELECT * from dbo.fnCustomers('A')
> and get results. Cool.
> Now I want to extend this with another function that counts the results
> from
> the first function:
> ---
> ALTER FUNCTION fnCustomersCount
> (
> @.Initial VARCHAR(1)
> )
> RETURNS VARCHAR(10)
> AS
> BEGIN
> DECLARE @.CustCount INT
> SELECT @.CustCount = CustomerID
> FROM fnCustomers(@.Initial)
> GROUP BY CustomerID
> RETURN @.CustCount
> END
> ---
> But thatdoesn't seem to work.
> Select * from fnCustomersCount ('A')
> gives me an error: Invalid object name 'fnCustomersCount'.
> what am I doing wrong?
>
>|||Thanks.
You're right. Originally it was returning an INT. I played around with it
and forgot to change it back.
Appreciate your help!
"Razvan Socol" <rsocol@.gmail.com> wrote in message
news:1142837800.513726.290670@.i39g2000cwa.googlegroups.com...
> Hello, mrmagoo
> When invoking scalar UDF-s, you must use the UDF in an expression (not
> in the FROM clause) and you must specify the object owner, like this:
> SELECT dbo.fnCustomersCount ('A')
> And by the way, why does your function return a varchar(10) instead of
> an int ?
> Razvan
>|||Hi
I don't think you need the second UDF. I think you would like to count the
customers , am I right?
ALTER FUNCTION fnCustomers
(
@.Initial VARCHAR(1)
)
RETURNS @.Cust TABLE
(
CustomerID VARCHAR(100)
)
AS
BEGIN
INSERT @.Cust
SELECT CustomerID from Customers where CustomerID LIKE @.INITIAL +'%'
RETURN
END
SELECT COUNT(*) FROM dbo.fnCustomers('A%')
"mrmagoo" <-> wrote in message
news:OM0BMx%23SGHA.4608@.tk2msftngp13.phx.gbl...
> Thanks.
> You're right. Originally it was returning an INT. I played around with it
> and forgot to change it back.
> Appreciate your help!
>
> "Razvan Socol" <rsocol@.gmail.com> wrote in message
> news:1142837800.513726.290670@.i39g2000cwa.googlegroups.com...
>

function performance question

can anyone explain to me why the code excerpt 1 performs 60 reads on my DB, and code excerpt 2 performs 140000 ?

I know that specifically the statements are doing different things but they are both inserting into tables based on input parameters.

All relevant fields are indexed so I wouldn't have thought this was the issue?

Does the number of joins really make such a difference to performance?

code excerpt 1 (60 reads)
INSERT INTO @.table_var
SELECT dbo.Organisation.OrganisationName,
dbo.Organisation.DepartmentName,
dbo.Address.BuildingNumber,
dbo.BuildingName.BuildingName,
dbo.SubBuildingName.SubBuildingName,
Thoroughfare_1.ThoroughfareName AS DependentThoroughfareName,
ThoroughfareDescriptor_1.ThoroughfareDescriptor AS DependentThoroughfareDescriptor,
dbo.Thoroughfare.ThoroughfareName,
dbo.ThoroughfareDescriptor.ThoroughfareDescriptor,
dbo.Locality.DoubleDependentLocality,
dbo.Locality.DependentLocality,
dbo.Locality.PostTown,
dbo.Address.Outcode,
dbo.Address.Incode,
dbo.Address.ConcatenationIndicator
FROM dbo.Address INNER JOIN
dbo.BuildingName ON dbo.Address.BuildingNameKey = dbo.BuildingName.BuildingNameKey INNER JOIN
dbo.Locality ON dbo.Address.LocalityKey = dbo.Locality.LocalityKey INNER JOIN
dbo.Organisation ON dbo.Address.OrganisationKey = dbo.Organisation.OrganisationKey AND
dbo.Address.PostcodeType = dbo.Organisation.PostcodeType INNER JOIN
dbo.SubBuildingName ON dbo.Address.SubBuildingNameKey = dbo.SubBuildingName.SubBuildingNameKey INNER JOIN
dbo.Thoroughfare ON dbo.Address.ThoroughfareKey = dbo.Thoroughfare.ThoroughfareKey INNER JOIN
dbo.ThoroughfareDescriptor ON dbo.Address.ThoroughfareDescriptorKey = dbo.ThoroughfareDescriptor.ThoroughfareDescriptorK ey INNER JOIN
dbo.Thoroughfare Thoroughfare_1 ON dbo.Address.DependentThoroughfareKey = Thoroughfare_1.ThoroughfareKey INNER JOIN
dbo.ThoroughfareDescriptor ThoroughfareDescriptor_1 ON
dbo.Address.DependentThoroughfareDescriptorKey = ThoroughfareDescriptor_1.ThoroughfareDescriptorKey
WHERE (dbo.Address.AddressKey = @.addresskey) AND
(dbo.Address.OrganisationKey = @.organisationkey) AND
(dbo.Address.PostcodeType = @.postcodetype)

code excerpt 2:

INSERT INTO @.table_var_out
SELECT dbo.Organisation.OrganisationName, dbo.Address.OrganisationKey, dbo.Address.AddressKey, dbo.Address.PostcodeType
FROM dbo.Address INNER JOIN
dbo.Organisation ON dbo.Address.OrganisationKey = dbo.Organisation.OrganisationKey AND
dbo.Address.PostcodeType = dbo.Organisation.PostcodeType
WHERE (dbo.Address.Outcode = @.outcode) AND (dbo.Address.Incode = @.incode)Not all indexes are equal. Have you looked at the query plans for the select statements?

Function like Informix DB's Set Explain

Hi,
In SQL Server is any function like Informix DB's Set Explain?
It's mean that during execute SQL syntax and I can know the SQL syntax use
what's kind of Index or not.
So, what's name of this function in SQL Server? And how to run it? Any
document can reference?
Thanks for help!
Angiangi
I think what you need is to look at Show Execution Plan option in the Query
menu on QA.
"angi" <enchiw@.sanrong.com.tw> wrote in message
news:uK5sjN71EHA.1192@.tk2msftngp13.phx.gbl...
> Hi,
> In SQL Server is any function like Informix DB's Set Explain?
> It's mean that during execute SQL syntax and I can know the SQL syntax use
> what's kind of Index or not.
> So, what's name of this function in SQL Server? And how to run it? Any
> document can reference?
> Thanks for help!
> Angi
>|||"angi" <enchiw@.sanrong.com.tw> wrote in message
news:uK5sjN71EHA.1192@.tk2msftngp13.phx.gbl...
> Hi,
> In SQL Server is any function like Informix DB's Set Explain?
> It's mean that during execute SQL syntax and I can know the SQL syntax use
> what's kind of Index or not.
> So, what's name of this function in SQL Server? And how to run it? Any
> document can reference?
> Thanks for help!
> Angi
>
Use the Showplan icon in the Query Analyzer.
A text based option is to run the SET SHOWPLAN ON statement.
Take a look in Books Online for SHOWPLAN option for analyzing query plans.
HTH
Rick Sawtell
MCT, MCSD, MCDBA|||Thanks Uri Dimant and Rick Sawtell.
Thank you so much!
Angi

Function like Informix DB's Set Explain

Hi,
In SQL Server is any function like Informix DB's Set Explain?
It's mean that during execute SQL syntax and I can know the SQL syntax use
what's kind of Index or not.
So, what's name of this function in SQL Server? And how to run it? Any
document can reference?
Thanks for help!
Angiangi
I think what you need is to look at Show Execution Plan option in the Query
menu on QA.
"angi" <enchiw@.sanrong.com.tw> wrote in message
news:uK5sjN71EHA.1192@.tk2msftngp13.phx.gbl...
> Hi,
> In SQL Server is any function like Informix DB's Set Explain?
> It's mean that during execute SQL syntax and I can know the SQL syntax use
> what's kind of Index or not.
> So, what's name of this function in SQL Server? And how to run it? Any
> document can reference?
> Thanks for help!
> Angi
>|||"angi" <enchiw@.sanrong.com.tw> wrote in message
news:uK5sjN71EHA.1192@.tk2msftngp13.phx.gbl...
> Hi,
> In SQL Server is any function like Informix DB's Set Explain?
> It's mean that during execute SQL syntax and I can know the SQL syntax use
> what's kind of Index or not.
> So, what's name of this function in SQL Server? And how to run it? Any
> document can reference?
> Thanks for help!
> Angi
>
Use the Showplan icon in the Query Analyzer.
A text based option is to run the SET SHOWPLAN ON statement.
Take a look in Books Online for SHOWPLAN option for analyzing query plans.
HTH
Rick Sawtell
MCT, MCSD, MCDBA|||Thanks Uri Dimant and Rick Sawtell.
Thank you so much!
Angi

Function like Informix DB's Set Explain

Hi,
In SQL Server is any function like Informix DB's Set Explain?
It's mean that during execute SQL syntax and I can know the SQL syntax use
what's kind of Index or not.
So, what's name of this function in SQL Server? And how to run it? Any
document can reference?
Thanks for help!
Angi
angi
I think what you need is to look at Show Execution Plan option in the Query
menu on QA.
"angi" <enchiw@.sanrong.com.tw> wrote in message
news:uK5sjN71EHA.1192@.tk2msftngp13.phx.gbl...
> Hi,
> In SQL Server is any function like Informix DB's Set Explain?
> It's mean that during execute SQL syntax and I can know the SQL syntax use
> what's kind of Index or not.
> So, what's name of this function in SQL Server? And how to run it? Any
> document can reference?
> Thanks for help!
> Angi
>
|||"angi" <enchiw@.sanrong.com.tw> wrote in message
news:uK5sjN71EHA.1192@.tk2msftngp13.phx.gbl...
> Hi,
> In SQL Server is any function like Informix DB's Set Explain?
> It's mean that during execute SQL syntax and I can know the SQL syntax use
> what's kind of Index or not.
> So, what's name of this function in SQL Server? And how to run it? Any
> document can reference?
> Thanks for help!
> Angi
>
Use the Showplan icon in the Query Analyzer.
A text based option is to run the SET SHOWPLAN ON statement.
Take a look in Books Online for SHOWPLAN option for analyzing query plans.
HTH
Rick Sawtell
MCT, MCSD, MCDBA
|||Thanks Uri Dimant and Rick Sawtell.
Thank you so much!
Angi

Sunday, February 26, 2012

Fun (trouble) with outer join

Okay, I'm having an issue with an outer join that is just confounding
me! Can somebody help explain. I started out with a large query that
was not returning all of the data that I wanted, so i paired it down to
this simple outer join:
SELECT E.EMP_RNG_CDE
FROM DATA_TABLE B LEFT OUTER JOIN
CODE_TABLE E ON E.EMP_RNG_CDE =B.EMP_RNG_CDE
WHERE B.POST_CDE = '60503'
AND B.SEG_CDE = '5'
There are 6 rows in the in "CODE_TABLE" .. while only 2 rows in
"DATA_TABLE" will match.. so I want all 6 out of the "CODE_TABLE" every
time (hence my OUTER JOIN...)
my results look like this however:
EMP_RNG_CDE
1
2
-- I only received the rows that matched from B.. not the outer rows
found in E!
HOWEVER now this drives me really crazy.. if re-work the query to join
my tables in the WHERE Clause and use the "*=" syntax for my left outer
join.. it works just right!
SELECT E.EMP_RNG_CDE
FROM DATA_TABLE B, LEFT OUTER JOIN
CODE_TABLE E
WHERE E.EMP_RNG_CDE *= B.EMP_RNG_CDE AND
B.POST_CDE = '60503'
AND B.SEG_CDE = '5'
Returns:
EMP_RNG_CDE
1
2
3
4
5
6
? Aren't those 2 queries the same? Just with different syntax for the
LEFT OUTER JOIN '
Can somebody help me with why those two are different? And how I can
get the results from the 2nd query with a "OUTER JOIN" syntax in my
FROM clause?
thansks!
jeffprizJeff,
Try switching the order of the tables in the join clause or try a RIGHT
JOIN.
HTH
Jerry
<jeffpriz@.yahoo.com> wrote in message
news:1128372693.433884.78940@.g14g2000cwa.googlegroups.com...
> Okay, I'm having an issue with an outer join that is just confounding
> me! Can somebody help explain. I started out with a large query that
> was not returning all of the data that I wanted, so i paired it down to
> this simple outer join:
> SELECT E.EMP_RNG_CDE
> FROM DATA_TABLE B LEFT OUTER JOIN
> CODE_TABLE E ON E.EMP_RNG_CDE =B.EMP_RNG_CDE
> WHERE B.POST_CDE = '60503'
> AND B.SEG_CDE = '5'
> There are 6 rows in the in "CODE_TABLE" .. while only 2 rows in
> "DATA_TABLE" will match.. so I want all 6 out of the "CODE_TABLE" every
> time (hence my OUTER JOIN...)
> my results look like this however:
> EMP_RNG_CDE
> 1
> 2
> -- I only received the rows that matched from B.. not the outer rows
> found in E!
> HOWEVER now this drives me really crazy.. if re-work the query to join
> my tables in the WHERE Clause and use the "*=" syntax for my left outer
> join.. it works just right!
> SELECT E.EMP_RNG_CDE
> FROM DATA_TABLE B, LEFT OUTER JOIN
> CODE_TABLE E
> WHERE E.EMP_RNG_CDE *= B.EMP_RNG_CDE AND
> B.POST_CDE = '60503'
> AND B.SEG_CDE = '5'
> Returns:
> EMP_RNG_CDE
> 1
> 2
> 3
> 4
> 5
> 6
> ? Aren't those 2 queries the same? Just with different syntax for the
> LEFT OUTER JOIN '
> Can somebody help me with why those two are different? And how I can
> get the results from the 2nd query with a "OUTER JOIN" syntax in my
> FROM clause?
> thansks!
> jeffpriz
>|||The preserved table is on the LEFT or the RIGHT side of the infixed
operator.
Here is how OUTER JOINs work in SQL-92. Assume you are given:
Table1 Table2
a b a c
====== ======
1 w 1 r
2 x 2 s
3 y 3 t
4 z
and the outer join expression:
Table1
LEFT OUTER JOIN
Table2
ON Table1.a = Table2.a <== join condition
AND Table2.c = 't'; <== single table condition
We call Table1 the "preserved table" and Table2 the "unpreserved table"
in the query. What I am going to give you is a little different, but
equivalent to the ANSI/ISO standards.
1) We build the CROSS JOIN of the two tables. Scan each row in the
result set.
2) If the predicate tests TRUE for that row, then you keep it. You also
remove all rows derived from it from the CROSS JOIN
3) If the predicate tests FALSE or UNKNOWN for that row, then keep the
columns from the preserved table, convert all the columns from the
unpreserved table to NULLs and remove the duplicates.
So let us execute this by hand:
Let @. = passed the first predicate
Let * = passed the second predicate
Table1 CROSS JOIN Table2
a b a c
=========================
1 w 1 r @.
1 w 2 s
1 w 3 t *
2 x 1 r
2 x 2 s @.
2 x 3 t *
3 y 1 r
3 y 2 s
3 y 3 t @.* <== the TRUE set
4 z 1 r
4 z 2 s
4 z 3 t *
Table1 LEFT OUTER JOIN Table2
a b a c
=========================
3 y 3 t <= only TRUE row
--
1 w NULL NULL Sets of duplicates
1 w NULL NULL
1 w NULL NULL
--
2 x NULL NULL
2 x NULL NULL
2 x NULL NULL
3 y NULL NULL <== derived from the TRUE set - Remove
3 y NULL NULL
--
4 z NULL NULL
4 z NULL NULL
4 z NULL NULL
the final results:
Table1 LEFT OUTER JOIN Table2
a b a c
=========================
1 w NULL NULL
2 x NULL NULL
3 y 3 t
4 z NULL NULL
The basic rule is that every row in the preserved table is represented
in the results in at least one result row.
There are limitations and very serious problems with the extended
equality version of an outer join used in some diseased mutant
products. Consider the two Chris Date tables
Suppliers SupParts
supno supno partno qty
========= ==============
S1 S1 P1 100
S2 S1 P2 250
S3 S2 P1 100
S2 P2 250
and let's do an extended equality outer join like this:
SELECT *
FROM Supplier, SupParts
WHERE Supplier.supno *= SupParts.supno
AND qty < 200;
If I do the outer first, I get:
Suppliers LOJ SupParts
supno supno partno qty
=======================
S1 S1 P1 100
S1 S1 P2 250
S2 S2 P1 100
S2 S2 P2 250
S3 NULL NULL NULL
Then I apply the (qty < 200) predicate and get
Suppliers LOJ SupParts
supno supno partno qty
===================
S1 S1 P1 100
S2 S2 P1 100
Doing it in the opposite order
Suppliers LOJ SupParts
supno supno partno qty
===================
S1 S1 P1 100
S2 S2 P1 100
S3 NULL NULL NULL
Sybase does it one way, Oracle does it the other and Centura (nee
Gupta) lets you pick which one -- the worst of both non-standard
worlds! In SQL-92, you have a choice and can force the order of
execution. Either do the predicates after the join ...
SELECT *
FROM Supplier
LEFT OUTER JOIN
SupParts
ON Supplier.supno = SupParts.supno
WHERE qty < 200;
.. or do it in the joining:
SELECT *
FROM Supplier
LEFT OUTER JOIN
SupParts
ON Supplier.supno = SupParts.supno
AND qty < 200;
Another problem is that you cannot show the same table as preserved and
unpreserved in the extended equality version, but it is easy in SQL-92.
For example to find the students who have taken Math 101 and might
have taken Math 102:
SELECT C1.student, C1.math, C2.math
FROM (SELECT * FROM Courses WHERE math = 101) AS C1
LEFT OUTER JOIN
(SELECT * FROM Courses WHERE math = 102) AS C2
ON C1.student = C2.student;|||The WHERE clause causes your outer join to "become" an inner join. Not
explicitly, but in effect. (Put as simply as possible.)
Change your where clause like this or - as Jerry suggests - use RIGHT outer
join:
WHERE (B.POST_CDE = '60503' or B.POST_CDE is null)
AND (B.SEG_CDE = '5' or B.SEG_CDE is null)
ML|||Thanks! That actually helped a good bit! (it took me 5 reads, but I got
there!) LOL
I see where it's going. And i got my simple query to work, and I was
able to go back to my full-blown query to get it to work too
correctly..
thanks