RE: tune between query/join

  • From: "Dunbar, Norman (Capgemini)" <norman.dunbar.capgemini@xxxxxxxxxxxxxxxxxxxxxxxxx>
  • To: "sfaroult@xxxxxxxxxxxx" <sfaroult@xxxxxxxxxxxx>, "ax.mount@xxxxxxxxx" <ax.mount@xxxxxxxxx>
  • Date: Fri, 21 Oct 2011 08:27:46 +0000

Morning Stephane,

<SNIP>

>> If you rewrite the condition as the equivalent
>> 
>> where a.lowest_amount <= b.amount
>>      and a.highest_amount >= b.amount

<SNIP>

>> Create an index on (lowest_amount, highest_amount) and it will fly.

The OP said that this was the query:

>> >> select a.account_number, a.id, b.*
>> >>    from account a, tmp_account b
>> >> where b.amount between a.lowest_amount and a.highest_amount

Plus:

>> >> account has 8000000 rows and tmp_account 150000, 

And:

>> >> this query takes around 5 hours to run.

So, *assuming* that there is a "missing" semi-colon above, surely this query is 
returning a selection of rows from an 8,000,00 * 150,000 cartesian product?

With a join between a.<some_id> and b.<some_id>, in addition to the above, it 
should fly even more?

Mind you, I'm only on my first coffee of the morning and I'm really really not 
as good an SQL guru as you are, so be gentle with me!


Cheers,
Norm.

Norman Dunbar
Contract Senior Oracle DBA
Capgemini Database Build Team
Internal : 7 28 2051
External : 0113 231 2051

Information in this message may be confidential and may be legally privileged. 
If you have received this message by mistake, please notify the sender 
immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should 
still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under 
the Freedom of Information Act, Data Protection Act or for litigation.  Email 
messages and attachments sent to or from any Environment Agency address may 
also be accessed by someone other than the sender or recipient, for business 
purposes.

If we have sent you information and you wish to use it please read our terms 
and conditions which you can get by calling us on 08708 506 506.  Find out more 
about the Environment Agency at www.environment-agency.gov.uk
--
//www.freelists.org/webpage/oracle-l


Other related posts: