Skip to Main Content
  • Questions
  • View that opens and runs once. The next time it's opened it hangs.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Brett.

Asked: October 18, 2016 - 6:01 pm UTC

Last updated: October 20, 2016 - 1:06 am UTC

Version: 11.2.0.4.0

Viewed 1000+ times

You Asked

I have a view that when you open the view in say something like TOAD, or MS Access, or SMSS it opens fine the first time. The next time you open it or select from it it hangs.

Creating the view I get no errors or warnings. If I open the view in TOAD or try and do a SELECT * FROM xxxxxx.XXX_LOW_FLYERS_MEASPERLOC_VW in PL/SQL it opens fine. Takes approximately 8 seconds to run. I get approximately 60 rows returned. No errors. I go and open a different table/view and come back into this view or run the PL\SQL a second time it hangs. I experience the same results if I use MS Access as front end or using a remote linked account in SMSS.

It opens fine if I compile the view before opening or selecting every time.

Not to experienced with Oracle.

Any thoughts or suggestions would be greatly appreciated.

DROP VIEW xxxxxx.XXX_LOW_FLYERS_MEASPERLOC_VW;

/* Formatted on 10/18/2016 1:23:03 PM (QP5 v5.252.13127.32847) */
CREATE OR REPLACE FORCE VIEW xxxxxx.XXX_LOW_FLYERS_MEASPERLOC_VW
(
XXX_MASTER_ID,
MEASPERLOC
)
AS
SELECT f1.XXX_MASTER_ID, COUNT (r1.XXX_MASTER_ID) AS MeasPerLoc
FROM xxxxxx.XXX_FYLERCOUNT_VW f1
INNER JOIN (SELECT * FROM xxxxxx.XXX_RAW_DATA WHERE DTTM_MEAS > SYSDATE - 8) r1
ON f1.XXX_MASTER_ID = r1.XXX_MASTER_ID
WHERE r1.MEASUREMENT_LOCATION = 1 AND (r1.MEAS_TAG = 'XD' OR r1.MEAS_TAG = 'YD')
GROUP BY f1.XXX_MASTER_ID;


Also, had tried just using table xxxxxx.XXX_RAW_DATA to the JOIN rather than limiting it to the past 8 days.

and Connor said...

Run

SELECT /*+ gather_plan_statistics*/ * FROM xxxxxx.XXX_LOW_FLYERS_MEASPERLOC_VW

followed by

select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'))

to see the plan estimates vs actuals.

Then do the same on the second time (when it runs slow), and compare the two.

If you get stuck, post them here (using the code tags) and we'll take a look

Rating

  (1 rating)

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

Comments

Hanging View

Brett Robbins, October 19, 2016 - 1:06 pm UTC

I ran the queries to gather the plan information the first time but it hangs on the second run. When I cancel I don't get the results back.

However, based on what I saw in the plan information from the first run I believe the issue is related to the nesting of the views. There are 3 views involved. v1, v2 which calls v1, and v3 which calls v1 and v2.

I used a WITH statement to combine queries to create 1 view instead of 3 separate views. It seems to be working fine this way. No more hanging after the initial select/open.

Thank you for your help.
Connor McDonald
October 20, 2016 - 1:06 am UTC

Glad you got it sorted out.

Its worth reading about "view merging" vs "view resolution" in the docs.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library