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;

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: