Physical queries generated with DISTINCT clause
Hi All,
We have a model with three dimension tables and a fact table. All the join conditions between dimension and fact tables are defined and dimension with level keys.
Apart from this, one of the dimension is used for applying the row level filter.
Oracle BI is generating physical queries with DISTINCT clause, which is impacting the performance of the query exeuction. Any tips in modification to business model to avoid the generation of DISTINCT clause would be appreciated.
Thanks,
Phani
hi,
Open RPD-->Double click on Logical table source in BMM layer and go to content tab .you will have Select Distinct Values by default it was uncheck if that is checked uncheck that one....(this one is only to restrict from BMM layer)
thanks,
saichand.v
Similar Messages
-
Tunning the Query with Distinct Clause
Hi All,
I have the below query that returns 28113657 records
select src_Wc_id, osp_id, src_osp_id
from osp_complements o1
where exists (select 1 from wc_crossref wc
where wc.src_wc_id = o1.SRC_WC_ID
and wc.state = 'CA')
This query executes within a second...
But when i include a DISTINCT clause in the select statement, it takes more time ... (more than 20 mins)
I am trying to get it tunned. Please advice me with your knowledge to get it done
Thanks for your time
Kannan.Retrieving distinct rows requires a sort of all returned rows. 20 - 3 = ~17 mins for sorting 28 mln rows looks too much. You need to tune your instance in order to speed up sort operation. The amount of memory dedicated to sorts is controlled by PGA_AGGREGATE_TARGET parameter. If it's set to 0 (not recommended) then SORT_AREA_SIZE is used. The process of PGA tuning is quite complex and described in PGA Memory Management chapter of Performance Tuning Guide.
There is a workaround which allows to bypass sort operation, but it requires proper index and proper access by that index. The idea is that rows rertrieved via index are automatically ordered by indexed columns. If that and only that columns (possibly - in the same order as in the index, I don't know) are selected using DISTINCT then sort is not actually performed. Rows are already sorted due to access via index.
Hope this will help you.
Regards,
Dima -
Using: oracle 10g
I'm trying to get unique records in my result set, but I can't seem to get my query to work correctly.
Using the following code:
select distinct PLAYER_ID, LAST_NAME , MONIKER, LEAGUE_NAME, TEAM_name, POSITION_1_DESC,
BIRTH_DATE, BIRTH_CITY, BIRTH_COUNTRY_short, METRIC_HEIGHT
from customeR_data.cd_soccer_players
where league_id in (49,64,140,39,80,22,54,51,58,135)
group by PLAYER_ID, LAST_NAME , MONIKER, LEAGUE_NAME, TEAM_name, POSITION_1_DESC,
BIRTH_DATE, BIRTH_CITY, BIRTH_COUNTRY_short, METRIC_HEIGHT
order by player_id, last_nameNot really sure what i'm doing wrong here but I seem to be getting records with the same player_idHi,
As others have explained, DISTINCT just means that each row of output will be different, in some way, from every other row.
If two rows have a different league_name, that means the rows are different, regardless of what is in the other columns.
GROUP BY also guarantees that no two rows will be identical, so DISTINCT is not doing anything in your query.
If you want just one row of output per player_id, then GROUP BY player_id only.
You can use MIN or MAX to get the items that are dependent on player_id (such as last_name).
When there are are two (or more) different values for some field (like league_name) what do you want to display?
If you want a delimited list of items (like the sting 'Chmp_1,TBS'), then search for "String Aggregation". asktom has a good page on this topic. -
Select query with UNION clause in database adapter
Friends,
I have got a SQL query with two UNION clause withing it. like
select a,b,c
from a
union
select a,b,c
from b
The schema generated is like below in sequence
<element>a</element>
<element>b</element>
<element>c</element>
<element>a</element>
<element>b</element>
<element>c</element>
So, the columns from different select queries joined with UNION clause are all appeared in schema instead of the distinct columns.
Is there any way around to solve this issue ? or will need to with DB function/procedure.I think I know what you are saying but your example doesn't make sense, your SQL should produce something like
I had to change a, b, c with elementA, elementB, elementC as a and b are reserved html tags.
<elementA>DateA</elementA>
<elementB>DataB</elementB>
<elementC>DataC</elementC>
...What is the result of the query when you run it in SQLPlus? Is it what you expect?
cheers
James -
Problem with performance of a query having order by, distinct clause
Hi,
I have a problem with queries having order by, distinct clause.
While its executing its taking lot of time. With DBMS_PROFILER identified the queries taking long time.
The table is having approximately 70 million rows.
Problem -1
select * from table_name order by col1;
select distinct col1,col2 from table_name;
Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.
Solution1:
Max parallel servers is 8.
select /* + parallel(table_name,8) */ * from table_name order by col1;
select /* + parallel(table_name,8) */ distinct col1, col2 from table_name ;
Solution-2:
select /* + first_rows */ * from table_name order by col1;
select /* + first_rows */ distinct col1, col2 from table_name ;
Problem-2
I am having a query with where condition on columns.
Select * from table_name where col1='value1' and col2!='value2';
Index created on col1 and col2.
As we no that not equal won't use index as it is a composite index it should use the lead column. but its not using the index.
Should i forcibly use index with hint or suggest me better solution.
Any help really appreciated.
Thanks in advanceunique wrote:
The table is having approximately 70 million rows.
select * from table_name order by col1;Do you really want 70,000,000 rows from your table without any restrictions ? And furthermore ordered output ? I honestly understand the slowness of that query.
Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.Who knows if you choosed the right solution. I would suggest to reconsider your query and the need of 70,000,000 returned rows.
Problem-2
I am having a query with where condition on columns.
Select * from table_name where col1='value1' and col2!='value2';Please, provide the explain plan, eventually the tkprof output could also help. And tables descirption AND indexes description.
And OS and Oracle version.
Nicolas. -
Generate a where clause with outer join criteria condition: (+)=
Hi,
In my search page, I use Auto Customization Criteria mode, and I build where clause by using get Criteria():
public void initSrpQuery(Dictionary[] dic, String userName) {
int dicSize = dic.length;
StringBuffer whereClause = new StringBuffer(100);
Vector parameters = new Vector(5);
int clauseCount = 0;
int bindCount = 1;
for(int i=0; i < dicSize; i++){
String itemName = (String)(dic.get(OAViewObject.CRITERIA_ITEM_NAME));
Object value = dic[i].get(OAViewObject.CRITERIA_VALUE);
String joinCondition = (String)dic[i].get(OAViewObject.CRITERIA_JOIN_CONDITION);
String criteriaCondition = (String)dic[i].get(OAViewObject.CRITERIA_CONDITION);
String criteriaDataType = (String)dic[i].get(OAViewObject.CRITERIA_DATATYPE);
String viewAttributename = (String)dic[i].get(OAViewObject.CRITERIA_VIEW_ATTRIBUTE_NAME);
String columnName = findAttributeDef(viewAttributename).getColumnNameForQuery();
if((value != null) /*&& (!("".equals((String).trim())))*/){
if(clauseCount > 0){
whereClause.append(" AND ");
whereClause.append(columnName + " " + criteriaCondition + " :");
whereClause.append(++bindCount);
parameters.addElement(value);
clauseCount++;
If I want to generate following where clause:
select
,emp.name
,emp.email
,emp.salesrep_number
,comp.name
,gs.srp_goal_header_id
,gs.status_code
,gs.start_date
,gs.end_date
from g2c_goal_shr_emp_assignments_v emp
,jtf_rs_salesreps rs
,xxg2c_srp_goal_headers_all gs
,cn_comp_plans_all comp
where 1 = 1
and rs.salesrep_id = gs.salesrep_id (+)
and gs.comp_plan_id = comp.comp_plan_id (+)
and gs.period_year (+) = :1 -- :1 p_fiscal_year
How can I generate a where clause with outer join : gs.period_year (+) = :1 ? Will I get '(+)=' from get(OAViewObject.CRITERIA_CONDITION)?
thanks
LeiIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Outer Join with Where Clause in LTS
HI all,
I have a requirement like this in ANSI SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1 left outer join product_group p2 on p1.product_id = p2.product_id
and p2.product_group = 'NEW'
In Regular SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1, product_group p2
WHERE p1.product_id *= p2.product_id and p2.product_group = 'NEW'
In OBIEE, I am using a left outer join between these two in Logical table Source, and also, Gave
p2.product_group = 'NEW' in WHERE clause of LTS.
This doesn't seem to solve purpose.
Do you have any idea how to convert WHERE clause in physical query that OBIEE is generating to something like
product p1 left outer join product_group p2 on p1.product_id = p2.product_id AND p2.product_group = 'NEW'
I am using Version 10.1.3.4.1
Creating an Opaque view would be my last option though.Hello
I have read your post and the responses as well. and I understand that you have issues with the Outer Join with where Clause in LTS.
Try this solution which worked for me (using your example ) -
1. In the Physical Layer created a Complex join between PRODUCT and PRODUCT_GROUP tables and use this join relationship :
PRODUCT.PROD_ID = PRODUCT_GROUP.PROD_ID AND PRODUCT_GROUP.GROUP_NAME = 'MECHANICAL'
2. In the General Tab of PRODUCT table LTS add PRODUCT_GROUP table and select Join Type as Left Outer Join.
3. Check Consistency and make sure there are no errors .
when you run a request you should see the following query generated -
select distinct T26908.PROD_ID as c1,
T26908.PROD_NAME as c2,
T26912.GROUP_NAME as c3
from
PRODUCT T26908 left outer join PRODUCT_GROUP T26912 On T26908.PROD_ID = T26912.PROD_ID and T26912.GROUP_NAME = 'MECHANICAL'
order by c1, c2, c3
Hope this works for you. If it does please mark this response as 'Correct' .
Good Luck. -
Distinct clause as part of EJB QL
Hi,
I am trying to perform a simple query which looks like following in ejb-jar.xml
<query>
<query-method>
<method-name>findBySecurityNumber</method-name>
<method-params>
<method-param>int</method-param>
</method-params>
</query-method>
<ejb-ql>SELECT DISTINCT OBJECT(a) FROM LoanEntity a WHERE a.securityId = ?1
</ejb-ql>
</query>
In the SQL generated, I do not see the distinct clause being generated. Any ideas
as to what I am doing incorrectly?
This was a bug in SP 1, WL 6.1. But I am using SP2.
Thanks for your help
MohitHi Mohit,
You aren't doing anything wrong. The generated queries don't contain a distinct clause
because it isn't portable. For example, Oracle will not allow the use of "SELECT
DISTINCT" in conjunction with a "FOR UPDATE" clause. For portablility, the EJB
container manually weeds out the duplicate results. You can, however, still can have a
distinct clause in your generated SQL by using the sql-select-distinct element of your
CMP deployment descriptor. This may give you better performance but be sure the
transaction your query executes in will not have an isolation level of
TRANSACTION_READ_COMMITTED_FOR_UPDATE or you will run into problems.
- Matt
Mohit Sehgal wrote:
Hi,
I am trying to perform a simple query which looks like following in ejb-jar.xml
<query>
<query-method>
<method-name>findBySecurityNumber</method-name>
<method-params>
<method-param>int</method-param>
</method-params>
</query-method>
<ejb-ql>SELECT DISTINCT OBJECT(a) FROM LoanEntity a WHERE a.securityId = ?1
</ejb-ql>
</query>
In the SQL generated, I do not see the distinct clause being generated. Any ideas
as to what I am doing incorrectly?
This was a bug in SP 1, WL 6.1. But I am using SP2.
Thanks for your help
Mohit -
Distinct Clause missing on "Primary Key"
In our implementation, we have views and tables mixed physical Schema. For the views, obviously, they do not have to have 1 column as PK, but have a combination of columns to uniquely identify a record. Now when we use some of the views as dimension in our physical layer to do a join, it will automatically mark that joined column in the view as a "key" column, which makes sense.
Now, when we expose the very same column to the presentation, and then, do a query on that, it did not give use a distinct value of that column, instead, it give you 1 row per line. If I make a request by using columns with PK column from the same dimension table, it will not have a "Distnct" in the select statement , But if I put the PK column with other columns from a Fact table, it is then showing a "Distinct" clause in the select statement. In our situation, we need to have a distinct clause in the select statement, even there is no fact column involved.By definition your key column(s) defined in the Physical and Logical models must be unique. If you have multiple rows returned for your key when selecting from just the dimension table then your key is incorrect.
If you are saying when you join to the fact you see multiple rows, then check you have set your aggregate functions correctly on your fact measures. ie. SUM/COUNT etc...
Hope this helps. -
[NQQuery log]: Physical SQL generated agaisnt 2 Database in OBIEE 11g
Hi Experts,
I have a problem regarding the physical SQL generated by Query log.
So this is the setup.
SCENARIO 1:
Oracle Data Warehouse DB
- col1
- col2
- col3
OLAP_OBIEE
- col4
When I run these columns together in Analysis. It seems like the physical SQL generated in the Query log is partitioned with each other and I cant get the exact SQL so I can make comparison with the total record count in Analysis UI and the SQL developer.
select col1, col2, col3 from Oracle Data Warehouse tables
select col4 from OLAP_OBIEE tables
================================================================
SCENARIO 2:
Oracle Data Warehouse DB
- col1
- col2
- col3
- col4
Running these columns together in Analysis. I am wondering why the physical SQL is somewhat also partitioned just like in SCENARIO 1.
select col1, col2, col3 from Oracle Data Warehouse tables
select col4 from Oracle Data Warehouse tables
Hope that you get what am I trying to say. :(
Thanks,
Edited by: OBIEE/BIP Forumer on Oct 29, 2012 1:27 AM
Edited by: OBIEE/BIP Forumer on Oct 29, 2012 1:27 AMHi Maqsoon,
Sorry for the confusion, in my Analysis report, I have a report where it generates 2 physical SQL in one Database, also I have a report where it uses 2 Database which also generates 2 physical SQL.
Below is the SQl generated in my Analysis report using 1 Database
select count(distinct case when T68197.OPTY_WID > 0 then concat(T67058.INTEGRATION_ID, cast(T67058.DATASOURCE_NUM_ID as CHARACTER ( 30 ) )) end ) as c1,
T67058.OPTY_O_REVN as c2,
T67365.CUST_VALUE_NAME as c3,
T157680.NAME as c4,
T157680.INTEGRATION_ID as c5
from
W_OPTY_D T67058 /* Dim_W_OPTY_D */ ,
W_REVN_F T68197 /* Fact_W_REVN_F */ ,
W_PARTY_D T157680,
W_PARTY_ORG_D T67365
where ( T67058.ROW_WID = T68197.OPTY_WID and T67365.ROW_WID = T157680.PARTY_ORG_WID and T68197.PR_CUSTOMER_WID = T157680.ROW_WID )
group by T67058.OPTY_O_REVN, T67365.CUST_VALUE_NAME, T157680.NAME, T157680.INTEGRATION_ID
order by c5, c2
[2012-10-30T11:44:39.000+00:00] [OracleBIServerComponent] [TRACE:2] [USER-18] [] [ecid: 352c537d7893ee94:-5718ddd6:13aaccb7670:-8000-0000000000005c50] [tid: f650d700] [requestid: 45ca0005] [sessionid: 45ca0000] [username: joshua.l.manego.iii] -------------------- Sending query to database named Oracle Data Warehouse (id: <<1201371>>), connection pool named Oracle Data Warehouse Connection Pool, logical request hash edb0c7c0, physical request hash 87553d2a: [[
select sum(D1.c1) over (partition by D1.c4, D1.c2) as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
sum(D1.c5) over (partition by D1.c6, D1.c4, D1.c2) as c5,
D1.c6 as c6
from
(select count(T84444.ORDER_WID) as c1,
T67365.CUST_VALUE_NAME as c2,
T157680.NAME as c3,
T157680.INTEGRATION_ID as c4,
sum(T84444.ORDER_NRC) as c5,
T67058.OPTY_O_REVN as c6
from
W_OPTY_D T67058 /* Dim_W_OPTY_D */ ,
W_PARTY_ORG_D T67365,
W_ORDER_F T84444 /* Fact_W_ORDER_F */ ,
W_PARTY_D T157680
where ( T67058.ROW_WID = T84444.OPTY_WID and T67365.ROW_WID = T157680.PARTY_ORG_WID and T84444.CUSTOMER_WID = T157680.ROW_WID )
group by T67058.OPTY_O_REVN, T67365.CUST_VALUE_NAME, T157680.NAME, T157680.INTEGRATION_ID
) D1
order by c4, c6
Below is the physical SQL that uses 2 Database
select T68071.QUOTE_NUM as c1,
T116081.CURRENT_BASE_POSTN as c2,
T66755.PER_NAME_MONTH as c3,
T68071.STATUS_I as c4,
T68071.QUOTE_TYPE_I as c5,
T68071.SUB_TYPE_I as c6,
T84523.ROW_WID as c7
from
W_POSITION_D T74722 /* Dim_W_POSITION_D */ ,
W_QUOTE_D T68071 /* Dim_W_QUOTE_D */ ,
W_QUOTE_F T84523 /* Fact_W_QUOTE_F */ ,
W_DAY_D T66755 /* Dim_W_DAY_D_Common */ ,
W_POSITION_DH T116081 /* Dim_W_POSITION_DH_Position_Hierarchy */
where ( T66755.ROW_WID = T84523.OPEN_DT_WID and T68071.ROW_WID = T84523.QUOTE_WID and T74722.ROW_WID = T84523.PR_EMP_POS_WID and T74722.ROW_WID = T116081.POSITION_WID and T84523.PR_EMP_POSTN_DH_WID = T116081.ROW_WID )
order by c7
[2012-10-30T11:51:42.000+00:00] [OracleBIServerComponent] [TRACE:2] [USER-18] [] [ecid: 352c537d7893ee94:-5718ddd6:13aaccb7670:-8000-0000000000005cb8] [tid: f61fc700] [requestid: 45ca0007] [sessionid: 45ca0000] [username: joshua.l.manego.iii] -------------------- Sending query to database named OLAP_OBIEE (id: <<1204144>>), connection pool named Connection Pool, logical request hash c180fd3b, physical request hash a2e8b0d6: [[
select T315910.NIVEL_APPROVACAO as c1,
T315910.ALCADA_DESCONTO as c2,
T315910.ROW_WID as c3
from
W_QUOTEITEM_F T315910
order by c3
Based on what you said, so it is impossible to merge the physical SQL if we use 2 Database right?
Your effort in answering to my question is much appreciated, Thank you. -
How to Combine Multiple Physical Queries
Hi All,
I have a big reports with over 70-80 columns in Answer. This is not a Pivot report. Now it is generating 3 physical queries .
I need to merge this 3 queries into a single query. But it seems very hard to implement.
Couple of points:
1. Report is generating 3 physical queries. All queries are GROUP BY queries and each of them giving different count separately
2. If we find a way to combine. The result would be different from Answers Report Result (This is my assumption)
3. How Answer is combining the results from 3 queries and showing us the result?
Any input or thought is high appreciated.
I'm totally stuck in there. Tried different ways. But is there any solution for this that I'm not able to think?
Pls Help
Thanks in Advance
Regards
SudiptaHi Kranthi,
Thanks for you reply.
I need to combine multiple report queries into one and give it to ETL guys. I don't have to do anything in Answers. This is my requirement.
I'm good in SQL. So I tried to combine like the following. Taking a small scenario.
In this case, Anlytics is generating following 2 queries:
Query 1:
select sum(x), [Fact column]
sum(y), [Fact column]
column1, [Dim column]
column2, [Dim column]
column3, [Dim column]
from table1,table2,table3
where [All joins]
group by column1,column2,column3
Query 2:
select sum(z), [Fact column]
column1, [Dim column]
column2, [Dim column]
column3, [Dim column]
from table1,table2,table3
where [All joins]
group by column1,column2,column3
I'm trying to combine it:
Query 1:
select sum(x), [Fact column]
sum(y), [Fact column]
sum(z), [Fact column]
column1, [Dim column]
column2, [Dim column]
column3, [Dim column]
from
(select sum(x), [Fact column]
sum(y), [Fact column]
column1, [Dim column]
column2, [Dim column]
column3, [Dim column]
from table1,table2,table3
where [All joins]
group by column1,column2,column3
) q1,
select sum(z), [Fact column]
column1, [Dim column]
column2, [Dim column]
column3, [Dim column]
from table1,table2,table3
where [All joins]
group by column1,column2,column3
) q2
where
q1.column1=q2.column1 and
q1.column2=q2.column2 and
q1.column3=q2.column3
But i think it is not the correct way may be, as i'm getting a bit different count. So the where conditions are not matching for the 2 queries above.
Any thought on this?
Thanks
Sudipta -
Using bind variable with IN clause
My application runs a limited number of straight up queries (no stored procs) using ODP.NET. For the most part, I'm able to use bind variables to help with query caching, etc... but I'm at a loss as to how to use bind variables with IN clauses. Basically, I'm looking for something like this:
int objectId = 123;
string[] listOfValues = { "a", "b", "c"};
OracleCommand command = new OracleCommand();
command.Connection = conn;
command.BindByName = true;
command.CommandText = @"select blah from mytable where objectId = :objectId and somevalue in (:listOfValues)";
command.Parameters.Add("objectId", objectId);
command.Parameters.Add("listOfValues", listOfValues);
I haven't had much luck yet using an array as a bind variable. Do I need to pass it in as a PL/SQL associative array? Cast the values to a TABLE?
Thanks,
NickNevermind, found this
How to use OracleParameter whith the IN Operator of select statement
which contained this, which is a brilliant solution
http://oradim.blogspot.com/2007/12/dynamically-creating-variable-in-list.html -
Avoid distinct clause in the query
hi i have a query from a single table using distinct clause and has columns (a,b,c,d,e,f,g,h,i)
eg: select distinct a,b ,c,d from table
where a<>0 and b<>0 and c<>0 and d<>0 and e=o and f=0 and g=0 and h=0 and i=0 ;
when i see the execution plan with out distinct... it performs a bit faster.
how do i remove distinct clause and make the query perform better
this particular query is used as inline view in my vieiw . it is used in from clause .
please suggest
second question.... iam getting bitmap index to rowid conversion ...is this good? does it hamper performance . how to avoid this?
regards
raj
Edited by: raj_fresher on Jul 17, 2009 7:48 AMHi Raj
what is e in the query ?It is the column name you provided yourself in your own unformatted example.
After 400+ posts I thought you would understand that it's not that hard to put this exact tag => (yes, 6 characters, 4 letters between 2 curly brackets) before and after your code examples or sample data or explain plans.
That way you maintain formatting and improve readability for us poor readers by magnitudes.
But, I'm sure you'll succeed as well as all the others who can.
I always look on the bright side.
Example:
Earlier this week another Raj also finally got enlightened about it, and his life has since then changed forever!
+He drives a Bentley now, you know+ ;) -
I found out issue distinct clause in query ,refcursor not returning rows
URGENT
hi the following procedure returns records but when i add distinct clause to (open v_refcursor for select )
i.e open v_refcursor for select distinct column1,column2 .......... in the procedure the procedure is not returning records. please help what is the issue here?
CREATE OR REPLACE procedure proc_shared_report3 (in_cust_id varchar2,in_user_array user_tab , in_acct_array acct_tab,in_report_pvlg_hier varchar2,in_fmt_pvlg_hier varchar2,v_refcursor OUT sys_refcursor)
is
BEGIN
if in_acct_array.count>0 and in_fmt_pvlg_hier is not null and in_cust_id is not null and in_user_array.count>0 and in_report_pvlg_hier is not null then
dbms_output.put_line('all are not null');
*open v_refcursor for select usr_id* from vw_get_user_profile where usr_id in (
SELECT USR_ID FROM VW_GET_ACCOUNTS WHERE USR_ID IN (SELECT distinct up1.usr_id FROM vw_get_user_privileges up1,vw_get_user_privileges up2 WHERE
up1.usr_id=up2.usr_id and
up1.product_hierarchy=in_report_pvlg_hier and up2.PRODUCT_HIERARCHY=in_fmt_pvlg_hier AND up1.usr_id in (select usr_id from vw_get_user_for_customer where
cust_id=in_cust_id)
and up1.usr_id Member Of in_user_array) AND acct_nb Member of in_acct_array);
/* if account list is null and rest all not null */
elsif (in_acct_array is null or in_acct_array IS EMPTY or in_acct_array.count = 0) and in_fmt_pvlg_hier is not null and in_cust_id is not null and in_user_array.count>0 and in_report_pvlg_hier is not null then
dbms_output.put_line('acc is null and rest are not null');
*open v_refcursor for select usr_id,usr_type_cd* from vw_get_user_profile where usr_id in(SELECT distinct up1.usr_id FROM vw_get_user_privileges up1,vw_get_user_privileges up2 WHERE
up1.usr_id=up2.usr_id and
up1.product_hierarchy=in_report_pvlg_hier and up2.PRODUCT_HIERARCHY=in_fmt_pvlg_hier AND up1.usr_id in (select usr_id from vw_get_user_for_customer where
cust_id=in_cust_id)
and up1.usr_id Member Of in_user_array);
/* if account list is null and format pvlg hierarchy is null */
elsif (in_acct_array is null or in_acct_array IS EMPTY or in_acct_array.count = 0) and in_fmt_pvlg_hier is null and in_cust_id is not null and in_user_array.count>0 and in_report_pvlg_hier is not null
then
dbms_output.put_line('acc is null and format is null null');
*open v_refcursor for select usr_id,tmzon_cd* from vw_get_user_profile where usr_id in (
(SELECT distinct usr_id FROM vw_get_user_privileges WHERE product_hierarchy=in_report_pvlg_hier AND usr_id in (select usr_id from vw_get_user_for_customer where
cust_id=in_cust_id)
and usr_id Member Of in_user_array)) ;
/* if account list is not null and format pvlg hierarchy is null */
else -- If i get only one privilege and all other inputs then
dbms_output.put_line('acc list is not null and format pvlg is null');
*open v_refcursor for select usr_id,prod_shrt_nm* from vw_get_user_profile where usr_id in (
SELECT USR_ID FROM VW_GET_ACCOUNTS WHERE USR_ID IN (SELECT distinct usr_id FROM vw_get_user_privileges WHERE
product_hierarchy=in_report_pvlg_hier AND usr_id in (select usr_id from vw_get_user_for_customer where
cust_id=in_cust_id) and usr_id Member Of in_user_array ) AND acct_nb Member of in_acct_array);
END IF;
END proc_shared_report3;
/Edited by: raj_fresher on Aug 12, 2009 8:50 AM
Edited by: raj_fresher on Aug 12, 2009 1:40 PMits like this ...... ?
You have to understand that without any testdata/ a reproducable testcase, all I can do is asking you to test some alternatives, I'm just guessing things from what I can make of your example, and hope you'll repost back any differences in a clear and concisive way.
What I didn't understand is why you're not just joining your tables/views instead of using inner queries.
Unfortunatly you're not providing any feedback on that, on the other hand you've narrowed down your problem to a specific part of your query? But you're not sharing why/what makes you decide to take that turn.
But: you're still using inner queries in your reply.
So, sorry, I cannot proceed/say anything useful unless you answer my previous post.
Because, there are still many other questions/doubts: I don't understand why you're not aliasing your columns properly, for example.
I don't know why you've suddenly switched to VW_GET_USER_cust_sa?
I don't know if you've tried the straight join instead of nesting queries?
And if you did, what's the problem?
Please read and understand this, so you'll get your answers by the speed of light the next time you've got a question or problem:
http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
And don't refrain from using that tag ;) -
Distinct clause and query performance
Friends,
I have a query which returns results in 40 seconds without distinct clause and when I add distinct clause it takes over 2 hours.
I have verified following -
1. indexes/table statistics are up to date.
2. columns that are used in where clause but are not indexed have upto date column statistics
Any idea what could be the reason, explain plan shows that distinct clause has a very expensive cost.
Thanks
Query and explain plan is below
SELECT
DISTINCT -- with distinct 2hrs + and without 40 seconds
quote_by_dst.qte_hdr_stat_cd, quote_by_dst.qte_ln_cond_cd,
product.prod_nm, product.prod_id,
cs_ship_by_dst.bto_ds_cac_ownr_ud,
quote_by_dst.qte_csup_csup_am, cs_ship_by_dst.bto_ds_cac_nm,
product.spl_sht_nm,
product.prod_blg_un_fac_um
|| ' '
|| product.prod_blg_um
|| ' '
|| product.prod_stck_um,
product.prod_blg_um, quote_by_dst.qte_ln_brk_1_blg_uom_am,
quote_by_dst.qte_csup_avg_cst_am,
quote_by_dst.qte_csup_rev_gm_pct_am,
quote_by_dst.qte_csup_avg_cst_am, cs_ship_by_dst.bto_id,
cs_ship_by_dst.bto_ds_cac_cd,
cs_ship_by_dst.bto_ds_cac_cd
|| product.prod_id
|| cs_ship_by_dst.bto_id
FROM infowhse.quote_by_dst4 quote_by_dst,
infowhse.product,
infowhse.cs_ship_by_dst4 cs_ship_by_dst,
infowhse.department
WHERE (quote_by_dst.dpt_cd = department.dpt_cd)
AND (quote_by_dst.cus_dpt_id = cs_ship_by_dst.cus_dpt_id)
AND (product.prod_id = quote_by_dst.prod_id)
AND ( ( quote_by_dst.qte_ln_cond_cd = 'E'
OR quote_by_dst.qte_ln_cond_cd = 'C'
AND quote_by_dst.qte_hdr_stat_cd = 'A'
AND ((cs_ship_by_dst.bto_cust_type_cd) = '01')
AND cs_ship_by_dst.bto_ds_cac_ownr_ud = 'EHOC'
AND department.dpt_cd > '0.00'
)Explain plan
Plan
SELECT STATEMENT CHOOSECost: 911,832,256 Bytes: 433,941,639,459 Cardinality: 2,729,192,701
15 SORT UNIQUE Cost: 911,832,256 Bytes: 433,941,639,459 Cardinality: 2,729,192,701
14 NESTED LOOPS Cost: 68,705 Bytes: 433,941,639,459 Cardinality: 2,729,192,701
12 HASH JOIN Cost: 68,705 Bytes: 425,754,061,356 Cardinality: 2,729,192,701
1 INDEX FAST FULL SCAN NON-UNIQUE INFOWHSE.DST_SEC_DST_SEC_DST_CD_IX Cost: 25 Bytes: 922,700 Cardinality: 184,540
11 HASH JOIN Cost: 16,179 Bytes: 1,199,209,082 Cardinality: 7,941,782
2 INDEX FAST FULL SCAN NON-UNIQUE INFOWHSE.DST_SEC_DST_SEC_DST_CD_IX Cost: 25 Bytes: 922,700 Cardinality: 184,540
10 HASH JOIN Cost: 15,879 Bytes: 3,374,060 Cardinality: 23,110
8 HASH JOIN Cost: 15,200 Bytes: 2,981,190 Cardinality: 23,110
6 HASH JOIN Cost: 13,113 Bytes: 1,779,470 Cardinality: 23,110
3 TABLE ACCESS FULL INFOWHSE.CUSTOMER_SHIP Cost: 5,640 Bytes: 42,372 Cardinality: 1,177
5 PARTITION RANGE ALL Partition #: 11 Partitions accessed #1 - #12
4 TABLE ACCESS FULL INFOWHSE.QUOTE Cost: 7,328 Bytes: 38,826,590 Cardinality: 946,990 Partition #: 11 Partitions accessed #1 - #12
7 TABLE ACCESS FULL INFOWHSE.PRODUCT Cost: 1,542 Bytes: 9,246,640 Cardinality: 177,820
9 INDEX FAST FULL SCAN NON-UNIQUE INFOWHSE.CUST_SHIP_SLSDST_DTP_SICALL_IX Cost: 185 Bytes: 9,878,411 Cardinality: 581,083
13 INDEX UNIQUE SCAN UNIQUE INFOWHSE.DEPARTMENT_PK Bytes: 3 Cardinality: 1This might be more useful.
Query is still running.
There is heavy wait time for scattered file read.
Results from
SELECT * FROM V$SESSION_WAIT WHERE SID = 48;
SID SEQ# EVENT P1TEXT P1 P1RAW P2TEXT P2 P2RAW P3TEXT P3 P3RAW WAIT_TIME SECONDS_IN_WAIT STATE
48 6865 db file scattered read file# 108 000000000000006C block# 1593370000000000026E69 blocks 32 0000000000000020 2 30 WAITED KNOWN TIME
SELECT * FROM V$SESSION_EVENT WHERE SID = 48;
SID EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED AVERAGE_WAIT MAX_WAIT TIME_WAITED_MICRO
48 log file sync 1 0 0 0 0 563
48 db file sequential read 11 0 0 0 0 243
48 db file scattered read 6820 0 330 0 7 3296557
48 SQL*Net message to client 19 0 0 0 0 23
48 SQL*Net message from client 18 0 128 7 127 1281912 Sorry for long post.
Maybe you are looking for
-
Postings in wrong Functional Area
Hi, I have a complicated scenario, i have a service purchase order for a cost center C111 which as a Functional Area F101, during invoice i had changed the cost center to C222 and changed the Functional Area to F101, where the cost center C222 belong
-
Transaction similar to MDVP, for Production Orders
Hello. I have used transaction MDVP to perform a collective availability check on Planned Orders. Do you know of a similar one that gives me the same information on Production Orders? I have used CO24 to get a report of Missing parts, but I feel that
-
Looking for good definitions and references for "Wait Model".(10g) Examples how it can be used for performance tuning. Thanks.
-
Am currently working in a project in which Server intiates the Clients application[Swing] and keeps track of the application.For a single client it consumes some 20MB memory.For more than 200 client it consumes 20Mb*200 & More memory .Is there any wa
-
I am being told that "Back to Mac" isn't working because NAT Port Mapping is turned off on my router. What does that mean and how do I fix it?