Abdu_Allah
asked on
Why this simple SQL query takes too long time to be executed?!!
Hi, do someone know why the execution time time for the following SQL query takes more that 25 second?! By the way the two tables contains only 10 records.
I'm sure the reason is the Convert function but why? and how to accelerate this SQL statement?
I'm sure the reason is the Convert function but why? and how to accelerate this SQL statement?
SELECT 'US' + CONVERT(varchar,[user].user_id ) AS id,[user].Full_Name AS item FROM [user] UNION SELECT 'GR' + CONVERT(varchar,gr.group_id ) AS id,gr.Name AS item FROM [group] AS gr;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could someone try it on his own machine please? I want to make sure it's not from my own machine?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>tried it on my SQL 2005 Server : Runtime < 1 sec giving a resultset of 20 rows
So the problem is at my side! thank you.
>I wonder if problem is caused by both of table-names (user and group) being reserved keywords
I do not think so.
So the problem is at my side! thank you.
>I wonder if problem is caused by both of table-names (user and group) being reserved keywords
I do not think so.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The problem is unlikely to be caused by the table names. The first thing I asked him to do was run the query without using the convert function and everything ran okay.
Is there a concept of a database language and a client side language in SQL Query (my expertise is within Oracle). If so, is it possible that client side settings are different to the database settings, thereby causing the convert routine to do more work that it needs to?
Is there a concept of a database language and a client side language in SQL Query (my expertise is within Oracle). If so, is it possible that client side settings are different to the database settings, thereby causing the convert routine to do more work that it needs to?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I run this query in both SQL Server Management Studio and application and i takes the same time(more than 25 second).
>could you try to get the execution plan of the sql server ?
Sorry, what is execution plan of the sql server ?
>could you try to get the execution plan of the sql server ?
Sorry, what is execution plan of the sql server ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is what I got:
|--Sort(DISTINCT ORDER BY:([Union1007] ASC, [Union1008] ASC))
|--Concatenation
|--Compute Scalar(DEFINE:([Expr1003]= 'US'+CONVE RT(varchar (30),[Vist aFileExplo rer].[dbo] .[User].[U ser_ID],0) ))
| |--Clustered Index Scan(OBJECT:([VistaFileExp lorer].[db o].[User]. [PK_User]) )
|--Compute Scalar(DEFINE:([Expr1006]= 'GR'+CONVE RT(varchar (30),[Vist aFileExplo rer].[dbo] .[Group].[ Group_ID] as [gr].[Group_ID],0)))
|--Index Scan(OBJECT:([VistaFileExp lorer].[db o].[Group] .[IX_Group ] AS [gr]))
|--Sort(DISTINCT ORDER BY:([Union1007] ASC, [Union1008] ASC))
|--Concatenation
|--Compute Scalar(DEFINE:([Expr1003]=
| |--Clustered Index Scan(OBJECT:([VistaFileExp
|--Compute Scalar(DEFINE:([Expr1006]=
|--Index Scan(OBJECT:([VistaFileExp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried them the numbers of rows is 1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok
PK_User Nov 2 2008 8:00PM 1 1 1 0 4 NO
IX_Group Nov 2 2008 3:32PM 1 1 1 0 18 YES
PK_User Nov 2 2008 8:00PM 1 1 1 0 4 NO
IX_Group Nov 2 2008 3:32PM 1 1 1 0 18 YES
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nothing, less than one second. Obvoiusly the reason is from convert function, so do you have another alternative?
>Is there particular reason for using CONVERT function?
Yes of course I want to concatinate the characters 'GR' and 'US' with the id number.