Q

Help making a query faster

I would like to execute this query faster. Can you please help me? The query works but it can get slow with different values.

I would like to execute this query faster. Can you please help me? The query works but it can get slow with different values.
select distinct (tb1.SupporterID), tb1.lotteryNumber, tb1.DrawNumber,
tb1.PrizeDrawID, tb1.prizeValue, 
tb1.winningTicket, tb1.title, tb1.initials, tb1.surname, 
tb1.address1,tb1.address2,tb1.address3,tb1.address4,
tb1.supporterNumber, tb1.prizeName from ( select 
distinct pw1.SupporterID, pw1.PrizeWinID, Lpt.lotteryNumber,
pw1.DrawNumber, pw1.PrizeDrawID, 
pd.prizeValue, pw1.winningTicket, pw1.title, pw1.initials, pw1.surname, 
pw1.address1,pw1.address2,pw1.address3,pw1.address4, s.supporterNumber,
p.prizeName  from prize_win pw1 
inner join ( select pt.purchasedTicketID,L.lotteryNumber from
purchased_Ticket pt inner join lottery L 
on  pt.lotteryID = L.lotteryID where L.lotteryNumber between 215 and
230) Lpt on pw1.PurchasedTicketID = 
Lpt.purchasedTicketID inner join prize_draw pd on pw1.PrizeDrawID =
pd.PrizeDrawID inner join supporter 
s on pw1.SupporterID = s.SupporterID inner join prize p on
pw1.PrizeDrawID = p.PrizeDrawID) tb1 inner 
join (select pw1.SupporterID, pw1.PrizeWinID from prize_win  pw1 inner
join ( select 
pt.purchasedTicketID from purchased_Ticket pt inner join lottery L on
pt.lotteryID = L.lotteryID where 
L.lotteryNumber between 215 and 230) Lpt on pw1.PurchasedTicketID =
Lpt.purchasedTicketID ) tb2 on 
tb1.SupporterID = tb2.SupporterID where tb1.PrizeWinID <> tb2.PrizeWinID
order by tb1.SupporterID asc;
Usually when the response time changes based on the values, this indicates data skew. In other words, you put in "where x=10" and you get back five values, and "where x=5" gives back 3,000. Oracle assumes that data is equally distributed around indexed values. If the data is not equally distributed about an index it is skewed. In order to help the optimizer with skewed data you need to use histograms. Histograms are created using the ANALYZE command or through options in the DBMS_STATS gather procedures.
This was first published in January 2006

Dig deeper on Oracle and SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close