Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Query optimization
12 posts, Page 1 of 2
1
2
»»
Query optimization
Rate Topic
Display Mode
Topic Options
Author
Message
Aadhar Joshi
Aadhar Joshi
Posted Wednesday, December 12, 2012 12:35 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:44 PM
Points: 1,143,
Visits: 229
Hello,
I have two tables
#InnerTable which have around 7000 rows
DCl.CompanyToken which have around 20000000 rows
when i am firing below query, it takes around 30 mins to execute and return 787 rows..
please help to optimize it
SELECT
a.SearchTokenNumber ,
a.SearchRowID ,
CT.CompanyID ,
CT.CompanyRowID ,
a.SearchField ,
a.MaxPossibleScore ,
a.AssignedWeight ,
MAX(a.Weight) Weight
FROM
#InnerTable a
INNER JOIN DCl.CompanyToken CT ON a.CompanyTokenNumber = CT.CompanyTokenNumber
WHERE AND CT.Token = a.Token
GROUP BY a.SearchTokenNumber ,
a.SearchRowID ,
CT.CompanyID ,
CT.CompanyRowID ,
a.SearchField ,
a.MaxPossibleScore ,
a.AssignedWeight
Note..
CREATE INDEX IX_LocalIdentifierID ON #InnerTable (CompanyTokenNumber) index is applied on #InnerTable.
/****** Object: Index [ix_CL_DCL_CompanyToken] Script Date: 12/12/2012 13:04:19 ******/
CREATE CLUSTERED INDEX [ix_CL_DCL_CompanyToken] ON [DCL].[CompanyToken]
(
[CompanyTokenNumber] ASC,
[Token] ASC,
[CompanyID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
index is applied on DCl.CompanyToken
Post #1395465
Koen Verbeeck
Koen Verbeeck
Posted Wednesday, December 12, 2012 12:38 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 2:11 AM
Points: 9,378,
Visits: 6,473
Can you post the actual query plan?
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1395467
GilaMonster
GilaMonster
Posted Wednesday, December 12, 2012 12:49 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 4:30 AM
Points: 37,742,
Visits: 30,021
Please post table definitions, index definitions and execution plan, as per
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #1395474
Aadhar Joshi
Aadhar Joshi
Posted Wednesday, December 12, 2012 1:40 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:44 PM
Points: 1,143,
Visits: 229
Please find attachment
Thanks,
Aadhar
Post Attachments
Query.zip
(
11 views,
25.04 KB
)
Post #1395492
nigelrivett
nigelrivett
Posted Wednesday, December 12, 2012 1:49 AM
Old Hand
Group: General Forum Members
Last Login: Monday, January 28, 2013 1:45 AM
Points: 386,
Visits: 199
How many rows does it need to access in the large table - is it most of them or a few.
Are the group by columns independent? Can some be omitted from the group by and a max used in the resultset - i.e. if you omit some any column from the group by clause will you always get less groups?
Cursors never.
DTS - only when needed and never to control.
Post #1395495
Aadhar Joshi
Aadhar Joshi
Posted Wednesday, December 12, 2012 2:07 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:44 PM
Points: 1,143,
Visits: 229
large table has 20000000 rows and all group by are required
By ommiting single group by will raise me to an error..
Post #1395509
nigelrivett
nigelrivett
Posted Wednesday, December 12, 2012 2:48 AM
Old Hand
Group: General Forum Members
Last Login: Monday, January 28, 2013 1:45 AM
Points: 386,
Visits: 199
The large table has that many rows but are they all involved in the join to the temp table or does that join filter the rows accessed and if so by how much. If you only require a few thousand rows from the large table it could help to split the query into two.
Removing a column from the group by will give an error unless you aggregate the column in the select clause by using (e.g.) max()
So if you remove a.AssignedWeight from the group by clause and change the entry in the select clause to max(a.AssignedWeight) do you get less entries returned or is a.AssignedWeight dependent on the other values?
Cursors never.
DTS - only when needed and never to control.
Post #1395528
Aadhar Joshi
Aadhar Joshi
Posted Wednesday, December 12, 2012 3:12 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:44 PM
Points: 1,143,
Visits: 229
This is what u are telling same thing.
If i split query and i take sub data and group it or i take temp table to store partial data and use it to further join, It will take same time.
I tried but couldnt succeed.
Post #1395542
nigelrivett
nigelrivett
Posted Wednesday, December 12, 2012 3:17 AM
Old Hand
Group: General Forum Members
Last Login: Monday, January 28, 2013 1:45 AM
Points: 386,
Visits: 199
Do you want to answer the questions I asked?
Cursors never.
DTS - only when needed and never to control.
Post #1395547
Aadhar Joshi
Aadhar Joshi
Posted Wednesday, December 12, 2012 4:09 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:44 PM
Points: 1,143,
Visits: 229
I tried but it produces less rows..
Post #1395574
« Prev Topic
|
Next Topic »
12 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.