Improving performance of query with View
Hi ,
I'm working on a stored procedure where certain records have to be eleminated , unfortunately tables involved in this exception query are present in a different database which will lead to performance issue. Is there any way in SQL Server to store this query
in a view and store it's execution plan and make it work like sp.While I beleive it's kinda crazy thought but is there any better way to improve performance of query when accessed across databases.
Thanks,
Vishal.
Do not try to solve problems that you have not yet confirmed to exist. There is no general reason why a query (regardless of whether it involves a view) that refers to a table in a different database (NB - DATABASE not INSTANCE) will perform poorly.
As a suggestion, write a working query using a duplicate of the table in the current database. Once it is working, then worry about performance. Once that is working as efficiently as it can , change the query to use the "remote" table rather
than the duplicate. Then determine if you have an issue. If you cannot get the level of performance you desire with a local table, then you most likely have a much larger issue to address. In that case, perhaps you need to change your perspective
and approach to accomplishing your goal.
Similar Messages
-
Improve performance of query with order by
Hello,
I have a query with a necessary "order by" which lasts 24 seconds. The same query without the "order by" lasts 1 second.
How can I improve the performance of the query with "order by"?
Thank you very much.
The query is:
select distinct CC.acceso,CC.ext_acceso,TIT.TITULO_SALIDA
from (((Ocurrencias CT01 inner join
palabras p0 on (CT01.cod_palabra = p0.cod_palabra and p0.palabra like 'VENEZUELA%' AND p0.campo = 'AUTOR')) INNER JOIN
CENTRAL CC ON (CT01.ACCESO = CC.ACCESO AND CT01.EXT_ACCESO = CC.EXT_ACCESO))) inner join
codtit ctt on (CC.acceso = ctt.acceso and CC.ext_acceso = ctt.ext_acceso) inner join
titulos tit on (ctt.cod_titulo = tit.cod_titulo and ctt.portada = '1')
where CC.nivel_reg <> 's'
ORDER BY 3 ASC;My guess is SQL Scratchpad is a GUI and is not returning all the rows but just the first screenful. Without any order by or distinct the database can start returning rows as soon as it finds the first one. With an order or distinct it needs to sort the rows so the first row can only be returned after the last row is retrieved.
Open a command line prompt and run
sqlplus
SQL> set timing on
SQL>And then run your queries.
If you still have a large discrepancy do this
SQL> set autotrace traceonly
SQL>And then run the queries and post the output. -
How to improve performance of query
Hi all,
How to improve performance of query.
please send :
[email protected]
thanks in advance
bhaskarhi
go through the following links for performance
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
http://www.asug.com/client_files/Calendar/Upload/ASUG%205-mar-2004%20BW%20Performance%20PDF.pdf
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1955ba90-0201-0010-d3aa-8b2a4ef6bbb2 -
Improve performance of an inline view query
All,
I have a unique situation where I have to limit the number of rows based on group. so I created an Inline view and applied a limit on it.
ex:
SELECT col_A, col_B FROM ( SELECT col_a, count(*) FROM tab_a WHERE col_a = 'XXX' GROUP BY col_a) ROWNUM <-10.
but this design was rejected, because it seems to have a great impact on performance due to inline view.
Also I cant set a rowlimit directly on the query because GROUP BY clause is used in the select.
When the rownum is directly applied in the WHERE, first it limits the rows and then it makes a GROUP, so when user asks to retrieve 10 records, it may show less than 10 rows because of the grouping.
please help to find a alternative solution which helps to get the expected result set and same time without loosing performance.Hi,
The sql you gave us is not valid. There is no "col_b" in your inline view, there is no "where" before "rownum<10", and the inline view returns only one row.
Try to produce a reproducible scenario with scott.emp and scott.dept generated by $ORACLE_HOME/rdbms/admin/utlsampl.sql
Regards
Laurent -
Ora-13226 when performing spatial query on view
Hi,
in my database I have a view with spatial column. The view is based on UNION ALL select. When I try to run spatial query on the view, the database returns ora-13226 error. When I recreate the view to consist only one select (without UNION ALL) the spatial query return correct result. Could you pls help me how to do a spatial query on spatial view whose definition contains UNION ALL select?
Thanks
AndrewHi,
it's quite simple:
create view test_view as
select id, geometry from table_a
union all
select id, geometry from table_b;
When I try for example:
select *
from test_view
where sdo_relate(geometry, (select geometry from table_c where id=1316),'mask=anyinteract') = 'TRUE';
it throws ora-13226 error.
Interesting is that following query where the geometry is directly included runs well:
select *
from test_view
where sdo_relate(geometry, MDSYS.SDO_GEOMETRY (....),'mask=anyinteract') = 'TRUE';
also when I recreate the test_view as
create view test_view as
select id, geometry from table_a;
then also the first query (with inner select) returns no error.
It's a little bit strange isn't it?
Andrew -
How to improve query performance when query with mtart
hi all,
I need to know what is the best way to query out MATNR when i have values for MTART and WERKS?
When a user select a MTART and WERKS, a whole bunch of MATNR related to them are display out. How do i improve this query so that it does not take a long time?
Thanks
Willliam WilstrothIs that what you are looking for???
select a~matnr a~mtart ... b~werks ...
into table <itab>
from mara as a
inner join marc as b
on a~matnr = b~matnr
where mtart = p_mtart
and werks = p_werks.
There is an index on MTART in table MARA.
<b>T Material Type</b>
Kind Regards
Eswar -
Performance of query using view - what is happening here
Hi,
I can't explain the difference in performance between two queeries.
For a datawarehouse I have 3 tables from 3 different sources, named source1, source2 and
source3 they all have the identical columns:
client_key
,client_revenue
source1 has 90.000.000 rows, source2 1.000.000 rows and source3 50.000 rows
I also made a view say, all_clients which is the union of the 3 tables plus a constant column called 'source'
which corresponds to the table_name.
If I run a query which shows the number of records it takes 15-20 minutes:
select source,count(*)
from all_clients
group by source.
If i run the following query it takes about 5 minutes!
select 'source1',count(*)
from source1
union
select 'source2',count(*)
from source2
union
select 'source3',count(*)
from source3.
What makes the difference?Hmmm... Interesting. In my small example things seem pretty similar. Have you done the explain plans?
An observation is that you are using a UNION rather than a UNION ALL which would be better as you may be incurring an unnecessary SORT UNIQUE.
create table tab1 as(select object_id, object_type from all_objects);
create table tab2 as(select object_id, object_type from all_objects);
create table tab3 as(select object_id, object_type from all_objects);
analyze table tab1 estimate statistics;
analyze table tab2 estimate statistics;
analyze table tab3 estimate statistics;
create view v_tab123 as(select 'source1' source,count(*) cnt
from tab1
union
select 'source2',count(*)
from tab2
union
select 'source3',count(*)
from tab3);
select 'source1' source,count(*) cnt
from tab1
union
select 'source2',count(*)
from tab2
union
select 'source3',count(*)
from tab3;
Operation Object Name Rows Bytes Cost TQ In/Out PStart PStop
SELECT STATEMENT Hint=CHOOSE 3 180
SORT UNIQUE 3 180
UNION-ALL
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB1 38 K 10
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB2 38 K 10
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB3 38 K 10
-- Union
select source, cnt from(
select 'source1' source,count(*) cnt
from tab1
union
select 'source2',count(*)
from tab2
union
select 'source3',count(*)
from tab3)
Operation Object Name Rows Bytes Cost TQ In/Out PStart PStop
SELECT STATEMENT Hint=CHOOSE 3 180
VIEW 3 54 180
SORT UNIQUE 3 180
UNION-ALL
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB1 38 K 10
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB2 38 K 10
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB3 38 K 10
-- Union ALL
select source, cnt from(
select 'source1' source,count(*) cnt
from tab1
union ALL
select 'source2',count(*)
from tab2
union ALL
select 'source3',count(*)
from tab3)
Operation Object Name Rows Bytes Cost TQ In/Out PStart PStop
SELECT STATEMENT Hint=CHOOSE 3 180
VIEW 3 54 180
SORT UNIQUE 3 180 <<<<============== Unnecessary
UNION-ALL
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB1 38 K 10
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB2 38 K 10
SORT AGGREGATE 1 60
TABLE ACCESS FULL TAB3 38 K 10
analyze table tab1 delete statistics;
analyze table tab2 delete statistics;
analyze table tab3 delete statistics;
Now with RBO - the SORT UNIQUE goes away for the above query.
Operation Object Name Rows Bytes Cost TQ In/Out PStart PStop
SELECT STATEMENT Hint=CHOOSE
VIEW
UNION-ALL
SORT AGGREGATE
TABLE ACCESS FULL TAB1
SORT AGGREGATE
TABLE ACCESS FULL TAB2
SORT AGGREGATE
TABLE ACCESS FULL TAB3 -
How Can I increase performance of Query with Distinct Keyword
Dear Experts,
In my Query when I execute this without Distinct it give result very soon,
But when I excute this with Distinct its performance is very slow is there any option for increase the performance with Distinct .
I have to use Distinct according to our rewuirement.neither DISTINCT nor GROUP BY do sort. If you need to sort, use ORDER BY. Slight correction, they do a sort, but your results are not guarenteed to be sorted.
The overhead of a sort is incurred, if your results is large enough (my test below isn't) you will be sorting to disk. Which as we all know can be very slow.
9i:
SQL> SET TRIMSPOOL ON
SQL> CREATE TABLE D (A VARCHAR2(2));
Table created.
SQL> INSERT INTO D (A) SELECT DBMS_RANDOM.STRING('U',2) FROM DUAL CONNECT BY LEVEL <= 5000;
5000 rows created.
SQL> COMMIT;
Commit complete.
SQL> SET AUTOTRACE TRACEONLY EXPLAIN;
SQL> SELECT DISTINCT A FROM D;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (UNIQUE)
2 1 TABLE ACCESS (FULL) OF 'D'
SQL> SELECT A FROM D GROUP BY A;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (GROUP BY)
2 1 TABLE ACCESS (FULL) OF 'D'
SQL> SELECT DISTINCT A FROM D ORDER BY A;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (UNIQUE)
2 1 TABLE ACCESS (FULL) OF 'D'
SQL> SPOOL OFF10g
SQL> SET TRIMSPOOL ON
SQL> CREATE TABLE D (A VARCHAR2(2));
Table created.
SQL> INSERT INTO D (A) SELECT DBMS_RANDOM.STRING('U',2) FROM DUAL CONNECT BY LEVEL <= 5000;
5000 rows created.
SQL> COMMIT;
Commit complete.
SQL> SET AUTOTRACE TRACEONLY EXPLAIN;
SQL> SELECT DISTINCT A FROM D;
Execution Plan
Plan hash value: 3079699766
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5000 | 15000 | 7 (29)| 00:00:01 |
| 1 | HASH UNIQUE | | 5000 | 15000 | 7 (29)| 00:00:01 |
| 2 | TABLE ACCESS FULL| D | 5000 | 15000 | 5 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
SQL> SELECT A FROM D GROUP BY A;
Execution Plan
Plan hash value: 2712634873
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5000 | 15000 | 7 (29)| 00:00:01 |
| 1 | HASH GROUP BY | | 5000 | 15000 | 7 (29)| 00:00:01 |
| 2 | TABLE ACCESS FULL| D | 5000 | 15000 | 5 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
SQL> SELECT DISTINCT A FROM D ORDER BY A;
Execution Plan
Plan hash value: 1773491675
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5000 | 15000 | 8 (38)| 00:00:01 |
| 1 | SORT UNIQUE | | 5000 | 15000 | 7 (29)| 00:00:01 |
| 2 | TABLE ACCESS FULL| D | 5000 | 15000 | 5 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
SQL> SPOOL OFF -
Improve performance on computers with more than 1 GB RAM (Photoshop CS2)
Photoshop CS2 uses complex memory management procedures. On computers with 1 GB of RAM, or more, you can optimize Photoshop to take advantage of the quantity of RAM in your system to manage memory more efficiently. For further information on how to implement the "Bigger Tiles" Plug-in please refer to Adobe Knowledgebase
Document 331372Hi,
1 to 8 GB for process is little on the higher side :) Y don't you try to "page" it up like windows.. Serialize the memory intensive objects into a folder and load them (unserialize) when they are required...
Just a suggestion and not exactly answering your qn. ..But just thought will post this comment ... Hope it gives some insight..
Cheers,
Chandra -
Improve Performance on Inline view Query
All,
I have a unique situation where I have to limit the number of rows based on group. so I created an Inline view and applied a limit on it.
ex:
SELECT col_A, col_B FROM ( SELECT col_a, count(*) FROM tab_a WHERE col_a = 'XXX' GROUP BY col_a) ROWNUM <-10.
but this design was rejected, because it seems to have a great impact on performance due to inline view.
Also I cant set a rowlimit directly on the query because GROUP BY clause is used in the select.
When the rownum is directly applied in the WHERE, first it limits the rows and then it makes a GROUP, so when user asks to retrieve 10 records, it may show less than 10 rows because of the grouping.
please help to find a alternative solution which helps to get the expected result set and same time without loosing performancebut this design was rejected, because it seems to have a great impact on performance due to inline view.What proof was offered that this query performed badly. There is nothing inherently non-performant about in-line views. I would demand to see some evidence that this query uses an unreasonable amount of system resource.
However, you could try this:
SELECT t.col1, avg(t.col2)
FROM t1 t
WHERE t.col1 IN ( SELECT DISTINCT x.col1
FROM t1 x
WHERE col3 = 'XXX'
AND rownum <=10 )
GROUP BY t.col1
/I assume your example is not derived from your real code (otherwise the WHERE clause would restrict the inline query to one returned row - problem solved!)
Cheers, APC -
Improve performance of the below query
Hi Gurus,
I have following query with the plan described. I need to improve the the performance of this query as it is using full table scans.
How could achieve this.
SELECT csf.*,
NULL subject_flag,
NULL next_exp_rewards_date,
0 next_exp_rewards,
(csf.rewards_cf - csf.rewards_bf - csf.total_rewards) * -1 reward_spent
FROM crm_statement_fulfilled csf, crm_accounts ca
WHERE csf.account_id = ca.account_id
AND csf.procg_date = '01-jul-2012'
AND ca.cycle_id = '01'
AND ca.date_closed IS NULL
AND ca.account_type IN ('LTT', 'LTY', 'LYI')
ORDER BY csf.account_id
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.2.0
Connected as crm
SQL> desc crm_statement_fulfilled
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(19)
CAMPAIGN_ID NUMBER(10)
CYCLE_ID VARCHAR2(2)
CUSTOMER_ID NUMBER(14) Y
PROCG_DATE DATE
GE_FULFILLED VARCHAR2(1) Y
POINTS_DISPLAYED VARCHAR2(1) Y
REASON_ID VARCHAR2(10) Y
POINTS_BF NUMBER(10,2) Y
PROMO_POINTS NUMBER(10,2) Y
GW_ADJ_POINTS NUMBER(10,2) Y
TOTAL_REWARDS NUMBER(10,2) Y
GW_FUL_POINTS NUMBER(10,2) Y
REC_POINTS NUMBER(10,2) Y
REC_FC_POINTS NUMBER(10,2) Y
POINTS_CONVERTED NUMBER(10,2) Y
POINTS_CF NUMBER(10,2) Y
TOTAL_POINTS NUMBER(10,2) Y
TOTAL_AIR_MILES_VALUE NUMBER(10) Y
POINTS_EXPIRED NUMBER(10,2) Y
CDT_IN_STR_POINTS NUMBER(10,2) Y
CDT_OUT_STR_POINTS NUMBER(10,2) Y
ANNIVERSARY_POINTS NUMBER(10,2) Y
LOYALTY_POINTS NUMBER(10,2) Y
NEXT_EXP_POINTS NUMBER(10,2) Y
NEXT_EXP_POINTS_DATE DATE Y
REWARDS_BF NUMBER(10,2) Y
REWARDS_CF NUMBER(10,2) Y
SQL> desc crm_accounts
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(19)
CYCLE_ID VARCHAR2(2)
ACCOUNT_TYPE VARCHAR2(3)
SECURITY_PASSWORD VARCHAR2(80) Y
ACCESS_PASSWORD VARCHAR2(80) Y
AIRMILES_ID VARCHAR2(16) Y
DATE_OPENED DATE
SEED VARCHAR2(1) Y
AUTO_AIRMILES VARCHAR2(1) Y
CURRENCY VARCHAR2(3) Y
DATE_CLOSED DATE Y
STORE_OPENED VARCHAR2(4) Y
DATE_ACTIVATED DATE Y
OLD_ACCOUNT_ID NUMBER(19) Y
CARDPAC_ACCOUNT_ID NUMBER(19) Y
ORG_ID VARCHAR2(10) Y
LOGO_ID VARCHAR2(10) Y
PTS_TO_ACCOUNT_ID NUMBER(19) Y
DMW_ACCOUNT_ID VARCHAR2(19) Y
SQL>Hi,
Sid_ Z. wrote:
Hi Gurus,
I have following query with the plan described. I need to improve the the performance of this query as it is using full table scans...For all tuning requests, see the forum FAQ {message:id=9360003}
AND csf.procg_date = '01-jul-2012'Don't try to compare a DATE (such as procg_date) with as VARCHAR2 (such as '01-jul-2012'.
Use TO_DATE or a DATE literal instead. -
Options to control display performance of CLOBs, etc. in Query Result view?
Whenever I attempt to query a table that contains LOBs (e.g. a CLOB or XMLTYPE), the lack of performance pretty much makes the "Query Result" view (from F9) unusable. Any time I attempt to scroll the results, SQL developer apparently continues to query the database for the additional characters to populate the view.
Resizing the columns containing the LOB to only a few characters almost solves the issue. Unfortunately, the size of the columns showing the LOBs apparently attempt to resize to the length of the LOB, making the column several pages long - and the same performance issue prevents resizing it smaller.
Ideally, there would be some way to resize a column to a given or even a predefined and small size, without having to drag the resize handle the entire width of the desired resize amount. Alternatively, there could be a user preference to never set default column widths above a given number of pixels or characters. Another option would be a user preference to disable the in-line display of LOB contents, displaying only and requiring a click on the "..." (or pencil icon) button to open the "View Value" dialog. Ideally, all 3 of these options could be implemented.
One crude work-around I'm using for now is to exclude the LOB columns from the results, requiring me to make secondary queries to see the LOB contents when necessary, and doesn't allow for scrolling through and viewing the LOB contents at all. Another work-around is to run the query as a script (F5) instead of a query (F9), and view the results in the "Script Output" view instead.
I'm currently using SQL Developer 2.1.0.63, but experienced this same issue with all previous versions, including 1.5.5.
Thanks!I agree.
When I requested to auto-width the columns, I said to build in a maximum, but apparently they didn't.
I suggest you log 2 feature requests on the SQL Developer Exchange; 1 for the maximum width, 1 for the CLOB contents/performance. Like this others can vote too and add weight for future implementation (I will).
Have fun,
K. -
How to improve performance of the attached query
Hi,
How to improve performance of the below query, Please help. also attached explain plan -
SELECT Camp.Id,
rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount,
(SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
rCam.AccountKey as AccountKey
FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
WHERE Camp.AccountKey = rCam.AccountKey
AND Camp.AvCampaignKey = rCam.AvCampaignKey
AND Camp.AccountKey = CamBilling.AccountKey
AND Camp.CampaignKey = CamBilling.CampaignKey
AND rCam.AccountKey = xSite.AccountKey
AND rCam.AvSiteKey = xSite.AvSiteKey
AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
to_date('01-01-2011', 'DD-MM-YYYY')
GROUP By rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount
Explain Plan :-
Description Object_owner Object_name Cost Cardinality Bytes
SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
SORT AGGREGATE 1 13
VIEW GEMINI_REPORTING 14 1 13
HASH GROUP BY 14 1 103
NESTED LOOPS 13 1 103
HASH JOIN 12 1 85
TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
NESTED LOOPS 9 5 325
HASH JOIN 7 1 40
SORT UNIQUE 2 1 18
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1duplicate thread..
How to improve performance of attached query -
Need to improve Performance of select...endselect query
Hi experts,
I have a query in my program like below with inner join of 3 tables.
In my program used select....endselect again inside this select...endselect statements used..
While executing in production taking lot of time to fetch records. Can anyone suggest to improve performance of below query urgently...
Greatly appreciated ur help...
SELECT MVKEDWERK MVKEMATNR MVKEVKORG MVKEVTWEG MARA~MATNR
MARAMTART ZM012MTART ZM012ZLIND ZM012ZPRICEREF
INTO (MVKE-DWERK , MVKE-MATNR , MVKE-VKORG , MVKE-VTWEG , MARA-MATNR
, MARA-MTART , ZM012-MTART , ZM012-ZLIND , ZM012-ZPRICEREF )
FROM ( MVKE
INNER JOIN MARA
ON MARAMATNR = MVKEMATNR
INNER JOIN ZM012
ON ZM012MTART = MARAMTART )
WHERE MVKE~DWERK IN SP$00004
AND MVKE~MATNR IN SP$00001
AND MVKE~VKORG IN SP$00002
AND MVKE~VTWEG IN SP$00003
AND MARA~MTART IN SP$00005
AND ZM012~ZLIND IN SP$00006
AND ZM012~ZPRICEREF IN SP$00007.
%DBACC = %DBACC - 1.
IF %DBACC = 0.
STOP.
ENDIF.
CHECK SP$00005.
CHECK SP$00004.
CHECK SP$00001.
CHECK SP$00002.
CHECK SP$00003.
CHECK SP$00006.
CHECK SP$00007.
clear Check_PR00.
select * from A004
where kappl = 'V'
and kschl = 'PR00'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
Check_PR00 = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00008.
clear Check_ZPR0.
select * from A004
where kappl = 'V'
and kschl = 'ZPR0'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
Check_ZPR0 = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00009.
clear ZFMP.
select * from A004
where kappl = 'V'
and kschl = 'ZFMP'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
ZFMP = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00010.
clear mastercost.
clear ZDCF.
select * from A004
where kappl = 'V'
and kschl = 'ZDCF'
and vkorg = mvke-vkorg
and vtweg = mvke-vtweg
and matnr = mvke-matnr
and DATAB le sy-datum
and DATBI ge sy-datum.
if sy-subrc = 0.
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
ZDCF = konp-kbetr.
endif.
endselect.
endif.
endselect.
CHECK SP$00011.
clear masterprice.
clear Standardcost.
select * from mbew
where matnr = mvke-matnr
and bwkey = mvke-dwerk.
Standardcost = mbew-stprs.
mastercost = MBEW-BWPRH.
masterprice = mBEW-BWPH1.
endselect.
ADD 1 TO %COUNT-MVKE.
%LINR-MVKE = '01'.
EXTRACT %FG01.
%EXT-MVKE01 = 'X'.
EXTRACT %FGWRMVKE01.
ENDSELECT.
best rgds..
hari..Hi there.
Some advices:
- why going to MVKE first and MARA then? You will find n rows in MVKE for 1 matnr, and then go n times to the same record in MARA. Do the oposite, i.e, go first to MARA (1 time per matnr) and then to MVKE.
- avoid select *, you will save time.
- use trace or measure performance in tcodes ST05 and SM30.
- replace:
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
Check_ZPR0 = konp-kbetr.
endif.
endselect.
by
select * from konp
where knumh = a004-knumh.
Check_ZPR0 = konp-kbetr.
exit.
endselect.
Here, if I understood, you only need to atribute kbetr value to Check_ZPR0 if selecting anything (don't need the IF because if enters in select, subrc always equal to 0, and also don't need to do it several times from same a004-knumh - reason for the EXIT.
Hope this helps.
Regards.
Valter Oliveira.
Edited by: Valter Oliveira on Jun 5, 2008 3:16 PM -
How to improve performance of attached query
Hi,
How to improve performance of the below query, Please help. also attached explain plan -
SELECT Camp.Id,
rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount,
(SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
rCam.AccountKey as AccountKey
FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
WHERE Camp.AccountKey = rCam.AccountKey
AND Camp.AvCampaignKey = rCam.AvCampaignKey
AND Camp.AccountKey = CamBilling.AccountKey
AND Camp.CampaignKey = CamBilling.CampaignKey
AND rCam.AccountKey = xSite.AccountKey
AND rCam.AvSiteKey = xSite.AvSiteKey
AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
to_date('01-01-2011', 'DD-MM-YYYY')
GROUP By rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount
Explain Plan :-
Description Object_owner Object_name Cost Cardinality Bytes
SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
SORT AGGREGATE 1 13
VIEW GEMINI_REPORTING 14 1 13
HASH GROUP BY 14 1 103
NESTED LOOPS 13 1 103
HASH JOIN 12 1 85
TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
NESTED LOOPS 9 5 325
HASH JOIN 7 1 40
SORT UNIQUE 2 1 18
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1duplicate thread..
How to improve performance of attached query
Maybe you are looking for
-
Creative Live Vista IM webcam VF0260 on XP professional
Hi, i can't install the VF0260 webcam on my XP 32 bit machine. I downloaded the driver from the creative support page, and when i try to run SETUP.EXE i get a message telling me the setup is for VISTA only Please help Thanks
-
Hello !! I need some help ! I have searched all over the internet and can't find any help. I have a HP ENVY m6 Notebook PC running on Windows 8. After I updated Windows 8 to 8.1 some of the websites that I use wont completely load... It looks like th
-
Touchscreen defect? Can't open the iPad mini
My daily appointments show but I cannot open the calender itself, the photo-function is working - but nothing else. I can't open the device, as the touchscreen does not respond. Tried to turn it on and off - no help. Does any one know, what I can do
-
Unfortunately, the NEF files of the Nikon Coolpix 5400 ar not supported in Aperture. I have read somewhere that you can edit the supported camera list by using a RAW profile of a similar camera. Although I am not sure if this will work it would be ni
-
Graphics Card Error message...
Hello, I am experiencing a recent problem with my newly purchased MacBook Pro. (2.4GHz Intel core 2 Duo) I have FCP 4.5HD and after transfering it over to my new machine I am unable to launch it. At launch I get the error message: "This software requ