Getting statistics of Query Plan
Hi,
I have deployed a simple application on OEP default server (in localhost) in Eclipse. I can see the results in console when the generator send messages to port 9200. Also I can see the app is RUNNING when I check Event Processing Visualizer (http://localhost:9002/wlevs/)
However, in Query plan page, the stat result is always 0 for all the operators... I have take a look at all the related documentation but I couldn't resolve the problem.
Cheers,
Alireza
Dear XiYing,
Still zero stats even after enabling!
Here is my config:
<?xml version="1.0" encoding="UTF-8"?>
<wlevs:config xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application"
xmlns:jdbc="http://www.oracle.com/ns/ocep/config/jdbc">
<cql>
<stats-enabled>true</stats-enabled>
</cql>
<processor>
<name>CarSegStrQueryProcessor</name>
<rules>
<query id="CarSegStrQuery"> <![CDATA[ select car_id, speed, exp_way, lane, dir, (x_pos/52800) as seg from AdapterOutputChannel ]]> </query>
</rules>
</processor>
</wlevs:config>
Cheers,
Alireza
Similar Messages
-
Select Query Hangs / No DB Locks / Query Plan is good
I have below query in application which hangs ( Only sometimes ) and there are some session which also try to insert data into this tables also starts getting hanged.
SELECT DISTINCT F2 || ' - ' || F3 || ' - ' || F4
FROM Table1
WHERE F4 = 6160
AND F1|| F2|| F3 NOT IN (
SELECT F2|| F3 || F4
FROM Table2
WHERE F1 = 181)
F2 - varchar(4)
F3- varchar(100)
F4- varchar(20)
F1,F1 are NUMBER
Table1 has one unique index comprising all fields in ORDER F1,F2, X,F3, F4,Y - X,Y are some different field.
Table2 has one unique index comprising all fields in ORDER F1,F3, F4,F2 are some different field.
Below are facts from DBA ----
1- Session Query Plan was excellent -
2 - No tables were locked in DB
3 - Statistics on this table Table1 was calculated on Feb, 2008 and shows 8 millions rows but actual current row count is 13 million. DBA says sometime analyzing statistics again may cause poor query performance.
4- There were 8 session in DB, 1 was for above select statement and other 7 were trying to insert data into above table.
Can you please advise what could else be verified to root cause issue as it has been hanging many times - hence causing other session to hang ?
Many ThanksCan you clarify exactly what the DBA meant by "No tables were locked in DB"? What was the exact query that was used to determine this? Was it hitting V$LOCK (GV$LOCK in a RAC system)? Or the DBA_BLOCKERS and DBA_WAITERS tables? Or something else? The specific query here is important because there is a world of difference between a row-level lock and a table-level lock. Of course, locks would never prevent a SELECT statement from running, but it could cause problems for the INSERT statements.
I strongly concur with Old DBA's suggestion about refactoring the query to not do the concatenation in the NOT IN clause.
Are the F4 = 6160 and F1 = 181 conditions really using hard-coded numeric literals? Or are these bind variables? Is the data in F1 or F4 skewed-- that is, are there certain values that are more likely than other values?
How many rows would you expect to be in Table1 with an F4 value of 6160? How many rows in Table2 with a F1 value of 181?
Justin -
Merge cartesian join in query plan
Hi All
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
I am trying to sue dynamic sampling, but it doesn't seem to work.
please help on this.user8650395 wrote:
Hi All
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
I am trying to sue dynamic sampling, but it doesn't seem to work.
please help on this.Interesting.
There was a a thread a day or two ago about when dynamic sampling does not work. You can search OTN for it if you like. Also check the docs to make sure that dynamic sampling works with GTTS
One problem with GTTS is getting accurate statistics. Have you considered using DBMS_STATISTICS to set the statistics on the table to adjust the cardinality?
Your cardinality of 1 sounds incorrect. In theory a cartesian join against one row should be painelss; unfortunately your cardinality figure seems to be off! Sometimes in cases like yours the cost-based optimizer will choose a Cartesian join even when the table joins are properly specified. -
We are getting multiple 8623 Errors in SQL Log while running Vendor's software.
How can you catch which Query causes the error?
I tried to catch it using SQL Profiler Trace but it doesn't show which Query/Sp is the one causing an error.
I also tried to use Extended Event session to catch it, but it doesn't create any output either.
Error:
The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that
reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.
Extended Event Session that I used;
CREATE EVENT SESSION
overly_complex_queries
ON SERVER
ADD EVENT sqlserver.error_reported
ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.database_id, sqlserver.username)
WHERE ([severity] = 16
AND [error_number] = 8623)
ADD TARGET package0.asynchronous_file_target
(SET filename = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xel' ,
metadatafile = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xem',
max_file_size = 10,
max_rollover_files = 5)
WITH (MAX_DISPATCH_LATENCY = 5SECONDS)
GO
-- Start the session
ALTER EVENT SESSION overly_complex_queries
ON SERVER STATE = START
GO
It creates only .xel file, but not .xem
Any help/advice is greatly appreciatedHi VK_DBA,
According to your error message, about which query statement may fail with error message 8623, as other post, you can use trace flag 4102 & 4118 for overcoming this error. Another way is looking for queries with very long IN lists, a large number of
UNIONs, or a large number of nested sub-queries. These are the most common causes of this particular error message.
The error 8623 occurs when attempting to select records through a query with a large number of entries in the "IN" clause (> 10,000). For avoiding this error, I suggest that you could apply the latest Cumulative Updates media for SQL Server 2012 Service
Pack 1, then simplify the query. You may try divide and conquer approach to get part of the query working (as temp table) and then add extra joins / conditions. Or You could try to run the query using the hint option (force order), option (hash join), option
(merge join) with a plan guide.
For more information about error 8623, you can review the following article.
http://blogs.technet.com/b/mdegre/archive/2012/03/13/8623-the-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan.aspx
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support -
How to setup a query plan in effective at any time for SP or SQL query?
I have a SP which include a group by SQL statement. It retrieve data from a couple of tables which are over 1G size,
When I run this SP at first time, it take more than 5 minutes to get the result. then I run it again and again, Finally, it become very quick, I can get the result within second.
Not sure why. I guess it is because of query plan.
How to make it running at first time to get result within second? How to force a better best query plan in effective at first time to run the query?
If the engine has better plan in memory, could it be lost at some point? because I have the complain from end user said some times it is fast, sometime it is very slow.
How to resolve this problem?thanks, kevin. Here is the pesudo query( I modify table name as business rule from my company). you are right, mytab3 is a lookup table.
Select d.stock,i.description,c.categoryname,
Round(IsNull(Sum(d.qty),0),2) AS qty,
From mytab1 d,mytab2 s,invent i,mytab3 c
Where
d.stock != 'param1'
And d.id1 = s.id1 --id1: univarchar(11)
And i.code = c.code --code:univarchar(2)
And d.stock = i.stock --stock: univarchar(12)
And i.code2 = d.code2 --code2: univarchar(2)
And d.code2 = 'param2'
And s.id2 = 'param3' --id2: univarchar(6)
Group By c.categoryname,d.stock,i.description
Order By d.stock
here is the query plan when run this query:
The command completed with no results returned
QUERY PLAN FOR STATEMENT 1 (at line 1).
Executed in parallel by coordinating process and 4 worker processes.
STEP 1
The type of query is SELECT (into Worktable1).
GROUP BY
Evaluate Grouped SUM OR AVERAGE AGGREGATE.
Evaluate Grouped SUM OR AVERAGE AGGREGATE.
Evaluate Grouped SUM OR AVERAGE AGGREGATE.
Executed in parallel by coordinating process and 4 worker processes.
FROM TABLE
mytab2
s
Nested iteration.
Index : ind_mytab2 _id2
Forward scan.
Positioning by key.
Keys are:
id2 ASC
Executed in parallel with a 4-way hash scan.
Using I/O Size 16 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
mytab1
d
Nested iteration.
Index : ind_det_inv
Forward scan.
Positioning by key.
Keys are:
id1 ASC
Using I/O Size 16 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
invent
i
Nested iteration.
Using Clustered Index.
Index : invent_pk
Forward scan.
Positioning by key.
Keys are:
stock ASC
code2 ASC
Using I/O Size 2 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
mytab3
c
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 2 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
TO TABLE
Worktable1.
Parallel work table merge.
STEP 2
The type of query is INSERT.
The update mode is direct.
Executed by coordinating process.
Worktable2 created, in allpages locking mode, for ORDER BY.
FROM TABLE
Worktable1.
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 8 Kbytes for data pages.
With MRU Buffer Replacement Strategy for data pages.
TO TABLE
Worktable2.
STEP 3
The type of query is SELECT.
Executed by coordinating process.
This step involves sorting.
FROM TABLE
Worktable2.
Using GETSORTED
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 8 Kbytes for data pages.
With MRU Buffer Replacement Strategy for data pages.
Total estimated I/O cost for statement 1 (at line 1): 1409882.
The sort for Worktable2 is done in Serial -
Oracle 10g:
I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:
select * from (select * from A where b = 1) where ROWNUM < 1000 becomes very slow:
Query Plan for select * from A where b = 1 (Query is just an example):
Rows Plan
208912 SELECT STATEMENT
208912 SORT ORDER BY
208912 HASH JOIN RIGHT OUTER
408 INDEX FULL SCAN PK_BAD_ACK_TASK
208912 HASH JOIN RIGHT OUTER
16 INDEX FULL SCAN PK_INFORMATIONAL_TASK
208912 HASH JOIN RIGHT OUTER
1 INDEX FULL SCAN PK_SYSTEM_ERROR_TASK
208912 HASH JOIN RIGHT OUTER
1 INDEX FULL SCAN PK_REJECTED_TRANSMISSION
208912 HASH JOIN RIGHT OUTER
1 INDEX FULL SCAN PK_ONHOLD_TASK
208912 HASH JOIN RIGHT OUTER
329465 INDEX FAST FULL SCAN PK_FAILED_MESSAGE
208912 TABLE ACCESS FULL TASK
Query when I add ROWNUM (slow query as mentioned above):
Rows Plan
999 SELECT STATEMENT
<NULL> COUNT STOPKEY
208912 VIEW
208912 SORT ORDER BY STOPKEY
208912 HASH JOIN RIGHT OUTER
408 INDEX FULL SCAN PK_BAD_ACK_TASK
208912 NESTED LOOPS OUTER
208912 NESTED LOOPS OUTER
208912 NESTED LOOPS OUTER
208912 HASH JOIN RIGHT OUTER
329465 INDEX FAST FULL SCAN PK_FAILED_MESSAGE
208912 HASH JOIN RIGHT OUTER
16 INDEX FULL SCAN PK_INFORMATIONAL_TASK
208912 TABLE ACCESS FULL TASK
1 INDEX FAST FULL SCAN PK_ONHOLD_TASK
1 INDEX FAST FULL SCAN PK_REJECTED_TRANSMISSION
1 INDEX FAST FULL SCAN PK_SYSTEM_ERROR_TASKuser628400 wrote:
Oracle 10g:
I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:Some notes:
* When using ROWNUM the cost based optimizer switches to a FIRST_ROWS_N mode, this might explain the significant difference in the execution plan
* Try to get a more meaningful output using DBMS_XPLAN.DISPLAY
* Since you're already on 10g, try to compare the actual cardinalities to the estimates using DBMS_XPLAN.DISPLAY_CURSOR with the "ALLSTATS LAST" option and the GATHER_PLAN_STATISTICS hint.
See e.g. here for more information how to do it: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
This way you should be able to tell where the optimizer assumptions go wrong so that it thinks that the second one is better than the first one
A simple remedy you might want to try that should get you back to plan 1 is the following:
select * from (
select ROWNUM as rn, a.* from (select * from A where b = 1 ORDER BY<your_order_criteria>) a
where rn < 1000;Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
Edited by: Randolf Geist on Jan 11, 2009 9:33 PM
Added the obvious sort ORDER BY -
Conversion away from column type may result in sub-optimal query plan
Hello all,
I have the following select statement in a cursor compiled in a package.
SELECT id
FROM table
WHERE TRUNC(ts) >= TRUNC(SYSDATE - p_days)
However I get 4 warnings that read:
PLW-07204: conversion away from column type may result in sub-optimal query plan
Does anyone know of a way to rewrite the query to avoid the compilation warnings?
I'm just trying to compare the date without the time...
Thanks in advance
DanFor what it is worth, whenever you compare a date column to either sysdate or any built-in function returning a date you will get that warning.
SQL> desc t
Name Null? Type
ID NUMBER
DT DATE
SQL> SELECT DUMP(dt), DUMP(trunc(dt)), dump(sysdate)
2 FROM t;
DUMP(DT) DUMP(TRUNC(DT)) DUMP(SYSDATE)
Typ=12 Len=7: 120,107,7,12,15,16,43 Typ=13 Len=8: 7,215,7,12,0,0,0,0 Typ=13 Len=8: 7,215,7,12,14,16,11,0But,
SQL> CREATE FUNCTION f(p_v IN VARCHAR2) RETURN DATE AS
2 BEGIN
3 RETURN TO_DATE(p_v, 'dd-mon-yyyy');
4 END;
5 /
Function created.
SQL> SELECT DUMP(f('01-jan-2000')) FROM dual;
DUMP(F('01-JAN-2000'))
Typ=12 Len=7: 120,100,1,1,1,1,1John -
Hi,
I'm trying to get statistics from a variety of related tables
where the statistical counts are based on comparing the value on
one table with an equivalent value on a second table (and I want to
view the results grouped by time period, day, week, month, etc);
e.g.
Consider two tables - Customer & Customer_Action which
are related as a one-to-many (one customer can take many actions):
Customer: id, create_date, customer_name, etc.
Customer_Action: id, customer_id, create_date, action, etc.
If the customer took their first action at the same time as
they registered on the system (i.e. if the customer record was
created at the same time as the very first action record)
YES_count is incremented by 1 else
NO_count is incremented by 1
So running the query against the database the report would
look something like:
Customers Yes No
January 8 5 3
February 14 9 5 .... Etc.
I've tried this around a number of different ways but always
seem to end up with double counting in one way or another: see this
sample data
Customer Create_Date Action_Date
01 05/07/2008 12:36 05/07/2008 12:36
01 05/07/2008 12:36 28/08/2008 22:22
02 10/07/2008 12:04 10/07/2008 12:04
03 10/07/2008 12:12 10/07/2008 12:12
This should give me
Count Yes No
July 3 3 0
...... but I get always get a customer counts of 4 2 2!
My current statement is .....
SELECT count( m2u_Customer.id ) AS Customer,
min( m2u_Customer_Action.action_date ) AS 'Action_Date',
DATE_FORMAT( m2u_Customer.create_date, '%m-%M' ) AS Month,
sum(case when m2u_Customer.create_date =
m2u_Customer_Action.create_date then 1 else 0 end) as Yes,
sum(case when m2u_Customer.create_date !=
m2u_Customer_Action.create_date then 1 else 0 end) as No
FROM m2u_Customer
LEFT JOIN m2u_Customer_Action ON ( m2u_Customer.id =
m2u_CustomerAction.customer_ id )
WHERE m2u_Customer.create_date > '2008-07-02'
AND m2u_Customer.create_date < '2008-08-01'
GROUP BY DATE_FORMAT( m2u_Customer.create_date, '%m-%M' )
Can this be done?
Regards.
PatrickIn the default php.ini is set open_basedir which limits work with php only to few directories (and directories bellow them). There is set /srv/http, /home,/tmp and /usr/share/pear by default.
To allow your vhost you should add /data/www or set empty value. -
Logging level to get the physical query
Hi All,
Can anyone let me know , what log level i have set it up, so that I can get the physical query for BI Answers request.
Thanks
Shi,
Logging Levels
Level 0
No logging.
Level 1
Logs the SQL statement issued from the client application.
Logs elapsed times for query compilation, query execution, query cache processing, and back-end database processing.
Logs the query status (success, failure, termination, or timeout). Logs the user ID, session ID, and request ID for each query.
Level 2
Logs everything logged in Level 1.
Additionally, for each query, logs the repository name, business model name, presentation catalog (called Subject Area in Answers) name, SQL for the queries issued against physical databases, queries issued against the cache, number of rows returned from each query against a physical database and from queries issued against the cache, and the number of rows returned to the client application.
Level 3
Logs everything logged in Level 2.
Additionally, adds a log entry for the logical query plan, when a query that was supposed to seed the cache was not inserted into the cache, when existing cache entries are purged to make room for the current query, and when the attempt to update the exact match hit detector fails.
Do not select this level without the assistance of Technical Support.
Level 4
Logs everything logged in Level 3.
Additionally, logs the query execution plan. Do not select this level without the assistance of Technical Support.
Level 5
Logs everything logged in Level 4.
Additionally, logs intermediate row counts at various points in the execution plan. Do not select this level without the assistance of Technical Support.
Level 6 and 7
Reserved for future use.
Hope this helps,
cheers,
vineeth -
Help me to reduce buffer gets of following query
Buffer gets with this query is 460K.
We want to reduce it drastically.
SELECT temp21.resource_code
,temp21.employee_type employee_type
,temp21.resource_name resource_name
,temp21.manager_id
,temp21.manager_name
,temp21.period_start
,temp21.period_finish
,temp21.avail_hours
,temp21.act_hours
,temp21.timesheet_status timesheet_status
,temp21.email,temp21.ouc
,temp21.work_country
,f.level1_unit_id level1_id
,f.level2_unit_id level2_id
,f.level3_unit_id level3_id
,f.level4_unit_id level4_id
,f.level5_unit_id level5_id
,f.level6_unit_id level6_id
,f.level7_unit_id level7_id
,f.level8_unit_id level8_id
,f.level9_unit_id level9_id
,f.level10_unit_id level10_id
,f.level1_name
,f.level2_name
,f.level3_name
,f.level4_name
,f.level5_name
,f.level6_name
,f.level7_name
,f.level8_name
,f.level9_name
,f.level10_name
FROM (SELECT avail.res_id
,avail.resource_code
,avail.employee_type
,avail.person_type
,avail.resource_name
,avail.manager_id
,avail.manager_name
,avail.period_start
,avail.period_finish
,avail.avail_hours
,NVL(act.act_hours,0) act_hours
,act.timesheet_status
,avail.prid
,avail.email
,avail.ouc
,avail.work_country
FROM (SELECT /*+ALL_ROWS*/r.id res_id
,lk.name employee_type
,r.unique_name resource_code
,r.person_type
,r.first_name||' '||r.last_name resource_name
,r.manager_id manager_id
,r1.first_name||' '||r1.last_name manager_name
,TRUNC(tp.prstart) period_start
,TRUNC(tp.prfinish - 1) period_finish
,NVL(o.gs_hrs_avail_week,0) avail_hours
,r.email
,o.ouc
,o.work_country
,tp.prid
FROM niku.ODF_CA_RESOURCE o
,niku.SRM_RESOURCES r
,niku.SRM_RESOURCES r1
,niku.PRTIMEPERIOD tp
,niku.CMN_SEC_USER_GROUPS usr_grp
,niku.CMN_SEC_GROUPS grp
,(SELECT
NLS.NAME
,LKP.ID
FROM CMN_CAPTIONS_NLS NLS,CMN_LOOKUPS LKP
WHERE NLS.PK_ID=LKP.ID
AND LKP.LOOKUP_TYPE='SRM_RESOURCE_TYPE'
AND NLS.TABLE_NAME='CMN_LOOKUPS'
AND NLS.LANGUAGE_CODE='en') lk
WHERE r.id=o.id
AND r1.user_id(+)=r.manager_id
AND r.user_id=usr_grp.user_id
AND usr_grp.GROUP_ID=grp.id
AND r.person_type=lk.id
AND r.is_active = 1
AND r1.is_active = 1
AND grp.GROUP_CODE='gs_tb'
AND tp.prisopen = 1
) avail
,(SELECT r.id
,tp.prid
,SUM(NVL(practsum,0)/3600) act_hours
,ts.prstatus timesheet_status
FROM niku.SRM_RESOURCES r
,niku.PRTIMESHEET ts
SELECT /*+ALL_ROWS*/ MAX(prid) prid
,prtimeperiodid
,prresourceid
FROM niku.prtimesheet
GROUP BY prtimeperiodid,prresourceid
) ts_new
,niku.PRTIMEENTRY te
,niku.PRTIMEPERIOD tp
,niku.CMN_SEC_USER_GROUPS usr_grp
,niku.CMN_SEC_GROUPS grp
WHERE ts.prid=ts_new.prid
AND ts.prtimeperiodid=ts_new.prtimeperiodid
AND ts.prresourceid=ts_new.prresourceid
AND r.id=ts.PRRESOURCEID
AND ts.PRID=te.PRTIMESHEETID
AND ts.PRTIMEPERIODID=tp.prid
AND usr_grp.USER_ID=r.USER_ID
AND grp.id=usr_grp.group_id
AND r.is_active=1
AND tp.PRISOPEN=1
AND ts.prstatus not in(0,2,5)
AND grp.group_code='gs_tb'
AND TRUNC(tp.PRSTART) >= TRUNC(TO_DATE('7/24/2006','MM/DD/YYYY HH:MI:SS AM'))
AND TRUNC(tp.PRFINISH-1) <= TRUNC(TO_DATE('9/25/2006','MM/DD/YYYY HH:MI:SS AM'))
GROUP BY r.ID
,tp.PRID
,ts.prstatus) act
WHERE act.id(+) = avail.res_id
AND act.prid(+) = avail.prid
AND (avail.avail_hours - NVL(act.act_hours,0) > 0))temp21
,prj_obs_associations o1
,nbi_dim_obs f
WHERE 1=1
AND temp21.prid in (SELECT prid
FROM PRTIMEPERIOD
WHERE TRUNC(PRSTART) >= TRUNC(TO_DATE('7/24/2006','MM/DD/YYYY HH:MI:SS AM'))
AND TRUNC(PRFINISH-1) <= TRUNC(TO_DATE('9/25/2006','MM/DD/YYYY HH:MI:SS AM'))
AND
temp21.res_id = o1.record_id
AND o1.unit_id = f.obs_unit_id
AND o1.table_name = 'SRM_RESOURCES'
AND f.obs_type_id = 5000009
AND f.level5_unit_id = 5013334
ORDER BY temp21.manager_name
,temp21.manager_id
,temp21.resource_name
,temp21.resource_code
,temp21.period_start
,temp21.period_finish
,temp21.timesheet_status...Also
AND TRUNC(tp.PRSTART) >= TRUNC(TO_DATE('7/24/2006','MM/DD/YYYY HH:MI:SS AM'))
AND TRUNC(tp.PRFINISH-1) <= TRUNC(TO_DATE('9/25/2006','MM/DD/YYYY HH:MI:SS AM'))Although this won't fail, you have specified the time portion of the date without supplying data to be converted....which you don't need as it will automatically be set to midnight if you don't specify it.
In addition, you are applying the TRUNC function to the column you are comparing which will prevent any indexes from being used. You should perform the arithmetic on the litterals, not the columns, and set up the range correctly:
AND tp.PRSTART >= TO_DATE('7/24/2006','MM/DD/YYYY)
AND tp.PRFINISH < TO_DATE('9/25/2006','MM/DD/YYYY) + 2This should yeild the same result and will allow any indexes to be used.
Without a formatted execution plan and more info from you, this is just a wild guess as to what part of the problem might be.
HTH
David
After a further look, the cartesian product appears to be in the bold section:
SELECT
temp21.resource_code
,temp21.employee_type employee_type
,temp21.resource_name resource_name
,temp21.manager_id
,temp21.manager_name
,temp21.period_start
,temp21.period_finish
,temp21.avail_hours
,temp21.act_hours
,temp21.timesheet_status timesheet_status
,temp21.email,temp21.ouc
,temp21.work_country
,f.level1_unit_id level1_id
,f.level2_unit_id level2_id
,f.level3_unit_id level3_id
,f.level4_unit_id level4_id
,f.level5_unit_id level5_id
,f.level6_unit_id level6_id
,f.level7_unit_id level7_id
,f.level8_unit_id level8_id
,f.level9_unit_id level9_id
,f.level10_unit_id level10_id
,f.level1_name
,f.level2_name
,f.level3_name
,f.level4_name
,f.level5_name
,f.level6_name
,f.level7_name
,f.level8_name
,f.level9_name
,f.level10_name
FROM ( SELECT
avail.res_id
,avail.resource_code
,avail.employee_type
,avail.person_type
,avail.resource_name
,avail.manager_id
,avail.manager_name
,avail.period_start
,avail.period_finish
,avail.avail_hours
,NVL(act.act_hours,0) act_hours
,act.timesheet_status
,avail.prid
,avail.email
,avail.ouc
,avail.work_country
FROM ( SELECT /*+ALL_ROWS*/
r.id res_id
,lk.name employee_type
,r.unique_name resource_code
,r.person_type
,r.first_name||' '||r.last_name resource_name
,r.manager_id manager_id
,r1.first_name||' '||r1.last_name manager_name
,TRUNC(tp.prstart) period_start
,TRUNC(tp.prfinish - 1) period_finish
,NVL(o.gs_hrs_avail_week,0) avail_hours
,r.email
,o.ouc
,o.work_country
,tp.prid
FROM
niku.ODF_CA_RESOURCE o
,niku.SRM_RESOURCES r
,niku.SRM_RESOURCES r1
,niku.PRTIMEPERIOD tp
,niku.CMN_SEC_USER_GROUPS usr_grp
,niku.CMN_SEC_GROUPS grp
,( SELECT
NLS.NAME
,LKP.ID
FROM
CMN_CAPTIONS_NLS NLS,
CMN_LOOKUPS LKP
WHERE
NLS.PK_ID=LKP.ID
AND LKP.LOOKUP_TYPE='SRM_RESOURCE_TYPE'
AND NLS.TABLE_NAME='CMN_LOOKUPS'
AND NLS.LANGUAGE_CODE='en'
) lk
WHERE r.id=o.id
AND r1.user_id(+)=r.manager_id
AND r.user_id=usr_grp.user_id
AND usr_grp.GROUP_ID=grp.id
AND r.person_type=lk.id
AND r.is_active = 1
AND r1.is_active = 1
AND grp.GROUP_CODE='gs_tb'
AND tp.prisopen = 1
) avail
,( SELECT
r.id
,tp.prid
,SUM(NVL(practsum,0)/3600) act_hours
,ts.prstatus timesheet_status
FROM
niku.SRM_RESOURCES r
,niku.PRTIMESHEET ts
,( SELECT /*+ALL_ROWS*/
MAX(prid) prid
,prtimeperiodid
,prresourceid
FROM
niku.prtimesheet
GROUP BY
prtimeperiodid,
prresourceid
) ts_new
,niku.PRTIMEENTRY te
,niku.PRTIMEPERIOD tp
,niku.CMN_SEC_USER_GROUPS usr_grp
,niku.CMN_SEC_GROUPS grp
WHERE
ts.prid=ts_new.prid
AND ts.prtimeperiodid=ts_new.prtimeperiodid
AND ts.prresourceid=ts_new.prresourceid
AND r.id=ts.PRRESOURCEID
AND ts.PRID=te.PRTIMESHEETID
AND ts.PRTIMEPERIODID=tp.prid
AND usr_grp.USER_ID=r.USER_ID
AND grp.id=usr_grp.group_id
AND r.is_active=1
AND tp.PRISOPEN=1
AND ts.prstatus not in(0,2,5)
AND grp.group_code='gs_tb'
AND TRUNC(tp.PRSTART) >= TRUNC(TO_DATE('7/24/2006','MM/DD/YYYY HH:MI:SS AM'))
AND TRUNC(tp.PRFINISH-1) <= TRUNC(TO_DATE('9/25/2006','MM/DD/YYYY HH:MI:SS AM'))
GROUP BY r.ID
,tp.PRID
,ts.prstatus
) act
WHERE act.id(+) = avail.res_id
AND act.prid(+) = avail.prid
AND (avail.avail_hours - NVL(act.act_hours,0) > 0)
)temp21
,prj_obs_associations o1
,nbi_dim_obs f
WHERE 1=1
AND temp21.prid in ( SELECT prid
FROM PRTIMEPERIOD
WHERE TRUNC(PRSTART) >= TRUNC(TO_DATE('7/24/2006','MM/DD/YYYY HH:MI:SS AM'))
AND TRUNC(PRFINISH-1) <= TRUNC(TO_DATE('9/25/2006','MM/DD/YYYY HH:MI:SS AM'))
AND
temp21.res_id = o1.record_id
AND o1.unit_id = f.obs_unit_id
AND o1.table_name = 'SRM_RESOURCES'
AND f.obs_type_id = 5000009
AND f.level5_unit_id = 5013334
ORDER BY temp21.manager_name
,temp21.manager_id
,temp21.resource_name
,temp21.resource_code
,temp21.period_start
,temp21.period_finish
,temp21.timesheet_status Message was edited by:
david_tyler -
Query Plan Question for Outer Join
I have the following join query:
select unique ep.ACT_UID,
ep.SE_REQ_TS,
sr.SERVICE_NM
from
eaisvcs.Service_requests sr,
eaisvcs.SERVICE_EPISODE ep
where
ep.ACT_UID = sr.ACT_UID;
I have an index on the act_uid in both tables, and the statistics are up-to-date. There are about 3.2 million rows in each table. 10% of the act_uid's that are in the ep table that do not have a match in the sr table. Other than that, most id's match up between the tables.
Here is the query plan:
ID PARENT_ID OPERATION OPTIONS
0 SELECT STATEMENT
1 0 SORT UNIQUE
2 1 MERGE JOIN
3 2 SORT JOIN
4 3 TABLE ACCESS FULL
5 2 SORT JOIN
6 5 TABLE ACCESS FULL
I cannot figure out why a table scan is being performed every time on both tables. The Act_UID is the PK in the ep table. There is a composite index (act_uid, sev_seq_no) in the sr table. the act_id is a varchar2 column in both tables. The sev_seq_no column is numeric.
Any ideas or insights about this would be greatly appreciated.
Thanks!The plan can be good.
Oracle choose a full table scan for these reason too:
- sr.SERVICE_NM is not a part of the index and so a full table scan is less expensive. If you will add this field to your composite index Oracle will probably take this new index.
Bye, Aron -
Calculating estimated rows in query plan
Hi,
I'm trying to do one calculation over statistics, but I can't achieve the correct value.
The query is the following:
select * from product where
productid between 1387 and 1392
The result for estimated rows is 5,81583.
The histogram:
Considering the Avg_Range_Rows field the result should be 6, so I suppose this field is rounded.
Trying to do the calculation, I notice there are 132 possible key values between the two histogram keys. There are 126 rows (range_rows), so 126/132 = 0.95454545 . Multiply by 6 = 5.72727272, it doesn't achieve the value in query plan.
Trying the opposite way: 5,81583/6 = 0.969305 * 132=127.94826 . I don't understand how SQL Server is calculating this.
Thank you for the help !
Cheers,
Dennes - Se resolveu, classifique a mensagem, por favor - [http://www.bufaloinfo.com.br] NOVO DVD Segurança no ASP.NET : http://www.bufaloinfo.com.br/LearingSeriesSegurancaASPNET2.aspDennes
>>>Considering the Avg_Range_Rows field the result should be 6
It is 1
AVG_RANGE_ROWS is the average number of rows per distinct value and it is calculated as RANGE_ROWS / DISTINCT_RANGE_ROWS. In your example, we have a total of 126 records
for 126 DISTINCT_RANGE_ROWS, so that gives, 126/126 = 1 also shown on the histogram for AVR_RANGE_ROWS
http://sqlblog.com/blogs/ben_nevarez/archive/2009/09/04/statistics-used-by-the-query-optimizer-in-sql-server-white-paper.aspx
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How to get the SQL Execution Plan from complex Extractors ?
Hi
I am looking for a way to get the
SQL Execution Plan(s!)
from
Complex Extractors like 0CO_OM_CCA_9 ?
Anybody has got a suggestion ?
How to get this in SM50 ?
ThanXs
MartinIdentifying the query is the hard part. If you can identify it(based on table access or some such parameter, getting the execution plan is easy in ST04 .
-
The query processor could not produce a query plan
I'm getting this message:
Msg 8624, Level 16, State 17, Line 1
Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.
This is what I run
;WITH TableA AS
SELECT 101 as A_ID
,TableB AS
SELECT 1 as B_ID, 101 as B_A_ID , 'xxx' as B_Courses
UNION ALL
SELECT 2 , 101 , 'YYY'
UNION ALL
SELECT 3 , 101 , 'ZZZ'
UNION ALL
SELECT 4 , 102 , 'AAA'
SELECT
A_id
,x.x.value('(./text())[1]','varchar(500)') AS fieldX
FROM
TableA AS A
OUTER APPLY
-- CROSS APPLY
(SELECT
',' + B_Courses
FROM
TableB AS B
WHERE
1=1
AND B.B_A_ID = A.A_ID
FOR XML PATH(''),TYPE
) x(x)
With OUTER
APPLY, I get the message shown above.
With CROSS
APPLY, everything works nicely.
I resolve by adding in select this :
STUFF((SELECT ','+B_Courses
FROM
TableB AS B
WHERE
B.B_A_ID = A.A_ID
FOR XML PATH(''),TYPE).value('(./text())[1]' ,'VARCHAR(500)'),1,1,'')
Tested on:
Edition ProductVersion ProductLevel
Express Edition 9.00.3042.00 SP2
and
Edition ProductVersion ProductLevel
Developer Edition (64-bit) 11.0.2100.60 RTM
Any idea way is this happening?
ThanksIs the below working for you?
;WITH TableA AS
SELECT 101 as A_ID
,TableB AS
SELECT 1 as B_ID, 101 as B_A_ID , 'xxx' as B_Courses
UNION ALL
SELECT 2 , 101 , 'YYY'
UNION ALL
SELECT 3 , 101 , 'ZZZ'
UNION ALL
SELECT 4 , 102 , 'AAA'
SELECT
A_id
-- ,x.x.value('(./text())[1]','varchar(500)') AS fieldX --Commented this part
FROM
TableA AS A
OUTER APPLY
-- CROSS APPLY
(SELECT
',' + B_Courses
FROM
TableB AS B
WHERE
1=1
AND B.B_A_ID = A.A_ID
FOR XML PATH(''),TYPE
) x(x) -
Data not getting displayed in query
Hi
I have master infoobject with keyfigure units as percentage, and data is loaded and working fine.
data is not getting displayed in query, i am getting the error message, that exception aggregation has to be maintained for 0calday.
how do i resolve the issue
Regardssolved
Maybe you are looking for
-
Video playing from macbook to TV
Sorry for this odd question that may sound impossible for some or ludicrious for others but im a newbie and a computing n00b - so here goes: I have movies (AVI files) i play on my macbook but the 13" screen is bit small to enjoy the flick - so i ask:
-
I have a JDialog with a JTable and JScrollPane. JTable uses TableModel.java Now, when I am tryint to scroll to the right, the name of the columns, that was out of window won't redraw and the text is merged. The rows are ok. Only the titles. How to ge
-
Hi, as subject says, My WD 1.5TB Caviar Black brand new is inside Hitachi Tuoro Desk Pro 4TB USB 3.0 HDD enclosure and keeps ejecting randomly only on wake from sleep. On clean boot HDD works fine. Anyone know solution to this problem? Thank you
-
[SOLVED]No sound after installing oss
I am installing oss on my x86_64 pc. But I get the following when I type in " soundon ": Relinking OSS kernel modules for "3.14.2-1-ARCH SMP preempt mod_unload modversions " This may take few moments - please stand by... OSS build environment set up
-
How to Connect Tables on Separate Pages
Does anyone know if it's possible to have a table (B) be automatically updated when table (A) is changed? I am wondering if it's possible to have Table B match Table A, less a few columns and rows of info.. Table B is on a separate spreadsheet and a