473,395 Members | 1,931 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,395 software developers and data experts.

performance question

Hi , long time I didn't ask any questions
And now I am back.
I have a huge query
that looks like that

select emp.name,
a.field1, b.field1,c.field1,d.field1,e,field1,f.field1,g.fie ld1
from emp left join (select sum(field1),empid from table group by
empid ) as a
on emp.uniqueid = a.empid
left join (select sum(field1),empid from table group by empid ) as
b
on emp.uniqueid = b.empid
left join (select sum(field1),empid from table group by empid ) as
d
on emp.uniqueid = d.empid
left join (select sum(field1),empid from table group by empid )as c
on emp.uniqueid = c.empid
left join(select sum(field1),empid from table group by empid ) as e
on emp.uniqueid = e.empid
left join (select sum(field1),empid from table group by empid )as f
on emp.uniqueid = f.empid
left join (select sum(field1),empid from table group by empid )as g
on emp.uniqueid =g.empid
where condition1 and
condition2 and condition3
union
select emp.name,
a.field1, b.field1,c.field1,d.field1,e,field1,f.field1,g.fie ld1
from emp left join (select sum(field1),empid from table group by
empid ) as a
on emp.uniqueid = a.empid
left join (select sum(field1),empid from table group by empid ) as
b
on emp.uniqueid = b.empid
left join (select sum(field1),empid from table group by empid ) as
d
on emp.uniqueid = d.empid
left join (select sum(field1),empid from table group by empid )as c
on emp.uniqueid = c.empid
left join(select sum(field1),empid from table group by empid ) as e
on emp.uniqueid = e.empid
left join (select sum(field1),empid from table group by empid )as f
on emp.uniqueid = f.empid
left join (select sum(field1),empid from table group by empid )as g
on emp.uniqueid =g.empid
where condition4 and
condition5 and condition6
union
select emp.name,
a.field1, b.field1,c.field1,d.field1,e,field1,f.field1,g.fie ld1
from emp left join (select sum(field1),empid from table group by
empid ) as a
on emp.uniqueid = a.empid
left join (select sum(field1),empid from table group by empid ) as
b
on emp.uniqueid = b.empid
left join (select sum(field1),empid from table group by empid ) as
d
on emp.uniqueid = d.empid
left join (select sum(field1),empid from table group by empid )as c
on emp.uniqueid = c.empid
left join(select sum(field1),empid from table group by empid ) as e
on emp.uniqueid = e.empid
left join (select sum(field1),empid from table group by empid )as f
on emp.uniqueid = f.empid
left join (select sum(field1),empid from table group by empid )as g
on emp.uniqueid =g.empid
where condition7 and
condition8 and condition9
(If you need the real one I can include it (It is 1000 lines))
So when I run it on database it always takes a different time to
execute.
A lot of times it was timing out, sometimes it doesn't take long (with
the same parameters)
I reindexed all tables, ran
sp_updatestats
sp_configure 'min memory per query (KB)' ,10240
(with reconfigure of course.) It was the same instability.
I replaced all selects in from : (select sum(field1),empid from table
group by empid )
with functions in select , but it didn't help.
What can be wrong? what should I do in this case? I have a procedures
like that.
Jul 20 '05 #1
2 1211
The best way to resolve problem - analyze execution plan
Jul 20 '05 #2
inna (me****@hotmail.com) writes:
Hi , long time I didn't ask any questions
And now I am back.
I have a huge query
that looks like that

select emp.name,
a.field1, b.field1,c.field1,d.field1,e,field1,f.field1,g.fie ld1
from emp left join (select sum(field1),empid from table group by
empid ) as a
on emp.uniqueid = a.empid
left join (select sum(field1),empid from table group by empid ) as
b
on emp.uniqueid = b.empid
left join (select sum(field1),empid from table group by empid ) as
d


Why are you repeating the same derived table all over again? Obviously
your real query does not look like that, but in what you have obscured
that query, I don't know, and I don't want to guess.

With the CREATE TABLE and CREATE INDEX statements for the involved tables,
some information about that data size and distribution in the tables, as
well as the query of the table itself, people in this newsgroup might be
able to help you. Of course, if it is a 1000-line monster, then the sheer
size of the query may be an obstacle for assistance over newsgroups.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

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

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

Similar topics

7
by: Randell D. | last post by:
Folks, I have a Javascript performance question that I might have problems explaining... In PHP, better performance can be obtained dealing directly with a variable, as opposed to an element...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
4
by: Martin | last post by:
I am using graphics as backgrounds for forms,buttons,labels etc. The question is: is it faster to load all graphics from files on app start or to use it embeded (places in editor during design)....
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
6
by: Mike | last post by:
Lets just say my app is done HOO HOO. Now, I'm accessing the database via a web service and one thing i noticed that my app is running real slow. When I first started working on the app is ran...
18
by: Rune B | last post by:
Hi Group I was considering using a Generic Dictionary<> as a value container inside my business objects, for the reason of keeping track of fields changed or added and so on. - But how...
5
by: Varangian | last post by:
Hi, I have a performance issue question? which is best (in terms of efficiency and performance, I don't care neatness in code)... building an ArrayList of Object Instances using SqlDataReader...
5
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the...
5
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary,...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.