Skip to Main Content
  • Questions
  • Query goes on executing something like infinite loop without displaying any result .

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Ravi.

Asked: June 16, 2016 - 11:51 am UTC

Last updated: June 16, 2016 - 3:31 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Tom ,

I have two queries as mentioned below .
When I run the first query the result are as expected .
But when I run the second query , it goes on executing without displaying any results . I want to know why it is go on executing like an infinite loop .

Note Query 1 is almost same as Query 2 , the only difference I made is marked as underline in below queries
I have also pasted the explain plan of both the queries below .
( I really don't know how to introduce space and also don't know how to paste any diagrams here in the site so please bear with explain plans )

Please note that the subquery used in Query 2 always result in the same value as mentioned in Query 1 .i.e 1234

Query 1

SELECT /*+ INDEX(eventdiscount,eventdiscount_pk) INDEX( elementdiscount,elementdiscount_pk) INDEX(product,product_pk)
INDEX(price,price_pk) */
ed.REVENUE_CODE_ID,
ed.DISCOUNT_DESC,
ted.TARIFF_ID,
ed.EVENT_DISCOUNT_ID,
t.TARIFF_NAME
FROM eventdiscount ed, elementdiscount ted, price t ,productpricedetails cptd , product chp
WHERE ed.EVENT_DISCOUNT_ID= ted.EVENT_DISCOUNT_ID
AND ed.CATALOGUE_CHANGE_ID= ted.CATALOGUE_CHANGE_ID
AND ted.TARIFF_ID = t.TARIFF_ID
AND ted.CATALOGUE_CHANGE_ID= t.CATALOGUE_CHANGE_ID
AND cptd.TARIFF_ID = t.TARIFF_ID
AND cptd.CUSTOMER_REF =chp.CUSTOMER_REF
AND cptd.PRODUCT_SEQ = chp.PRODUCT_SEQ
AND ted.product_id = chp.product_id
AND cptd.CUSTOMER_REF ='BPPRU_T'
AND cptd.START_DAT <= TO_DATE(20160101,'YYYYMMDD')
AND (cptd.END_DAT is null OR cptd.end_dat >=TO_DATE(trim(20160131),'YYYYMMDD'))
AND cptd.PRODUCT_SEQ = 1
AND t.CATALOGUE_CHANGE_ID = 1234
AND ted.START_DAT <= TO_DATE(20160101,'YYYYMMDD')
AND (ted.END_DAT is null OR ted.end_dat >=TO_DATE(trim(20160131),'YYYYMMDD'))
AND ed.DISCOUNT_NAME = 'HUB-10Gbit/s';

Query 2

SELECT /*+ INDEX(eventdiscount,eventdiscount_pk) INDEX( elementdiscount,elementdiscount_pk) INDEX(product,product_pk)
INDEX(price,price_pk) */
ed.REVENUE_CODE_ID,
ed.DISCOUNT_DESC,
ted.TARIFF_ID,
ed.EVENT_DISCOUNT_ID,
t.TARIFF_NAME
FROM eventdiscount ed, elementdiscount ted, price t ,productpricedetails cptd , product chp
WHERE ed.EVENT_DISCOUNT_ID= ted.EVENT_DISCOUNT_ID
AND ed.CATALOGUE_CHANGE_ID= ted.CATALOGUE_CHANGE_ID
AND ted.TARIFF_ID = t.TARIFF_ID
AND ted.CATALOGUE_CHANGE_ID= t.CATALOGUE_CHANGE_ID
AND cptd.TARIFF_ID = t.TARIFF_ID
AND cptd.CUSTOMER_REF =chp.CUSTOMER_REF
AND cptd.PRODUCT_SEQ = chp.PRODUCT_SEQ
AND ted.product_id = chp.product_id
AND cptd.CUSTOMER_REF ='BPPRU_T'
AND cptd.START_DAT <= TO_DATE(20160101,'YYYYMMDD')
AND (cptd.END_DAT is null OR cptd.end_dat >=TO_DATE(trim(20160131),'YYYYMMDD'))
AND cptd.PRODUCT_SEQ = 1
AND t.CATALOGUE_CHANGE_ID in ( select distinct(catalogue_change_id) from eventdiscount where DISCOUNT_NAME = 'HUB-10Gbit/s' )
AND ted.START_DAT <= TO_DATE(20160101,'YYYYMMDD')
AND (ted.END_DAT is null OR ted.end_dat >=TO_DATE(trim(20160131),'YYYYMMDD'))
AND ed.DISCOUNT_NAME = 'HUB-10Gbit/s';


Explain Plan of Query 1

SELECT STATEMENT, GOAL = RULE
TABLE ACCESS BY INDEX ROWID ELEMENTDISCOUNT
NESTED LOOPS
NESTED LOOPS
MERGE JOIN CARTESIAN
NESTED LOOPS
NESTED LOOPS
NESTED LOOPS
TABLE ACCESS BY INDEX ROWID PRODUCT
INDEX UNIQUE SCAN PRODUCT_PK
TABLE ACCESS BY INDEX ROWID CATALOGUECHANGE
INDEX UNIQUE SCAN CATALOGUECHANGE_PK
TABLE ACCESS BY INDEX ROWID CATALOGUECHANGE
INDEX UNIQUE SCAN CATALOGUECHANGE_PK
TABLE ACCESS BY INDEX ROWID PRODUCTPRICEDETAILS
INDEX RANGE SCAN PRODUCTPRICEDETAILS_PK
BUFFER SORT
TABLE ACCESS BY INDEX ROWID EVENTDISCOUNT
INDEX RANGE SCAN EVENTDISCOUNT_PK
TABLE ACCESS BY INDEX ROWID PRICE
INDEX RANGE SCAN PRICE_AK1
INDEX RANGE SCAN ELEMENTDISCOUNT_PK

Explain Plan of Query 2

SELECT STATEMENT, GOAL = ALL_ROWS
NESTED LOOPS SEMI
NESTED LOOPS
NESTED LOOPS
NESTED LOOPS
MERGE JOIN CARTESIAN
TABLE ACCESS BY INDEX ROWID ELEMENTDISCOUNT
NESTED LOOPS
NESTED LOOPS
TABLE ACCESS BY INDEX ROWID CUSTHASPRODUCT
INDEX UNIQUE SCAN CUSTHASPRODUCT_PK
TABLE ACCESS FULL CATALOGUECHANGE
INDEX RANGE SCAN ELEMENTDISCOUNT_PK
BUFFER SORT
TABLE ACCESS BY INDEX ROWID PRODUCTPRICEDETAILS
INDEX RANGE SCAN PRODUCTPRICEDETAILS_PK
TABLE ACCESS BY INDEX ROWID PRICE
INDEX RANGE SCAN PRICE_AK1
TABLE ACCESS BY INDEX ROWID EVENTDISCOUNT
INDEX UNIQUE SCAN EVENTDISCOUNT_PK
TABLE ACCESS BY INDEX ROWID CATALOGUECHANGE
INDEX UNIQUE SCAN CATALOGUECHANGE_PK
TABLE ACCESS BY INDEX ROWID EVENTDISCOUNT
INDEX RANGE SCAN EVENTDISCOUNT_PK


Thanks & Regards
Ravi

and Chris said...

Oracle returns rows to the client when it's finished executing the query.

Your second query is simply taking (a lot) longer to process. If you wait long enough you'll get your answer eventually (assuming it don't hit an error).

If you're licensed for the Diagnostics and Tuning packs, use the SQL Monitor. This will show you the progress of the SQL execution in real time.

https://oracle-base.com/articles/11g/real-time-sql-monitoring-11gr1

A couple of observations on your query:

- The slow query has a full tablescan of CATALOGUECHANGE. I don't understand where this comes from, because it's not listed in either of your queries!
- There's a MERGE JOIN CARTESIAN in both plans. In the bad plan, I suspect Oracle has incorrectly estimated that the steps below only return one row. When they actually return lots.

To validate this, you need to get an execution (not explain!) plan. If you're not licensed for SQL Monitor, you'll have to wait for the query to finish to get this. You can find further instructions on this at:

https://blogs.oracle.com/sql/entry/how_to_create_an_execution

If you need further help then please post the execution plan for your slow query. Ensure this includes the estimated and actual rows!

To format your plans, use code tags.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

ghassan, June 16, 2016 - 2:18 pm UTC

" The slow query has a full tablescan of CATALOGUECHANGE. I don't understand where this comes from, because it's not listed in either of your queries! "

MAYBE A SYNONYM?

is there a bijection between the CATALOGUE_CHANGE_ID and the
DISCOUNT_NAME ?

why this predicate ?

AND t.CATALOGUE_CHANGE_ID in ( select distinct(catalogue_change_id) from eventdiscount where DISCOUNT_NAME = 'HUB-10Gbit/s' )

since you have this :
AND ed.DISCOUNT_NAME = 'HUB-10Gbit/s'

??

tables desc??
indexes??

Chris Saxon
June 16, 2016 - 3:31 pm UTC

MAYBE A SYNONYM?

Maybe. But all the tables in the query are in the plan. There's also a CUSTHASPRODUCT table in the plan not in the query.

So we're missing something somwhere...

More

Ghassan, June 16, 2016 - 6:34 pm UTC

Sorry I add more details to ..
Well I cannot see say table "price" in the plan. . So maybe price is a synonym to CATALOG. .table or maybe a view. .
I was just guessing instead of limiting to a table

Anyway the requester must give a reliable sentences. Really I admire your patience and good work . Don't know how all this community do if asktom close the door. Your site is a godsend reference.
All the bests

More to Explore

Hints

Need more information on hints? Check out the complete hint descriptions