Query takes forever to execute
This query executes forever:
select count(*)
from VIEW_DOCUMENT
where exists
select VIEW_DOCUMENT_ITEM.documentID
from VIEW_DOCUMENT_ITEM
where VIEW_DOCUMENT_ITEM.documentID=VIEW_DOCUMENT.documentID
Here's what's inside VIEW_DOCUMENT_ITEM:
select *
from DOCUMENT_ITEM
join VIEW_USER
If I replace "join VIEW_USER" with "join USER" the query executes normally in few seconds!
This makes no sense because here's what's in VIEW_USER:
select * from USER
Does anybody know what are possible causes for this strange behaviour?
Actually my query is much more complex, this is simplified version.
In original query it's 100% not cartesian join.
Result of my query is 2710 and result of Sven's query is 2711.
My question is only why does joining a table work normally and why does joining a view "select * from table" take forever.
I can't see execution plan because my query never ends. I have to kill the Linux process.
Here is TKPROF output, I don't know what this stuff means:
TKPROF: Release 10.2.0.1.0 - Production on Tue Mar 4 14:21:57 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Trace file: orcl_ora_29715.trc
Sort options: prsela exeela fchela
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
alter session set sql_trace true
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 1 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 64
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 1 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Misses in library cache during execute: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 58 0.00 0.01 0 0 0 0
Execute 308 0.05 0.06 0 0 0 0
Fetch 758 0.03 0.16 38 1188 0 2086
total 1124 0.10 0.24 38 1188 0 2086
Misses in library cache during parse: 13
Misses in library cache during execute: 13
1 user SQL statements in session.
308 internal SQL statements in session.
309 SQL statements in session.
Trace file: orcl_ora_29715.trc
Trace file compatibility: 10.01.00
Sort options: prsela exeela fchela
1 session in tracefile.
1 user SQL statements in trace file.
308 internal SQL statements in trace file.
309 SQL statements in trace file.
14 unique SQL statements in trace file.
3007 lines in trace file.
0 elapsed seconds in trace file.
Similar Messages
-
URGENT: SAVE_DATA takes forever to execute
Urgent, please advise.
In the planning layout all the planning functions work fine. When a user tries to execute SAVE_Data standard SAP function, the system takes forever to execute, and times out. NO matter how many records are to be processed, 76 vs 30000. This is a standard SAP function, and it did work before fine, what is the possible problem?
Thanks!1. Run BPS_Stat0 and see where it is going wrong.
2. Does this happen in multi area set up?
3. Try to do the same operations and save in BPS0. If the system saves in BPS0, then you have to relook at the folder configuration.
4. Let me know what kind of functions you have in the layout.
5. You can also check the values in the variables.
Ravi Thothadri -
I am creating a jsp application . . . .I am retreiving some values from my database oracle 10g..my query taking time to execute even in isql plus..am uisng tomcat5 and oracle 10gR2..can anyone pls tell me why it happens...my query fetches data from four tables...i dont know exactly why its taking so muc time say 50seconds...when i run the application in my local host it retrievs fast when i do that in server it creates a problem..
Actually it works fine when i deployed in my client server it takes time sometimes it takes atmost one minute
1.pls tell me how can i test my query about the performance
2.is der any command in oracle to test
3.how much bytes it takesLook at this thread...
When your query takes too long ... -
Query takes time to execute. Review this query and give me a possible quere
SELECT DISTINCT A.REFERENCE_NUMBER
FROM A,B,C
WHERE DF_N_GET_CONTRACT_STATUS (A.REFERENCE_NUMBER, TRUNC (SYSDATE)) = 1
AND ( B.CHQ_RTN_INDICATOR IS NULL AND B.CHALLAN_NUMBER IS NULL
AND C.INSTRUMENT_TYPE IN (1, 2) AND C.MODULE_CODE = 5 )
AND ( A.HEADER_KEY = B.HEADER_KEY AND C.HEADER_KEY = B.HEADER_KEY);
This query takes 3 minutes to execute. I want to improve the performance so that it can execute with in seconds.
Table A has 10 lakhs record.
Table B has 3.7 lakhs record.
Table C has 5.3 lakhs record. Consider DF_N_GET_CONTRACT_STATUS as function. REFERENCE_NUMBER is the type of Varchar2(20).
Plz give me a correct logical and fastest execution query for the same.
Thanks in advance.I would agree with the post from Santosh above that you should review the guidelines for posting a tuning request. This is VERY important. It is impossile to come up with any useful suggestions without the proper information.
In the case of your query, I would probably focus my attention on the function that you have defined. What happens if the condition using the DF_N_GET_CONTRACT_STATUS function is removed? Does it still take 3 minutes?
SELECT reference_number
from (
SELECT DISTINCT A.REFERENCE_NUMBER
FROM A,B,C
WHERE ( B.CHQ_RTN_INDICATOR IS NULL AND B.CHALLAN_NUMBER IS NULL
AND C.INSTRUMENT_TYPE IN (1, 2) AND C.MODULE_CODE = 5 )
AND ( A.HEADER_KEY = B.HEADER_KEY AND C.HEADER_KEY = B.HEADER_KEY)
where DF_N_GET_CONTRACT_STATUS(reference_number, trunc(sysdate)) = 1;Of course, the query above really depends on the cardinality of the returned data..... which is impossible to know without following the posting guidelines. This query could return anywhere between 0 rows and 2x10^17 rows. And in the latter case evaluating the function at the end wouldn't make any difference.
Also, do you really need the distinct? Does it make any difference? Most of the time that I see distinct, to me it either means the query is wrong or the data model is wrong. -
computer freezes after installing Yosemite upgrade when you click on something the colored wheel pops up and takes forever to execute
Boot into the Recovery volume (boot with the Command + R keys held down), select Disk Utility and repair both the disk permissions and the disk. Reboot normally and check the performance. Any improvement?
Have you run any "cleaning" or "optimizing" apps on your Mac or install any antivirus software? Download and run Etrecheck. Copy and paste the results into your reply. It's a diagnostic tool that was developed by one of the most respected users here in the ASC to help identify the more obvious culprits. -
MapLocationFinder.FindLocationsAtAsync takes forever to execute
I'm using MapLocationFinder.FindLocationsAtAsync in my Windows Phone 8.1 app, but sometimes the method takes too long time to execute (or in rare conditions it never finishes). I'd like to be able to skip the method execution in such cases, but I couldn't
find a way to cancel the execution of the method after some period.
Can anyone help me with this case?MapLocationFinder.FindLocationsAtAsync method returns
IAsyncOpertaion<TResult> object, you can use
AsTask extension method to convert it to a
Task<TResult> object, then you can easily to get the result, cancel, get notification on completion and so on. In this case, you can provide a button for user to stop from execution of FindLocationsAtAsync method.
For more info, refer to the page to see Remarks section.
https://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx. -
Hi
I have this query for inserts and it never ends. I need some suggestions , can some one please help ? It will be much appreciated
INSERT INTO PIMITEK.BENE_SEC_PCPTNT_FINAL
SELECT P.PART_ID, MAX(TH.TSKID || TT.TSKDESC)
FROM PIMITEK.BENE_SEC_PCPTNT P
LEFT JOIN TSKIDENT TI
ON SUBSTR(P.PART_ID,1,9) = SUBSTR(TI.FIELDVALUE,1,9)
AND TI.IDCODE = 18
AND TI.FIELDNBR = 1
AND SUBSTR(TI.FIELDVALUE,10,1) = ' '
LEFT JOIN COMPTSKIDENT CT
ON SUBSTR(P.PART_ID,1,9) = SUBSTR(CT.FIELDVALUE,1,9)
AND CT.IDCODE = 18
AND CT.FIELDNBR = 1
AND SUBSTR(CT.FIELDVALUE,10,1) = ' '
JOIN TSKHIST TH
ON (TI.TSKID = TH.TSKID
OR CT.TSKID = TH.TSKID)
AND TH.TSKCODE IN
(SELECT TSKCODE
FROM TSKTYPE
JOIN PIMITEK.BENE_SEC_TSKTYPES
ON TSKDESC = TASK_TYPE)
JOIN TSKTYPE TT
ON TH.TSKCODE = TT.TSKCODE
WHERE P.PART_ID NOT IN (SELECT P2.PART_ID
FROM PIMITEK.BENE_SEC_PCPTNT_FINAL P2)
GROUP BY P.PART_ID ;
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | INSERT STATEMENT | | 1 | 229 | 611K (1)| 02:02:14 | | |
| 1 | HASH GROUP BY | | 1 | 229 | 611K (1)| 02:02:14 | | |
|* 2 | HASH JOIN | | 1 | 229 | 611K (1)| 02:02:14 | | |
| 3 | NESTED LOOPS | | 1 | 218 | 611K (1)| 02:02:14 | | |
| 4 | NESTED LOOPS | | 1 | 203 | 611K (1)| 02:02:14 | | |
| 5 | NESTED LOOPS | | 1 | 188 | 611K (1)| 02:02:14 | | |
| 6 | NESTED LOOPS OUTER | | 1 | 172 | 370K (1)| 01:14:11 | | |
|* 7 | HASH JOIN OUTER | | 1 | 103 | 3443 (1)| 00:00:42 | | |
|* 8 | HASH JOIN ANTI | | 1 | 34 | 5 (20)| 00:00:01 | | |
| 9 | TABLE ACCESS FULL | BENE_SEC_PCPTNT | 1 | 17 | 2 (0)| 00:00:01 | | |
| 10 | TABLE ACCESS FULL | BENE_SEC_PCPTNT_FINAL | 1 | 17 | 2 (0)| 00:00:01 | | |
| 11 | PARTITION HASH ALL | | 528 | 36432 | 3438 (1)| 00:00:42 | 1 | 10 |
|* 12 | TABLE ACCESS FULL | TSKIDENT | 528 | 36432 | 3438 (1)| 00:00:42 | 1 | 10 |
| 13 | PARTITION HASH ALL | | 2445 | 164K| 367K (1)| 01:13:30 | 1 | 40 |
|* 14 | INDEX RANGE SCAN | COMPTSKIDENTNP_IDENTIF_IDCODE | 2445 | 164K| 367K (1)| 01:13:30 | 1 | 40 |
| 15 | PARTITION HASH ALL | | 432 | 6912 | 240K (1)| 00:48:03 | 1 | 10 |
|* 16 | INDEX FAST FULL SCAN | TSKHIST_TSK_OP_PD_ST_AC_DP | 432 | 6912 | 240K (1)| 00:48:03 | 1 | 10 |
| 17 | TABLE ACCESS BY INDEX ROWID| TSKTYPE | 1 | 15 | 1 (0)| 00:00:01 | | |
|* 18 | INDEX UNIQUE SCAN | TSKTYPE_TSKCODE | 1 | | 0 (0)| 00:00:01 | | |
| 19 | TABLE ACCESS BY INDEX ROWID | TSKTYPE | 1 | 15 | 0 (0)| 00:00:01 | | |
|* 20 | INDEX UNIQUE SCAN | TSKTYPE_TSKCODE | 1 | | 0 (0)| 00:00:01 | | |
| 21 | TABLE ACCESS FULL | BENE_SEC_TSKTYPES | 17 | 187 | 3 (0)| 00:00:01 | | |
Predicate Information (identified by operation id):
2 - access("TSKDESC"="TASK_TYPE")
7 - access(SUBSTR("P"."PART_ID",1,9)=SUBSTR("TI"."FIELDVALUE"(+),1,9))
8 - access("P"."PART_ID"="P2"."PART_ID")
12 - filter("TI"."IDCODE"(+)=18 AND SUBSTR("TI"."FIELDVALUE"(+),10,1)=' ' AND "TI"."FIELDNBR"(+)=1)
14 - access("CT"."IDCODE"(+)=18 AND "CT"."FIELDNBR"(+)=1)
filter(SUBSTR("CT"."FIELDVALUE"(+),10,1)=' ' AND SUBSTR("P"."PART_ID",1,9)=SUBSTR("CT"."FIELDVALUE"(+),1,9))
16 - filter("TI"."TSKID"="TH"."TSKID" OR "CT"."TSKID"="TH"."TSKID")
18 - access("TH"."TSKCODE"="TSKTYPE"."TSKCODE")
20 - access("TH"."TSKCODE"="TT"."TSKCODE")Hello,
Seem you have partitioned table, try the query without insert statement and then instead of insert use create table as (for test purpose). you should collect stats on all the table involved in this query. How many rows you have in this followign table BENE_SEC_TSKTYPES ? Next time when you post output enclose it in between \ tag to preserve formatting for better readibility.
You can also try using append hint and see if this speeds upINSERT /*+APPEND */ INTO pimitek.bene_sec_pcptnt_final ....
create table mytest_table as
SELECT p.part_id, MAX (th.tskid || tt.tskdesc)
FROM pimitek.bene_sec_pcptnt p
LEFT JOIN
tskident ti
ON SUBSTR (p.part_id, 1, 9) = SUBSTR (ti.fieldvalue, 1, 9)
AND ti.idcode = 18
AND ti.fieldnbr = 1
AND SUBSTR (ti.fieldvalue, 10, 1) = ' '
LEFT JOIN
comptskident ct
ON SUBSTR (p.part_id, 1, 9) = SUBSTR (ct.fieldvalue, 1, 9)
AND ct.idcode = 18
AND ct.fieldnbr = 1
AND SUBSTR (ct.fieldvalue, 10, 1) = ' '
JOIN
tskhist th
ON (ti.tskid = th.tskid OR ct.tskid = th.tskid)
AND th.tskcode IN (SELECT tskcode
FROM tsktype
JOIN
pimitek.bene_sec_tsktypes
ON tskdesc = task_type)
JOIN
tsktype tt
ON th.tskcode = tt.tskcode
WHERE p.part_id NOT IN (SELECT p2.part_id
FROM pimitek.bene_sec_pcptnt_final p2)
GROUP BY p.part_id;
Regards -
Problem with Top N Query when no rows returned (takes forever)
I have a table with 100 Million rows and I want to get the latest N records using:
SELECT * FROM
(SELECT * FROM tablename WHERE columnA= 'ABC' ORDER BY TIME DESC)
WHERE rownum <= N;
This works fine and is very fast when there are rows with columnA= 'ABC' but when there are no rows with columnA= 'ABC' the query takes forever.
The strange things is that the inner query returns immediately when run on it's own when no rows with columnA= 'ABC' exist e.g.
SELECT * FROM tablename WHERE columnA= 'ABC' ORDER BY TIME DESC
So why does it take for ever for to run:
SELECT * FROM (no rows inner query) WHERE rownum <= N;
I have also tried using:
SELECT * FROM
(SELECT columnA, rank() over(ORDER BY TIME DESC) time_rank
FROM tablename WHERE columnA='ABC')
WHERE time_rank <= N;
which returns instantly when there are now rows but takes much longer than the first query when there are rows.I cannot see a real difference:With histogram we can see a difference on the elapse when no row returned and into explain plan.
SQL> drop table tablename
2 /
Table dropped.
Elapsed: 00:00:00.03
SQL>
SQL> create table tablename
2 as
3 select sysdate - l time
4 , decode(trunc(dbms_random.value(1,10)),1,'ABC',2,'DEF',3,'GHI',4,'JKL','MNO') as columnA
5 from (select level l from dual connect by level <= 1000000)
6 /
Table created.
Elapsed: 00:01:19.08
SQL>
SQL> select columnA,count(*) from tablename group by columnA
2 /
COL COUNT(*)
ABC 110806
DEF 111557
GHI 111409
JKL 111030
MNO 555198
Elapsed: 00:00:05.05
SQL>
SQL> create index i1 on tablename(time)
2 /
Index created.
Elapsed: 00:00:34.08
SQL>
SQL> create index i2 on tablename(columna)
2 /
Index created.
Elapsed: 00:00:30.08
SQL>
SQL> exec dbms_stats.gather_table_stats(user,'TABLENAME',cascade=>true)
PL/SQL procedure successfully completed.
Elapsed: 00:01:18.09
SQL>
SQL> set autotrace on explain
SQL> SELECT * FROM
2 (SELECT * FROM tablename WHERE columnA= 'ABC' ORDER BY TIME DESC)
3 WHERE rownum <= 10
4 /
TIME COL
17/09/06 ABC
12/09/06 ABC
08/09/06 ABC
07/09/06 ABC
25/08/06 ABC
22/08/06 ABC
13/08/06 ABC
08/07/06 ABC
14/06/06 ABC
01/05/06 ABC
10 rows selected.
Elapsed: 00:00:01.04
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2364 Card=10 Bytes=120)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=2364 Card=200000 Bytes=2400000)
3 2 SORT (ORDER BY STOPKEY) (Cost=2364 Card=200000 Bytes=2400000)
4 3 TABLE ACCESS (FULL) OF 'TABLENAME' (Cost=552 Card=200000 Bytes=2400000)
SQL>
SQL> SELECT * FROM
2 (SELECT * FROM tablename WHERE columnA= 'MNO' ORDER BY TIME DESC)
3 WHERE rownum <= 10
4 /
TIME COL
20/09/06 MNO
19/09/06 MNO
16/09/06 MNO
14/09/06 MNO
13/09/06 MNO
10/09/06 MNO
06/09/06 MNO
05/09/06 MNO
03/09/06 MNO
02/09/06 MNO
10 rows selected.
Elapsed: 00:00:02.04
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2364 Card=10 Bytes=120)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=2364 Card=200000 Bytes=2400000)
3 2 SORT (ORDER BY STOPKEY) (Cost=2364 Card=200000 Bytes=2400000)
4 3 TABLE ACCESS (FULL) OF 'TABLENAME' (Cost=552 Card=200000 Bytes=2400000)
SQL>
SQL> SELECT * FROM
2 (SELECT * FROM tablename WHERE columnA= 'PQR' ORDER BY TIME DESC)
3 WHERE rownum <= 10
4 /
no rows selected
Elapsed: 00:00:01.01
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2364 Card=10 Bytes=120)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=2364 Card=200000 Bytes=2400000)
3 2 SORT (ORDER BY STOPKEY) (Cost=2364 Card=200000 Bytes=2400000)
4 3 TABLE ACCESS (FULL) OF 'TABLENAME' (Cost=552 Card=200000 Bytes=2400000)
SQL> set autot off
SQL>
SQL> EXECUTE DBMS_STATS.GATHER_TABLE_STATS(user,'TABLENAME',METHOD_OPT => 'FOR COLUMNS SIZE 250 columna')
PL/SQL procedure successfully completed.
Elapsed: 00:00:09.08
SQL>
SQL> set autotrace on explain
SQL> SELECT * FROM
2 (SELECT * FROM tablename WHERE columnA= 'ABC' ORDER BY TIME DESC)
3 WHERE rownum <= 10
4 /
TIME COL
17/09/06 ABC
12/09/06 ABC
08/09/06 ABC
07/09/06 ABC
25/08/06 ABC
22/08/06 ABC
13/08/06 ABC
08/07/06 ABC
14/06/06 ABC
01/05/06 ABC
10 rows selected.
Elapsed: 00:00:01.03
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1434 Card=10 Bytes=120)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=1434 Card=110806 Bytes=1329672)
3 2 SORT (ORDER BY STOPKEY) (Cost=1434 Card=110806 Bytes=1329672)
4 3 TABLE ACCESS (FULL) OF 'TABLENAME' (Cost=552 Card=110806 Bytes=1329672)
SQL>
SQL> SELECT * FROM
2 (SELECT * FROM tablename WHERE columnA= 'MNO' ORDER BY TIME DESC)
3 WHERE rownum <= 10
4 /
TIME COL
20/09/06 MNO
19/09/06 MNO
16/09/06 MNO
14/09/06 MNO
13/09/06 MNO
10/09/06 MNO
06/09/06 MNO
05/09/06 MNO
03/09/06 MNO
02/09/06 MNO
10 rows selected.
Elapsed: 00:00:02.05
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=6219 Card=10 Bytes=120)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=6219 Card=555198 Bytes=6662376)
3 2 SORT (ORDER BY STOPKEY) (Cost=6219 Card=555198 Bytes=6662376)
4 3 TABLE ACCESS (FULL) OF 'TABLENAME' (Cost=552 Card=555198 Bytes=6662376)
SQL>
SQL> SELECT * FROM
2 (SELECT * FROM tablename WHERE columnA= 'STU' ORDER BY TIME DESC)
3 WHERE rownum <= 10
4 /
no rows selected
Elapsed: 00:00:00.00
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=6 Card=1 Bytes=12)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=6 Card=1 Bytes=12)
3 2 SORT (ORDER BY STOPKEY) (Cost=6 Card=1 Bytes=12)
4 3 TABLE ACCESS (BY INDEX ROWID) OF 'TABLENAME' (Cost=5 Card=1 Bytes=12)
5 4 INDEX (RANGE SCAN) OF 'I2' (NON-UNIQUE) (Cost=4 Card=1)
SQL> Nicolas. -
I ran the following query:
select
q1.ISO_COUNTRY_CODE q1country
,q3.ISO_COUNTRY_CODE q3country
,q1.LANGUAGE_CODE q1lang
,q3.LANGUAGE_CODE q3lang
,q1.POSTAL_CODE pcode1
,q3.POSTAL_CODE pcode3
,case when q1.POSTAL_CODE=q3.POSTAL_CODE then 1 else 0 end as "check"
from street3 q3
inner join street1 q1 on q1.PERM_ID=q3.PERM_ID
where
nvl(upper(q1.ISO_COUNTRY_CODE),'tempnull')=nvl(upper(q3.ISO_COUNTRY_CODE),'tempnull')
and nvl(upper(q1.LANGUAGE_CODE),'tempnull')=nvl(upper(q3.LANGUAGE_CODE),'tempnull')
--and q1.POSTAL_CODE=q3.POSTAL_CODE
and rownum<10
;Results were returned in less than a second:
Q1COUNTRY,Q3COUNTRY,Q1LANG,Q3LANG,PCODE1,PCODE3,check
USA,USA,ENG,ENG,49946,49946,1
USA,USA,ENG,ENG,49946,49946,1
USA,USA,ENG,ENG,49946,49946,1
USA,USA,ENG,ENG,49946,49946,1
USA,USA,ENG,ENG,49946,49946,1
... etc.
When I uncomment the line and q1.POSTAL_CODE=q3.POSTAL_CODE in the WHERE clause, however, the query takes forever to return. This doesn't make sense to me since the postcodes are equal in most cases anyway.TKPROF is almost always gross overkill. Certainly overkill until one exhausts what can be done using an explain plan. You are correct that AUTOTRACE requires a special role, and also requires the DBA runl a script which far too many do not know how to do. So the answer is to provide, any time you are asking for tuning help, an explain plan report as no special privileges are required.
You will find demos here:
http://www.morganslibrary.org/library.html
under Explain Plan
Post the SQL, the report, and your full version number for help. -
Query on object-relational data takes forever
hello all
i have a problem with a query performance... it seems like whenever i call a specific object function, the query executes very very slow. The results though are correct.
let me explain what i do... I have some relational tables, and i recreate the schema into an object relational one. Then i insert data from relational tables to object tables. I follow this tutorial: [A Sample Application Using Object-Relational Features|http://download.oracle.com/docs/cd/B12037_01/appdev.101/b10799/adobjxmp.htm]
these are the types that make up the transaction object table.
CREATE OR REPLACE TYPE TransactionItem_objtyp AS OBJECT
transItemID NUMBER,
Quantity NUMBER,
iValue NUMBER,
item_ref REF Item_objtyp
CREATE TYPE TransactionItemList_ntabtyp AS TABLE OF TransactionItem_objtyp;
CREATE OR REPLACE TYPE Transaction_objtyp AS OBJECT
transID NUMBER,
cust_ref REF Customer_objtyp,
transTameio NUMBER,
transDateTime DATE,
isStoreCustomer CHAR(1),
store_ref REF Store_objtyp,
transItemList_ntab TransactionItemList_ntabtyp,
MAP MEMBER FUNCTION
getTransID RETURN NUMBER,
MEMBER FUNCTION
getTotalCost RETURN NUMBER
);the function that causes the query to run very slow (fetching 10 rows per sec in a query that should return 130.000 rows) is the getTotalCost:
CREATE OR REPLACE TYPE BODY Transaction_objtyp AS
MAP MEMBER FUNCTION getTransID RETURN NUMBER IS
BEGIN
RETURN transID;
END;
MEMBER FUNCTION getTotalCost RETURN NUMBER IS
i INTEGER;
Total NUMBER := 0;
BEGIN
IF(UTL_COLL.IS_LOCATOR(transItemList_ntab))
THEN
SELECT SUM(L.Quantity * L.iValue) INTO Total
FROM TABLE(CAST(transItemList_ntab AS TransactionItemList_ntabtyp)) L;
ELSE
FOR i IN 1..SELF.transItemList_ntab.COUNT LOOP
Total := Total + SELF.transItemList_ntab(i).Quantity * SELF.transItemList_ntab(i).iValue;
END LOOP;
END IF;
RETURN ROUND(Total,2);
END;
END;the table transaction_objtab that contains the nested table is this
CREATE TABLE Transaction_objtab OF Transaction_objtyp(
PRIMARY KEY(transID),
FOREIGN KEY(cust_ref) REFERENCING Customer_objtab,
FOREIGN KEY(store_ref) REFERENCING Store_objtab)
OBJECT IDENTIFIER IS PRIMARY KEY
NESTED TABLE transItemList_ntab STORE AS TransItem_ntab (
(PRIMARY KEY(transItemID))
ORGANIZATION INDEX)
RETURN AS LOCATOR
ALTER TABLE TransItem_ntab ADD (SCOPE FOR (item_ref) IS Item_objtab);and this is how i insert the values into the transaction_objtab and the nested tables from the relational ones:
INSERT INTO Transaction_objtab
SELECT t.transID,
REF(c),
t.transTameio,
t.transDateTime,
t.isStoreCustomer,
REF(s),
TransactionItemList_ntabtyp()
FROM transactions t, Customer_objtab c, store_objtab s
WHERE t.transCustomer = c.custCode AND t.transStore = s.storeCode;
BEGIN
FOR i IN (SELECT DISTINCT transID FROM transactionItems) LOOP
INSERT INTO TABLE( SELECT p.TransItemList_ntab
FROM Transaction_objtab p
WHERE p.transID = i.transID)
SELECT transItemIDseq.nextval, t.Quantity, t.iValue, REF(i)
FROM transactionItems t, item_objtab i
WHERE t.transID = i.transID AND t.itemID = i.itemID;
END LOOP;
END;so whenever i use transaction_objtab t, t.getTotalCount() query takes for ever.
is there anything i do wrong?
sorry for this long post.
thanks in advanceSo, how many transactions? How many items? There is a whole series of questions I would normally ask at this point, because performance tuning is - to a certain extent - largely a matter of rote. But there's a more fundamental issue.
You are experiencing the problem with objects. They are cool enough when handling individual "things" but they suck when it comes to set-based processing. SQL and relational programming, on the other hand, excels at that sort of thing. So the question which has to asked is, why are you using objects for this project?
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Query takes large time to execute
Hi,
These are interview questions:
1. If the query takes lot of time to execute, what should be the preliminary analysis done by a DBA
2. If we have system, users, rollback and temporary tablespaces, 2 disks disk1 and disk2, how should the tablespaces be distributed on the disks
I am interested to know the answers. Kindly respond
Thanks and Regards
Sumit Sharma2. If we have system, users, rollback and temporary tablespaces, 2 disks disk1 and disk2, how should the tablespaces be distributed on the disks
2 disk are not enough for a good distribution but however you could the best possible with that.
Really the optimal distribution of disk must be so:
DISK1: Tablespaces of data, One Controlfile, Redo Logs ( 1 member per group )
DISK2: Redo Logs ( 1 member per group ), One Controlfile
DISK3: Tablespaces for Indexes, Redo Logs ( 1 member per group ), One Controlfile
DISK4: Archives, Rollback Segments
Joel Pérez
http://otn.oracle.com/experts -
Executing SP in MSSQL takes forever?!
Hi all,
I need to execute a stored procedure in our database server, MS SQL Server 2000 and it takes forever...
I'm using Microsoft SQL Server 2000 Driver for JDBC Version 2.2.0022
My code:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://myhost:1433;DatabaseName=MYDB;User=me;Password=secret");
CallableStatement cs = conn.prepareCall("{call my_sp(?,?)}");
cs.setString(1,"param1");
cs.setString(2,"param2");
long start = System.currentTimeMillis();
ResultSet rs = cs.executeQuery();
System.out.println("exec time: " + (System.currentTimeMillis() - start) + " ms");
...Every time I execute this piece of code, it takes between 45-50 seconds...
I have tried to execute my SP from DBVisualizer and it is the same result. But, when I execute my SP from Enterprise Manager it takes less than a second?! Why? What have I missed? Does anybody recognize this problem?
Greatfull for any suggestions...
Cheers
//Anders =)For a single call, Statement is better in performance.This depends on the driver and the database. If you care about the last few milliseconds per call, measure your setup!
According to my measurements, in Oracle Statement and PreparedStatement are exactly the same speed for the first call, and PreparedStatement is faster on subsequent calls.
<speculation>
In some databases, the driver needs to do two round trip calls for the first execution of a PreparedStatement:
driver: Please prepare "select x from y where z = ?".
database: Prepared, you can refer to that as "statement 7".
driver: Execute statement 7 with parameter 42.
database: Done, here is the result set: <...>
In other databases, there is only one call:
driver: Prepare "select x from y where z = ?" and execute with parameter 42.
database: Use "statement 7" in later calls, and here is the result set: <...>
Depends on the database protocol which form is possible. In both cases, second, third, etc calls only need one step, so they are faster.
Another factor that affect PreparedStatement speed is how much work the database does to prepare something. Some databases may invoke a more time consuming compilation process for a PS than a plain Statement.
</speculation> -
What is the reason for query take more time to execute
Hi,
What is the reason for the query take more time inside procedure.
but if i execute that query alone then it excute within a minutes.
query includes update and insert.I have a insert and update query when I execute
without Procedure then that query execute faster but
If I execute inside procedure then It takes 2 hours
to execute.Put you watch 2 hours back and the problem will disappear.
do you understand what I want to say?I understood what you wanted to say and I understood you didn't understood what I said.
What does the procedure, what does the query, how can you say the query does the same as the procedure that takes longer. You didn't say anything useful to have an idea of what you're talking about.
Everyone knows what means that something is slower than something else, but it means nothing if you don't say what you're talking about.
To begin with something take a look at this
When your query takes too long ...
especially the part regarding the trace.
Bye Alessandro -
Urgen!! Query takes lots of time to execute and the production is in effect
Hi,
We have some data loading script. This scripts takes lots of time to execute. As Iam new to tunning please do let me know what is the wrong with the query !!
Thanks In advance
Query:
=========
INSERT /*+ PARALLEL */ INTO ris.ris_pi_profile
(ID,COUNTRY_OF_CITIZENSHIP,IMMIGRATION_STATUS,SSN,DOB,GENDER,
ETHNICITY,RACE,DEPARTMENT,DIVISION,INSTITUTION_ID,INST_EMAIL,EFFECT_DATE,ACADEMIC_TITLE,ACADEMIC_POSITION,
OTH_PER_DATA,PCT_RESEARCH,PCT_TEACHING,PCT_CLINICAL,PCT_ADMIN,PCT_OTHER,PCT_TRAINING)
SELECT
ap.id,
p.citizen_cd,
decode(p.visa_cd,'CV',0,'F1',1,'H1',2,'H1B',3,'H2',4,'J1',5,'J2',6,'O1',7,'PR',8,'PRP',9,'TC',10,'TN',11,'TNN',12),
(select n.soc_sec_num from sa.name n where n.name_id = p.name_id),
(select n.birth_date from sa.name n where n.name_id = p.name_id),
(select decode(n.gender_cd,'F',1,'M',2,0) from sa.name n where n.name_id = p.name_id),
(select decode(n.ethnic_cd,'H',1) from sa.name n where n.name_id = p.name_id),
(select decode(n.ethnic_cd,'A',2,'B',3,'I',1,'P',4,'W',5) from sa.name n where n.name_id = p.name_id),
a.dept_name,
a.div_name,
a.inst_id,
(select n.email from sa.name n where n.name_id = p.name_id),
a.eff_date,
ac.acad_pos_desc,
p.acad_pos_cd,
0,
p.research_pct,
p.teach_pct,
p.patient_pct,
p.admin_pct,
p.other_pct,
p.course_pct
FROM
appl1 ap,
sa.personal_data p,
sa.address a,
sa.academic_pos_cd ac,
profile_pi f
WHERE
p.project_role_cd='PI'
and ap.appl_id=f.appl_id
and p.appl_id=f.appl_id
and p.name_id=f.name_id
and a.addr_id=f.addr_id
and p.acad_pos_cd=ac.acad_pos_cd
AND EXISTS (select 1 from ris.ris_institution i WHERE i.id = a.inst_id)
AND EXISTS (select 1 from sa.academic_pos_cd acp WHERE acp.acad_pos_cd = p.acad_pos_cd);
In the execution PLan I see lots of Nested loop, Hash Join
Index( Unique scan)
Table Access by ( Index rowid)
This query is fast in Test DB but ver very slow in prod DB. Need your help Urgent.
MinazWhen your query takes too long...
When your query takes too long ... -
Query run: takes ages to execute!
Hi,
I had created a query ( on cube which has roughly 497000 records ).
when i am trying to execute it, a pop up message will comes up after half an hour so saying that result has exceeded xxxxxx rows: and then after a while a affirmation of result is incomplete!
even after these two messages it never has given any out put! it is still running!
what could be done to see the results of the query?
I had removed all the chars in rows area except one and placed in free char area!
But the issue remains an issue
Any suggestions?
Thanks,
Ravi1. Run your query in RSRT with execute and Debug option
2. Check Display SQL Query in Database tab.
3. View your result and you will know which aggregates / tables its using and their selection.
4. Based on the SQL result you can fine tune your selection.
5. Try to run your selection with small range.
Hope this helps...
Maybe you are looking for
-
XML tags in an "export : XML" Report Template
Hi All, I'm using the export XML report template to produce XML from a query. One of the column contains XML tags and the template is translating eg: if the column is "Groups" then I get: <Groups>& lt ;Group& gt ;Sales & lt ;/Group & gt ; & lt ;Group
-
Document Type is Changing While Doing Credit Memo
Hi Experts, I am doing the AR Credit Memo, based on (copy from) AR Invoice, Once i copied all the data, i am just adding the document. While adding the document, system popups the serial number selection screen, ( my items are managed by serial numbe
-
PCG Seed Data Invalid characters displayed in FRC
Hi, I'm not certain this is the correct forum or not. Customer has PCG 7.3.2 on 11i, using FRC. Many menus and concurrent program names & messages (all seed data) that use accents, are displaying garbled characters. eg: GRC Controls : Règles associÃ
-
ITunes 11.01.1.2 - Search Bar has disappeared.
I'm running the latest version of ITunes on a Windows machine. As far as I know, we haven't updated it recently - think it has been updated for a while. I opened ITunes this morning after using it successfully in the last couple of days and the Sear
-
[Oracle 10g] Download of add_job_email_notification package
Hi, Does anyone have the link to the download the add_job_email_notification package for Oracle 10g? I googled, but didn't find it, only a link that doesn't exist anymore. Thanks is advance