Performance Tuning the AVG function

Dear All,
I have a table which is rapidly growing. We have a query which is frequently executed on this table and it utilizes AVG function without a WHERE clause. Is there a way to tune this query?
I tried to create a Materialized View but Oracle rejects as AVG cannot be used in MV's. Also, it is now really easy at this point in time to rewrite the query.
Appreciate if anybody can help me out in this situation.
OS: Windows 2003 EE
Database: Oracle 10g R2 10.2.0.4
Sample Table:
Create table t(id number, name varchar2(30), amt number);
insert into t select level, 'level - ' || level, level * 100 from dual connect by dual level <= 1000;
commit;
Query:
select avg(amount) from t;
Thanks for you time.
- P

>
... and it utilizes AVG function without a WHERE clause
>
As Aman stated, a full table scan will be needed for a statement without a WHERE clause.
See these threads on how to post a tuning request
When your query takes too long ...
HOW TO: Post a SQL statement tuning request - template posting
HTH
Srini

Similar Messages

  • Performance tuning of a function which is part of a package.

    Hello
    I just built a function in a package. And now I want to make sure that the SQL is well tuned.
    I was going through the links mentioned in this post
    Performance Tuning
    to know more about performance tuning.
    But I am confused with some simple things.
    So when we analyze a single function present in a package , should I use the SQL of the function or
    should I use a call to that function.
    For example first I thought of using EXPLAIN PLAN.
    I see a different explain plan when I use a call to that function then
    when I use the actual SQL of the function with some plugged in parameters whereever required.
    What is the right way of doing it?
    Thank you

    I recommend :
    1. use SQL tracing with DBMS_MONITOR and then TKPROF on raw SQL trace file
    2. call the function as it used in your production environment
    See good examples in http://www.oracle-base.com/articles/10g/SQLTrace10046TrcsessAndTkprof10g.php (just refer to DBMS_MONITOR examples and TKPROF).
    Note that SQL trace will only trace SQL and not PL/SQL. If SQL elapsed time does not match function call elapsed time close enough, you need to use DBMS_PROFILER to know where PL/SQL non SQL code elapsed time is used.
    I don't recommend using EXPLAIN PLAN because it has known limitations http://docs.oracle.com/cd/E11882_01/server.112/e16638/ex_plan.htm#PFGRF94673 (others have said "EXPLAIN PLAN lies" - you can google for this expression ....).
    Edited by: P. Forstmann on 10 févr. 2012 19:44

  • Help: The AVG function.

    A query selecting a number column with data 5537 5367, the AVG of the column returns 5452 instead of 5454. Here is a script for test:
    create table test (a number(4));
    insert into test values(5537);
    insert into test values(5367);
    select avg(a) from test;
    It shows:
    AVG(A)
    5452
    Thank you in advance

    ARe you kidding ?!???
    5537 + 5367 = 10904 / 2 = 5452
    Maybe some fog on your glasses ?...
    Francois

  • Yielding the desired number of decimal places using the AVG function in t-sql

    Hello again.  Confused retired hobby coder having trouble setting up a scalar-valued function to return the desired number of decimal places from a AVG query.
    Whenever I run the following script I get the number of decimals I desire:
    Using the above I created a scalar-valued function as follows:
    Running this function as: SELECT [dbo].[TestHCIPartial] (1,3)  my return is -7.
    Can you help me with the function causing it to yield the answer to 6 decimal places?
    Thanks and regards, Minuend.

    You've not specified precision and scale in UDF return type. So you're leaving it to server to interpret it based on default settings
    If you want exactly up to four decimal places tweak udf as below
    ALTER FUNCTION..
    RETURNS decimal(20,4)
    AS
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Performance tuning the loop statement

    Hi,
    I have the following requirement.
    I have an internal table IT_TEST1 which has values
    Column1
    A
    B
    C
    D
    consider a second internal table IT_TEST2. It'll have values like as follows:..I need to know which are the entries in column1 that have more than one entry in column 2 without looping through this internal table..Kindly suggest..
    Column1 column2
    A            VAL1
    B            VAL1
    B            VAL2
    C            VAL1
    C            VAL2
    D            VAL1
    D            VAL2
    D            VAL3
    This has caused very big performance issue for it is

    Hi,
    I have faced a similar problem and the following strategy has saved a lot of processing time
    the following code may serve your pupose
    if you are using IT_TEST2 for further processing please use IT_TEST3
    otherwise use IT_TEST2 instead of IT_TEST3 in the code below......'
    *************************CODE SAMPLE************************************
    data : IT_TEST3 like IT_TEST2.  "declare internal table same as IT_TEST2
      IT_TEST3[] = IT_TEST2[]. 
        "Pass contents if IT_TEST2 is used for further processing
    Sort IT_TEST1 by column1 .  "Sort
    Sort IT_TEST3 by column1 .  "Sort
       loop at IT_TEST1.
               read table IT_TEST3
                    with key column1 = IT_TEST1-column1.
                     if sy-subrc = 0.
                          describle table IT_TEST3 lines n.
                              if lines > 1.
                                 "Multiple entries
                               else.
                                 "Single entry
                              endif.
                     endif.
      "Perform all operations on IT_TEST3
        DELETE IT_TEST3 WHERE  column1 = IT_TEST1-column1.
    "Delete the entry in IT_TEST3 already processed with the key of IT_TEST1
    "Next time you do the read entries for the previous and all predecessor loops
    will not be there'
    "As you go down the loop performance increases
    endloop.
    Regards
    Byju

  • Rounding the aggregate function in a pivot table

    How do I round the avg(GRADE) when I tried just wrapping it around the avg function I get an error message saying expect aggregate function inside pivot operation
    pivot
    ( avg(GRADE)
    for Column
    in ('1012222','2221112','333113' );
    Thanks for the help.
    Edit : Sorry wasn't very clear all thats shown is the pivot part of the statement.
    Edited by: 836321 on Feb 13, 2011 8:56 AM
    Edited by: 836321 on Feb 13, 2011 8:58 AM

    Hi, and welcome to the forum.
    It is hard to see how your piece of pseudo SQL is related to your subject title.
    There should not be any problem in wrapping ROUND around AVG:
    SQL> select deptno, round(avg(sal)) from emp
    where deptno in (10,20)
    group by deptno
        DEPTNO ROUND(AVG(SAL))
            20            2175
            10            2917
    2 rows selected.Edit: Sorry, did not recognize you query bit. You probably are asking about this:
    SELECT * FROM
       (SELECT deptno, sal FROM emp)
        PIVOT
       (ROUND(AVG(sal)) FOR deptno IN (10 AS Accounting, 30 AS Sales));
    Error at line 4
    ORA-56902: expect aggregate function inside pivot operationSuppose you have to (There might be other ways)
    SQL> SELECT Round(accounting), round(sales) FROM
       (SELECT deptno, sal FROM emp)
        PIVOT
       (AVG(sal) FOR deptno IN (10 AS Accounting, 30 AS Sales));
    ROUND(ACCOUNTING) ROUND(SALES)
                 2917         1567
    1 row selected.Regards
    Peter
    Edited by: Peter on Feb 13, 2011 9:05 AM
    Edited by: Peter Gjelstrup on Feb 13, 2011 9:08 AM

  • BDB Performance Tuning.

    Hello All,
    In efforts to tune BDB JE's performance, I'd like to ask everyone what sort of things you have looked at and tried. The application looks like this: it has multi-threaded reads/writes with large number of small entries. One thread for writing and another for reading. Most the performance tuning is needed on writing to the database, preferably to support stable insertion/modification times. Each entry is no more than 4KB (keys and entries are constant size)
    Some research indicates that changing page size to be equal to the size of the entry is helpful. I've looked at this: http://www.oracle.com/technology/documentation/berkeley-db/db/gsg/JAVA/dbconfig.html#pagesize
    However, DatabaseConfig.setPageSize() is nowhere to be found. Am I missing something? Where can I access this setting?
    I've also been having problems with database grinding to a near halt with large amounts of entries (under 1 mil) and total database file size of about 800MB. What are the general suggestions/practices for speeding things up? In this case performance is preferred over memory use.
    Thank you,
    Mike.

    Hi Mike,
    Some research indicates that changing page size to be
    equal to the size of the entry is helpful. I've
    looked at this:
    http://www.oracle.com/technology/documentation/berkele
    y-db/db/gsg/JAVA/dbconfig.html#pagesize
    However, DatabaseConfig.setPageSize() is nowhere to
    be found. Am I missing something? Where can I access
    this setting?You're looking at the docs for the wrong product -- that's the C product. The JE docs are here:
    http://www.oracle.com/technology/documentation/berkeley-db/je
    (Note the je suffix as opposed to the db suffix, which is the C product.)
    I've also been having problems with database grinding
    to a near halt with large amounts of entries (under 1
    mil) and total database file size of about 800MB.
    What are the general suggestions/practices for
    speeding things up? In this case performance is
    preferred over memory use.Have you tried increasing the JE cache size (EnvironmentConfig.setCacheSize)? In general, databases perform better with more memory. But to do performance tuning the first step is to normally print out the EnvironmentStats periodically and correlate changes in the stats with the performance you're seeing. Please see the performance section of the JE FAQ:
    http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • R12 Performance Tuning...

    Are there any docs or notes that one can to follow for EBS R12 performance tuning ?
    Regards,
    Rupdipt

    Hi,
    Please refer to the following links:
    Performance Tuning the Apps Database Layer
    http://blogs.oracle.com/schan/newsItems/departments/release12/2007/05/17#a1562
    Understanding JDBC Connections From the eBusiness Middle Tier
    http://blogs.oracle.com/schan/newsItems/departments/release12/2007/09/20#a2051
    Performance Tuning for the E-Business Suite
    http://blogs.oracle.com/schan/newsItems/departments/release12/2007/12/11#a2297
    The following notes/links provide guidelines for setting up JVMs (Jserv groups/OC4J instances) for online applications in Apps 11i and R12:
    Note: 362851.1 - Guidelines to setup the JVM in Apps Ebusiness Suite 11i and R12
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=362851.1
    Note: :462550.1 - Generate JVM heap dump in E-Business suite 11i and R12
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=462550.1
    Latest JVM Tuning Recommendations for Apps 11i
    http://blogs.oracle.com/schan/2007/03/01
    Tuning JVMs with Apps 11i
    http://blogs.oracle.com/schan/2007/02/16#a1230
    Configuring Middle-Tier JVMs for Applications 11i
    http://blogs.oracle.com/schan/2006/08/01#a494
    For tuning other application components (i.e. CM, initialization parameters, top SQL statements, application tier, ..etc), the following note should be helpful:
    Note: 169935.1 - Troubleshooting Oracle Applications Performance Issues
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=169935.1
    Note: 244040.1 - Oracle E-Business Suite Recommended Performance Patches
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=244040.1
    Note: 744143.1 - Tuning performance on eBusiness suite
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=744143.1
    Regards,
    Hussein

  • Store events in differents tables/ AVG function error

    HI,
    I have a very newbie question that i can't resolve.
    I want to store events in a database, so far so good, but if i define the events on context file like this:
    <wlevs:event-type-repository>
    <wlevs:event-type type-name="Averages">
    <wlevs:properties>
    <wlevs:property name="average_Generator1_ActivePower" type="float"/>
    <wlevs:property name="sum_Generator2_ActivePower" type="int"/>
    <wlevs:property name="max_Substation_Active_Power" type="int"/>
    <wlevs:property name="number_events" type="int"/>
    </wlevs:properties>
    </wlevs:event-type>
    <wlevs:event-type type-name="WindEvent">
    <wlevs:properties>
    <wlevs:property name="generator1_ActivePower" type="int"/>
    <wlevs:property name="generator2_ActivePower" type="int"/>
    <wlevs:property name="substation_Active_Power" type="int"/>
    </wlevs:properties>
    </wlevs:event-type>
    </wlevs:event-type-repository>
    They will be saved in the same table, TupleValues table.
    I try to workaround this situation by defining one of the events as a class and in this case the Oracle CEP create a different table to store this events. But, with this configuration, I have an error on the processor node, most exactly, in the avg function that use a property of the class created. Below there is the context file, the java class and the query in the processor
    #Java class
    public class WindEvent {
         private Integer Generator1_ActivePower;
         private Integer Generator1_AverageExpectedEnergy;
         private Integer Generator2_ActivePower;
         private Integer Generator2_AverageExpectedEnergy;
         private Integer Substation_Active_Power;
         private Integer Substation_AverageExpectedEnergy;
    #context file
    <wlevs:event-type-repository>
    <wlevs:event-type type-name="WindEvent">
    <wlevs:class>oracle.cep.demo.events.WindEvent</wlevs:class>
    </wlevs:event-type>
    </wlevs:event-type-repository>
         <wlevs:adapter id="adapter" provider="csvgen">
              <wlevs:listener ref="channel" />
              <wlevs:instance-property name="port" value="9001" />
              <wlevs:instance-property name="eventTypeName" value="WindEvent" />
              <wlevs:instance-property name="eventPropertyNames"
    value="generator1_ActivePower,generator1_AverageExpectedEnergy,generator2_ActivePower,generator2_AverageExpectedEnergy,substation_Active_Power,substation_AverageExpectedEnergy"/>
         </wlevs:adapter>
         <wlevs:channel id="channel" event-type="WindEvent">
              <wlevs:listener ref="processor" />
         </wlevs:channel>
         <wlevs:processor id="processor">
         </wlevs:processor>
    #query
    <processor>
    <name>processor</name>
    <rules>
    <query id="ExampleQuery">
    <![CDATA[select  avg(substation_Active_Power) as max_Substation_Active_Power, count(*) as number_events from channel [range 60]]]>
    </query>
    </rules>
    </processor>
    If somebody could help in the two questions i will be really grateful

    this is the output of the error:
    <Warning> <Spring> <BEA-2047006> <Work {0} terminated with exception = commonj.work.WorkException: java.lang.RuntimeException: [Adapter:2041010]Event type WindEvent has a property of type int. This tool only supports String, Integer, Long, Float, and Double properties.
    commonj.work.WorkException: java.lang.RuntimeException: [Adapter:2041010]Event type WindEvent has a property of type int. This tool only supports String, Integer, Long, Float, and Double properties.
         at weblogic.work.commonj.CommonjWorkManagerImpl$WorkStatus.setThrowable(CommonjWorkManagerImpl.java:260)
         at weblogic.work.commonj.CommonjWorkManagerImpl$WorkWithListener.run(CommonjWorkManagerImpl.java:198)
         at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Caused By: java.lang.RuntimeException: [Adapter:2041010]Event type WindEvent has a property of type int. This tool only supports String, Integer, Long, Float, and Double properties.
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl.validateEventType(CSVGenAdapterImpl.java:75)
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl.run(CSVGenAdapterImpl.java:42)
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl$$FastClassByCGLIB$$1d34d8cd.invoke(<generated>)
         at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
         at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
         at com.bea.wlevs.ede.impl.EventManagerAccessorProxy.invoke(EventManagerAccessorProxy.java:30)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.wlevs.ede.impl.EventBeanProxy.invoke(EventBeanProxy.java:38)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl$$EnhancerByCGLIB$$e60b1b.run(<generated>)
         at com.bea.wlevs.spring.RunnableBeanPostProcessor$RunnableWrapper.run(RunnableBeanPostProcessor.java:118)
         at weblogic.work.commonj.CommonjWorkManagerImpl$WorkWithListener.run(CommonjWorkManagerImpl.java:196)
         at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

  • How to use AVG function to determine difference.

    Hi, I have a basic table where there is an invoice price. I can do the AVG function to find out what the average is, but I need to be able to subtract the difference from each value in the column and submit it as a query. I was wondering if anyone had any advice how I'd do that.
    Thanks,
    Justin

    wrote:user_7000025
    Here is the table in question and the specific instructions:
    Write the query that will show the invoice number, the average invoice amount, and the difference between the average invoice amount and the actual invoice amount.
    INV_NUM CUST_NUM INV_DATE INV_AMOUNT
    8000 1000 23-MAR-04 236
    8001 1001 23-MAR-04 313
    8002 1001 30-MAR-04 528
    8003 1000 12-APR-04 195
    8004 1000 23-APR-04 619test@XE> --
    test@XE> -- Write the query that will show the invoice number, the average invoice amount, and
    test@XE> -- the difference between the average invoice amount and the actual invoice amount.
    test@XE> --
    test@XE>
    test@XE> --
    test@XE> with t as (
    2 select 8000 inv_num, 1000 cust_num, to_date('23-MAR-04','DD-MON-RR') inv_date, 236 inv_amount from dual union all
    3 select 8001, 1001, to_date('23-MAR-04','DD-MON-RR'), 313 from dual union all
    4 select 8002, 1001, to_date('30-MAR-04','DD-MON-RR'), 528 from dual union all
    5 select 8003, 1000, to_date('12-APR-04','DD-MON-RR'), 195 from dual union all
    6 select 8004, 1000, to_date('23-APR-04','DD-MON-RR'), 619 from dual)
    7 --
    8 select inv_num,
    9 cust_num,
    10 inv_date,
    11 inv_amount,
    12 avg(inv_amount) over () as avg_inv_amt,
    13 avg(inv_amount) over () - inv_amount as avg_actual_diff
    14 from t;
    INV_NUM CUST_NUM INV_DATE INV_AMOUNT AVG_INV_AMT AVG_ACTUAL_DIFF
    8000 1000 23-MAR-04 236 378.2 142.2
    8001 1001 23-MAR-04 313 378.2 65.2
    8002 1001 30-MAR-04 528 378.2 -149.8
    8003 1000 12-APR-04 195 378.2 183.2
    8004 1000 23-APR-04 619 378.2 -240.8
    5 rows selected.
    test@XE>
    test@XE>
    isotope
    Update: Good to know the solution worked. You may want to mark the question answered and award points.
    Edited by: isotope on Mar 14, 2009 10:50 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Avg function and problems with it

    I know this may sound stupid since I'm pretty new to Oracle and SQL, but I'm trying to do a query with an average price and it's keeps giving me the error that group function not allowed here. Could someone point me in the right direction here. This is what I have but it keeps giving me that error.
    SELECT productID productName, price
    FROM our_product
    WHERE AVG(price)<price;

    Since the AVG function requires that rows get aggregated, you can't use it like that in a WHERE clause. You could put it in a subquery like this
    SELECT productID, productName, price
      FROM our_product
    WHERE price > (
        SELECT AVG(price)
          FROM our_product
        )It would generally be more efficient, however, to do something like this with the analytic version of AVG
    SELECT *
      FROM (
        SELECT productID,
               productName,
               price,
               AVG(price) OVER () avg_price
          FROM our_product
    WHERE avg_price < priceJustin
    Edited by: Justin Cave on Oct 17, 2009 9:10 PM

  • Can anyone plz tell me the steps for performance tuning.

    hello friends
    what is performance tuning?
    can anyone plz tell me the steps for performance tuning.

    Hi Kishore, this will help u.
    Following are the different tools provided by SAP for performance analysis of an ABAP object
    Run time analysis transaction SE30
    This transaction gives all the analysis of an ABAP program with respect to the database and the non-database processing.
    SQL Trace transaction ST05
    The trace list has many lines that are not related to the SELECT statement in the ABAP program. This is because the execution of any ABAP program requires additional administrative SQL calls. To restrict the list output, use the filter introducing the trace list.
    The trace list contains different SQL statements simultaneously related to the one SELECT statement in the ABAP program. This is because the R/3 Database Interface - a sophisticated component of the R/3 Application Server - maps every Open SQL statement to one or a series of physical database calls and brings it to execution. This mapping, crucial to R/3s performance, depends on the particular call and database system. For example, the SELECT-ENDSELECT loop on the SPFLI table in our test program is mapped to a sequence PREPARE-OPEN-FETCH of physical calls in an Oracle environment.
    The WHERE clause in the trace list's SQL statement is different from the WHERE clause in the ABAP statement. This is because in an R/3 system, a client is a self-contained unit with separate master records and its own set of table data (in commercial, organizational, and technical terms). With ABAP, every Open SQL statement automatically executes within the correct client environment. For this reason, a condition with the actual client code is added to every WHERE clause if a client field is a component of the searched table.
    To see a statement's execution plan, just position the cursor on the PREPARE statement and choose Explain SQL. A detailed explanation of the execution plan depends on the database system in use.
    Need for performance tuning
    In this world of SAP programming, ABAP is the universal language. In most of the projects, the focus is on getting a team of ABAP programmers as soon as possible, handing over the technical specifications to them and asking them to churn out the ABAP programs within the “given deadlines”.
    Often due to this pressure of schedules and deliveries, the main focus of making a efficient program takes a back seat. An efficient ABAP program is one which delivers the required output to the user in a finite time as per the complexity of the program, rather than hearing the comment “I put the program to run, have my lunch and come back to check the results”.
    Leaving aside the hyperbole, a performance optimized ABAP program saves the time of the end user, thus increasing the productivity of the user, and in turn keeping the user and the management happy.
    This tutorial focuses on presenting various performance tuning tips and tricks to make the ABAP programs efficient in doing their work. This tutorial also assumes that the reader is well versed in all the concepts and syntax of ABAP programming.
    Use of selection criteria
    Instead of selecting all the data and doing the processing during the selection, it is advisable to restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code.
    Not recommended
    Select * from zflight.
    Check : zflight-airln = ‘LF’ and zflight-fligh = ‘BW222’.
    Endselect.
    Recommended
    Select * from zflight where airln = ‘LF’ and fligh = ‘222’.
    Endselect.
    One more point to be noted here is of the select *. Often this is a lazy coding practice. When a programmer gives select * even if one or two fields are to be selected, this can significantly slow the program and put unnecessary load on the entire system. When the application server sends this request to the database server, and the database server has to pass on the entire structure for each row back to the application server. This consumes both CPU and networking resources, especially for large structures.
    Thus it is advisable to select only those fields that are needed, so that the database server passes only a small amount of data back.
    Also it is advisable to avoid selecting the data fields into local variables as this also puts unnecessary load on the server. Instead attempt must be made to select the fields into an internal table.
    Use of aggregate functions
    Use the already provided aggregate functions, instead of finding out the minimum/maximum values using ABAP code.
    Not recommended
    Maxnu = 0.
    Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
    Check zflight-fligh > maxnu.
    Maxnu = zflight-fligh.
    Endselect.
    Recommended
    Select max( fligh ) from zflight into maxnu where airln = ‘LF’ and cntry = ‘IN’.
    The other aggregate functions that can be used are min (to find the minimum value), avg (to find the average of a Data interval), sum (to add up a data interval) and count (counting the lines in a data selection).
    Use of Views instead of base tables
    Many times ABAP programmers deal with base tables and nested selects. Instead it is always advisable to see whether there is any view provided by SAP on those base tables, so that the data can be filtered out directly, rather than specially coding for it.
    Not recommended
    Select * from zcntry where cntry like ‘IN%’.
    Select single * from zflight where cntry = zcntry-cntry and airln = ‘LF’.
    Endselect.
    Recommended
    Select * from zcnfl where cntry like ‘IN%’ and airln = ‘LF’.
    Endselect.
    Check this links
    http://www.sapdevelopment.co.uk/perform/performhome.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/afbad390-0201-0010-daa4-9ef0168d41b6
    kindly reward if found helpful.
    cheers,
    Hema.

  • Need help in Performance tuning for function...

    Hi all,
    I am using the below algorithm for calculating the Luhn Alogorithm to calculate the 15th luhn digit for an IMEI (Phone Sim Card).
    But the below function is taking about 6 min for 5 million records. I had 170 million records in a table want to calculate the luhn digit for all of them which might take up to 4-5 hours.Please help me performance tuning (better way or better logic for luhn calculation) to the below function.
    A wikipedia link is provided for the luhn algorithm below
    Create or Replace FUNCTION AddLuhnToIMEI (LuhnPrimitive VARCHAR2)
          RETURN VARCHAR2
       AS
          Index_no     NUMBER (2) := LENGTH (LuhnPrimitive);
          Multiplier   NUMBER (1) := 2;
          Total_Sum    NUMBER (4) := 0;
          Plus         NUMBER (2);
          ReturnLuhn   VARCHAR2 (25);
       BEGIN
          WHILE Index_no >= 1
          LOOP
             Plus       := Multiplier * (TO_NUMBER (SUBSTR (LuhnPrimitive, Index_no, 1)));
             Multiplier := (3 - Multiplier);
             Total_Sum  := Total_Sum + TO_NUMBER (TRUNC ( (Plus / 10))) + MOD (Plus, 10);
             Index_no   := Index_no - 1;
          END LOOP;
          ReturnLuhn := LuhnPrimitive || CASE
                                             WHEN MOD (Total_Sum, 10) = 0 THEN '0'
                                             ELSE TO_CHAR (10 - MOD (Total_Sum, 10))
                                         END;
          RETURN ReturnLuhn;
       EXCEPTION
          WHEN OTHERS
          THEN
             RETURN (LuhnPrimitive);
       END AddLuhnToIMEI;
    http://en.wikipedia.org/wiki/Luhn_algorithmAny sort of help is much appreciated....
    Thanks
    Rede

    There is a not needed to_number function in it. TRUNC will already return a number.
    Also the MOD function can be avoided at some steps. Since multiplying by 2 will never be higher then 18 you can speed up the calculation with this.
    create or replace
    FUNCTION AddLuhnToIMEI_fast (LuhnPrimitive VARCHAR2)
          RETURN VARCHAR2
       AS
          Index_no     pls_Integer;
          Multiplier   pls_Integer := 2;
          Total_Sum    pls_Integer := 0;
          Plus         pls_Integer;
          rest         pls_integer;
          ReturnLuhn   VARCHAR2 (25);
       BEGIN
          for Index_no in reverse 1..LENGTH (LuhnPrimitive) LOOP
             Plus       := Multiplier * TO_NUMBER (SUBSTR (LuhnPrimitive, Index_no, 1));
             Multiplier := 3 - Multiplier;
             if Plus < 10 then
                Total_Sum  := Total_Sum + Plus ;
             else
                Total_Sum  := Total_Sum + Plus - 9;
             end if;  
          END LOOP;
          rest := MOD (Total_Sum, 10);
          ReturnLuhn := LuhnPrimitive || CASE WHEN rest = 0 THEN '0' ELSE TO_CHAR (10 - rest) END;
          RETURN ReturnLuhn;
       END AddLuhnToIMEI_fast;
    /My tests gave an improvement for about 40%.
    The next step to try could be to use native complilation on this function. This can give an additional big boost.
    Edited by: Sven W. on Mar 9, 2011 8:11 PM

  • What are the best practices for Database management and performance tuning?

    Hello,
    I want to ensure that I am using the best practices for managing and maintaining our Database.
    Is there any documentation out there that outlines how to maintain and ensure top performance out of our database?
    Thank you!
    John Sefton

    I appreciate the responses, however this is not the information I am looking for.
    I am specificaly looking for best practices invloving the managment and performance tuning.
    Example: are their tools that I can install that will monitor the size and response time of the database and alert me if there is degradation in performance?
    Are there specific periodic activities I should be doing to garuntee that my database will continue to function that way it is supposed to?
    Or is this a fire and forget solution that does not need this attention?

  • Cannot save any changes - Microsoft Forefront 2010 for exchange is unable to perform the requested function

    HI, I have Forefront 2010 for Exchange installed for an Exchange 2007 SP2 running on Windows 2003 x64 SP2. Exchange has all roles installed on the same server. 
    When I try to save any change on Forefront I got the following message:
    Microsoft Forefront 2010 for Exchange is unable to perform the requested function. This may be because Forefront services are unavailable. Ensure that all Microsoft Forefront services are running and that WindowsPower Shell is functional
    Well, our FF services are running and PowerShell is functional. I checked some forums and found some problems when there is entries in the IP Allow / Block lists in Exchange UI. I removed those entries but problem remains.
    Any ideas would be appreciated.
    Xavier Villafuerte

    In my case, I was able to work around this issue by using  PowerShell directly.  For example, to run an on-demand scan for all mailboxes, this worked:
    #open EMS
    $aliases = (get-mailbox -result unlimited).alias
    Add-PsSnapin FSSPSSnapin
    set-FseOnDemandScan -MailboxList $aliases
    Start-FseOnDemandScan -EnableVirusScan $true
    Windows 2008 R2 SP1
    Exchange 2010 SP3, RU9
    PowerShell 4.0 present on the machine (though EMS runs PS 2.0)
    Forefront PowerShell cmdlets:
    https://technet.microsoft.com/en-us/library/cc482986.aspx
    Mike Crowley | MVP
    My Blog --
    Baseline Technologies

Maybe you are looking for