Performance of will_paginate + stored programs

Hi all,
What your experience with performance of will_paginate with stored procedures/functions? I have a few pipelined functions following the procedure described at http://wiki.rubyonrails.org/rails/pages/OracleStoredProceduresAsDataSource and uses will_paginate for it.
As you know, a code such as
paginate_by_sql([
"select col1, col2, col3 from table(function(?,?))", "#{param1}", "#{param2}",
], options)
will automatically form:
select count(*) from (select col1, col2, col3 from table(function(param1,param2)))
to count the results. This looks like it will result in Oracle needlessly retrieving data for col1, col2, etc when all that is needed is the number of results. Or is there (hopefully) some sophistication/intelligence that determines otherwise?
And then to get for example results 76-90 will_paginate forms:
select * from
(select raw_sql_.*, rownum raw_rnum_ from
(select col1, col2, col3 from table(function(param1,param2))) raw_sql_
where rownum <= 90) where raw_rnum_ > 75
Again, does this mean the pipelined function will still read all the data for results 1-75 first to form the "table"? If so, that would be a waste. Does it look like it's not ideal to use will_paginate with stored programs? Would appreciate to know what you think.
Thank you very much.
Johann
Edited by: johanntagle on Dec 9, 2008 4:06 AM

Short answer: it depends.
There will probobaly be very little difference in performance difference for a sipmle insert / update etc.
Multiple inserts / updates etc you will probobaly find faster with a stored procedure rather than n prepared statments as you only have to contact the database once vs n times.
Hope this helps!

Similar Messages

  • How to declare local variables in PL/SQL stored programs

    Where do I declare local variables in a PL/SQL stored program?
    I get compiler errors with either of the options below:
    FUNCTION GET_PRINCIPAL_BALANCE (CUT_OFF_DATE IN DATE, TITLE_SN IN DATE, TOTAL_BALANCE OUT NUMBER) RETURN NUMBER IS
    TOTAL_BALANCE NUMBER;
    BEGIN
    RETURN TOTAL_BALANCE;
    END;
    FUNCTION GET_PRINCIPAL_BALANCE (CUT_OFF_DATE IN DATE, TITLE_SN IN DATE, TOTAL_BALANCE OUT NUMBER) RETURN NUMBER IS
    BEGIN
    TOTAL_BALANCE NUMBER;
    RETURN TOTAL_BALANCE;
    END;

    Your local variable cannot have the same name as the formal out parameter. This is a procedure example, but since functions should not have out parameters anyway ...
    session2> CREATE PROCEDURE p (p_id IN NUMBER, p_did OUT NUMBER) AS
      2     p_did NUMBER;
      3  BEGIN
      4     p_did := p_id * 2;
      5  END;
      6  /
    Warning: Procedure created with compilation errors.
    session2> show error
    Errors for PROCEDURE P:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    1/1      PLS-00410: duplicate fields in RECORD,TABLE or argument list are
             not permittedThe proper way to create a function would be something like:
    CREATE FUNCTION f (p_id IN NUMBER) RETURN NUMBER AS
       l_did NUMBER;
    BEGIN
      l_did := p_id * 2;
      RETURN l_did;
    END;You should really assign a value to the variable before you return it.
    John

  • Performance  of a ABAP program

    Hi Friends,
    I have one doubt , in Performance  of a ABAP program.
    Which one gives good performance in Select Statement
    Open Cusor.. Select ... Close cusor  OR
    Select ..Package Size <n>
    If anybody having the  Idea please let me know .
    With Thanx.
    Elango

    Hi elangoraj,
    1. There is no standard calculation / method
       to determine the  package size.
    2. Its totally subjective and depends upon
      - the total number of records in database table,
      - the time taken to fetch one package
      - how many fetches we want.
    3. Usually It can be kept from 100 - 500.
    regards,
    amit m.

  • How to improve the performance of the abap program

    hi all,
    I have created an abap program. And it taking long time since the number of records are more. And can anyone let me know how to improve the performance of my abap program.
    Using se30 and st05 transaction.
    can anyone help me out step by step
    regds
    haritha

    Hi Haritha,
    ->Run Any program using SE30 (performance analysis)
    Note: Click on the Tips & Tricks button from SE30 to get performance improving tips.
    Using this you can improve the performance by analyzing your code part by part.
    ->To turn runtim analysis on within ABAP code insert the following code
    SET RUN TIME ANALYZER ON.
    ->To turn runtim analysis off within ABAP code insert the following code
    SET RUN TIME ANALYZER OFF.
    ->Always check the driver internal tables is not empty, while using FOR ALL ENTRIES
    ->Avoid for all entries in JOINS
    ->Try to avoid joins and use FOR ALL ENTRIES.
    ->Try to restrict the joins to 1 level only ie only for tables
    ->Avoid using Select *.
    ->Avoid having multiple Selects from the same table in the same object.
    ->Try to minimize the number of variables to save memory.
    ->The sequence of fields in 'where clause' must be as per primary/secondary index ( if any)
    ->Avoid creation of index as far as possible
    ->Avoid operators like <>, > , < & like % in where clause conditions
    ->Avoid select/select single statements in loops.
    ->Try to use 'binary search' in READ internal table. -->Ensure table is sorted before using BINARY SEARCH.
    ->Avoid using aggregate functions (SUM, MAX etc) in selects ( GROUP BY , HAVING,)
    ->Avoid using ORDER BY in selects
    ->Avoid Nested Selects
    ->Avoid Nested Loops of Internal Tables
    ->Try to use FIELD SYMBOLS.
    ->Try to avoid into Corresponding Fields of
    ->Avoid using Select Distinct, Use DELETE ADJACENT
    Check the following Links
    Re: performance tuning
    Re: Performance tuning of program
    http://www.sapgenie.com/abap/performance.htm
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
    check the below link
    http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
    See the following link if it's any help:
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
    Check also http://service.sap.com/performance
    and
    books like
    http://www.sap-press.com/product.cfm?account=&product=H951
    http://www.sap-press.com/product.cfm?account=&product=H973
    http://www.sap-img.com/abap/more-than-100-abap-interview-faqs.htm
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
    Performance tuning for Data Selection Statement
    http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
    Debugger
    http://help.sap.com/saphelp_47x200/helpdata/en/c6/617ca9e68c11d2b2ab080009b43351/content.htm
    http://www.cba.nau.edu/haney-j/CIS497/Assignments/Debugging.doc
    http://help.sap.com/saphelp_erp2005/helpdata/en/b3/d322540c3beb4ba53795784eebb680/frameset.htm
    Run Time Analyser
    http://help.sap.com/saphelp_47x200/helpdata/en/c6/617cafe68c11d2b2ab080009b43351/content.htm
    SQL trace
    http://help.sap.com/saphelp_47x200/helpdata/en/d1/801f7c454211d189710000e8322d00/content.htm
    CATT - Computer Aided Testing Too
    http://help.sap.com/saphelp_47x200/helpdata/en/b3/410b37233f7c6fe10000009b38f936/frameset.htm
    Test Workbench
    http://help.sap.com/saphelp_47x200/helpdata/en/a8/157235d0fa8742e10000009b38f889/frameset.htm
    Coverage Analyser
    http://help.sap.com/saphelp_47x200/helpdata/en/c7/af9a79061a11d4b3d4080009b43351/content.htm
    Runtime Monitor
    http://help.sap.com/saphelp_47x200/helpdata/en/b5/fa121cc15911d5993d00508b6b8b11/content.htm
    Memory Inspector
    http://help.sap.com/saphelp_47x200/helpdata/en/a2/e5fc84cc87964cb2c29f584152d74e/content.htm
    ECATT - Extended Computer Aided testing tool.
    http://help.sap.com/saphelp_47x200/helpdata/en/20/e81c3b84e65e7be10000000a11402f/frameset.htm
    Just refer to these links...
    performance
    Performance
    Performance Guide
    performance issues...
    Performance Tuning
    Performance issues
    performance tuning
    performance tuning
    You can go to the transaction SE30 to have the runtime analysis of your program.Also try the transaction SCI , which is SAP Code Inspector.
    edited by,
    Naveenan

  • Performance issue in customized program

    Hi,
    We have a performance issue in customized program.
    In this program he used do-enddo twice. I mean nested do-endo.
    How can we increase the performance.
    And when we did the code inspector it displays 9 errors 'Char. strings w/o text elements will not be translated'.
    Is there any performance issue for this error?
    Regards,
    Chandu.

    >  'Char. strings w/o text elements will not be translated'.
    > Is there any performance issue for this error?
    No, this is just not so clean programming. As for the rest, Please Read before Posting in the Performance and Tuning Forum and learn how to find out where the showstoppers really are.
    Thomas

  • Performance issue in customized program with do-enddo

    Hi,
    We have a performance issue in customized program.
    In this program he used do-enddo twice. I mean nested do-endo.
    How can we increase the performance.
    And when we did the code inspector it displays 9 errors 'Char. strings w/o text elements will not be translated'.
    Is there any performance issue for this error?
    Regards,
    Chandu.
    Moderator message - Cross post locked
    Edited by: Rob Burbank on Oct 20, 2009 12:42 PM

    >  'Char. strings w/o text elements will not be translated'.
    > Is there any performance issue for this error?
    No, this is just not so clean programming. As for the rest, Please Read before Posting in the Performance and Tuning Forum and learn how to find out where the showstoppers really are.
    Thomas

  • Test PC performance for certain LabView program

    Hello, 
    I am interesting in how to check minimum PC performance for certain LabView program?
    Thanks 

    I would say to look up the requirements for the RunTime Engine.  If you think you need more processing power, increase your requirements some.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • "Find..." in stored program units

    It would be nice if "Find..." was allowed in a stored program unit. Currently, this is only possible after choosing the "Edit" button in the "Code" tab.

    i bet this is, because the find and the replace-dialog are identical and you aren't allowed to replace in non-edit-mode.
    if the find-dialog can be started via parameters then one mode should be "Find only" where the "Replace" is disabled or hidden, so that you can use the find functionality in the non-edit-mode of a source-code

  • Change connection schema in Stored Program?

    Hi,
    Can anyone tell me if I can change connection schema in a stored program (not form program unit)? Does Oracle provide any build-in?
    Thanks.

    I could not think of a direct command to change connection. But I have written a tool that will read the username, password and database name from a table and dynamically create the link from within the procedure and use the link for further processing.
    The rough out line is as follows.
    1. read the table containing
    databasename, password, connect str
    2. dbms_sql or dbma_utility function to
    create a link for those parameters
    the link name can be some thing like
    mylink.
    3. further dmls on the procedure
    like
    select * from xxxx@mylink;
    But if you want the statements in the statements in step 3 to be non-dynamic sql then create a dummy link mylink to the current schema itself, so that the procedure will not have any compilation problem. also make sure whatever tables structures used in step 3 exist in the current schema.
    null

  • Stored Program Editor

    It would be nice to have the following features in the stored program editor:
    - outline view
    - navigate to another object by ctrl-click onto its name
    - named bookmarks (i.e. 0, 1, 2, ...) with an associated shortcut to navigate there
    I really like Raptor - it's a great tool!

    These are logged enhancements.
    -kris

  • Load stored program package into another db

    Hi,
    Let say I have a created a stored program package (contains spec and body) in an oracle database
    developed using sql developer.
    How do I transfer and load my stored program package into another oracle database?
    Do I also need to recompile after I did so?
    Thanks.

    You connect to the other database and recompile the code.

  • Tables storing Program Performance time

    Hi All,
    Can any one tell me the TAbles which store the
    execution time of  proagrams which are runnning daily .
    Regards
    Babu

    Hi Al,
    Not for JOB .
    ABAP programs running in foreground...
    Regards
    babu

  • Performance issue in abap program

    hi,
    how can we improve the performance of  abap program

    hi,
    read the follwing links
    ABAP provides few tools to analyse the perfomance of the objects, which was developed by us.
    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
    by using this tool we can analyse the perfomance issues related to DATABASE calls.
    Perfomance Techniques for improve the perfomance of the object.
    1) ABAP/4 programs can take a very long time to execute, and can make other processes have to wait before executing. Here are some tips to speed up your programs and reduce the load your programs put on the system:
    2) Use the GET RUN TIME command to help evaluate performance. It's hard to know whether that optimization technique REALLY helps unless you test it out.
    3) Using this tool can help you know what is effective, under what kinds of conditions. The GET RUN TIME has problems under multiple CPUs, so you should use it to test small pieces of your program, rather than the whole program.
    4) Generally, try to reduce I/O first, then memory, then CPU activity. I/O operations that read/write to hard disk are always the most expensive operations. Memory, if not controlled, may have to be written to swap space on the hard disk, which therefore increases your I/O read/writes to disk. CPU activity can be reduced by careful program design, and by using commands such as SUM (SQL) and COLLECT (ABAP/4).
    5) Avoid 'SELECT *', especially in tables that have a lot of fields. Use SELECT A B C INTO instead, so that fields are only read if they are used. This can make a very big difference.
    6) Field-groups can be useful for multi-level sorting and displaying. However, they write their data to the system's paging space, rather than to memory (internal tables use memory). For this reason, field-groups are only appropriate for processing large lists (e.g. over 50,000 records). If you have large lists, you should work with the systems administrator to decide the maximum amount of RAM your program should use, and from that, calculate how much space your lists will use. Then you can decide whether to write the data to memory or swap space.
    Use as many table keys as possible in the WHERE part of your select statements.
    7)Whenever possible, design the program to access a relatively constant number of records (for instance, if you only access the transactions for one month, then there probably will be a reasonable range, like 1200-1800, for the number of transactions inputted within that month). Then use a SELECT A B C INTO TABLE ITAB statement.
    8) Get a good idea of how many records you will be accessing. Log into your productive system, and use SE80 -> Dictionary Objects (press Edit), enter the table name you want to see, and press Display. Go To Utilities -> Table Contents to query the table contents and see the number of records. This is extremely useful in optimizing a program's memory allocation.
    9) Try to make the user interface such that the program gradually unfolds more information to the user, rather than giving a huge list of information all at once to the user.
    10) Declare your internal tables using OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to be accessing. If the number of records exceeds NUM_RECS, the data will be kept in swap space (not memory).
    11) Use SELECT A B C INTO TABLE ITAB whenever possible. This will read all of the records into the itab in one operation, rather than repeated operations that result from a SELECT A B C INTO ITAB... ENDSELECT statement. Make sure that ITAB is declared with OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to access.
    12) If the number of records you are reading is constantly growing, you may be able to break it into chunks of relatively constant size. For instance, if you have to read all records from 1991 to present, you can break it into quarters, and read all records one quarter at a time. This will reduce I/O operations. Test extensively with GET RUN TIME when using this method.
    13) Know how to use the 'collect' command. It can be very efficient.
    14) Use the SELECT SINGLE command whenever possible.
    15) Many tables contain totals fields (such as monthly expense totals). Use these avoid wasting resources by calculating a total that has already been calculated and stored.
    Some tips:
    1) Use joins where possible as redundant data is not fetched.
    2) Use select single where ever possible.
    3) Calling methods of a global class is faster than calling function modules.
    4) Use constants instead of literals
    5) Use WHILE instead of a DO-EXIT-ENDDO.
    6) Unnecessary MOVEs should be avoided by using the explicit work area operations
    see the follwing links for a brief insifght into performance tuning,
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_Introduction.asp
    http://help.sap.com/saphelp_nw2004s/helpdata/en/d1/801f7c454211d189710000e8322d00/frameset.htm
    regards
    Rohan

  • Performance issue with a program in HR-ABAP

    Hi All,
    I have a program that is taking very much time to execute please suggest some solution. I am pasting the  main code below.
    <large code part removed by moderator>
    Moderator message: Please Read before Posting in the Performance and Tuning Forum
    Moderator message: please post only relevant code parts, otherwise formatting is lost.
    Edited by: Thomas Zloch on Mar 1, 2011 11:11 AM

    >
    Aaron Shover wrote:
    > OK, Aditya, I added another type pool to my program and I can now use the same type that SAP is using.
    >
    > Thanks for pointing out the [obvious] solution that I was overlooking!
    >
    > Aaron
    Aaron, I was not aware of the type pools as mentioned I don't have access to the system at the moment. But type pool has type declarations as well, so what I meant was pulling out the 2 declarations that you need into your Z program could have solved the problem :). Which will happen now since you've included the type pools.
    Anyways good to know that you problem is solved.
    Cheers,
    Advait

  • Performance of ABAP query program

    Hi All,
    A custom program AQNWZ_TALAT=====TCS_AP_ITEMS== is taking lot of time running. And when checked the cost of the select statement is very high.
    I guessed it must be some custom abap query. Correct me if I am wrong.
    Also please let me know how to do the performance tuning on this code? Should I be editing the program directly or should I edit at the abap query level.
    Regards,
    Pooja
    Moderator message: Please Read before Posting in the Performance and Tuning Forum
    Edited by: Thomas Zloch on Dec 3, 2010 11:01 AM

    >A few tips you can use for finetuning a Report
    The actually a good collection of the most important pain points. But the recommendations are unfortunately quite poor, and even wrong. I have updated them a little bit.
    And for German speaking people I have added a reference to a textbook, where arll my recommendations are explained in detail.
    Siegfried
    1) Use mostly primary key to access data.
    ... nonsense, the task determines the WHERE clause, it is not your choice
    2) Before READ u sort the itab
    No
    3) use mostly the indexes fields in ur where clause.
    ... as 1, it is the other way, the task determines the WHERE-clause, make surwe that there is an index which
    supports it
    4) Restrict the the fields retrieved by your select sentences to the minimal set. (Avoid select *)
    nonsense, most SELECT use and must use *, use field list in wide tables
    5) try to use specify where clause so the abap sql optimizer chooses the right index.
    o.k., but who understands that in depth?
    6) Avoid sentences like select lifnr name1 into corresponding fields of lfa1 from lfa1 where....
    feel free to use if required
    (You should declare a working area and select into the working area, is twice faster)
    ... such general statements are always incorrect
    7) use hashed tables instead of standard tables. They are faster
    no, use sorted tables, hashed are very special and can only be used if there is a unique key
    8) avoid the use of collect as much as you can.
    total nonsense, use collect with hashed tables, works perfect, if you use it with standard tables, do not mix it with other statements
    1 Always check the driver internal tables is not empty , while using FOR ALL ENTRIES
    100% correct
    2 Avoid for all entries in JOINS
    ... not generally true
    3 Try to avoid joins and use FOR ALL ENTRIES.
    ... hmmm, there are pages of discussions, this statement was wrong, is wrong and will be wrong!!!
    4 Try to restrict the joins to 1 level only ie only for 2 tables
    nonsense, joins are complicated, you must know hw indexes are used, if everything is fine, then 10 or 20 tables can be joined
    5 Avoid using Select *.
    see 4)
    6 Avoid having multiple Selects from the same table in the same object.
    ... try to avoid to SELECT the same data, different criteria can be necessary
    7 Try to minimize the number of variables to save memory.
    ... obvious,
    8 The sequence of fields in 'where clause' must be as per primary/secondary index ( if any)
    ... no is must not the optimizer will not be influenced be the order , but do it, it increases readability
    9 Avoid creation of index as far as possible
    ... no, o.k. if you are not experienced than avoid ... otherwise the creation of the required indexes is absolutely mandatory for new tables, for SAP standard tables most indexes are already there. But still if very new accesses are added, then new indexes can become necessary.
    10 Avoid operators like , > , < & like % in where clause conditions
    ... no, you must add them, but be aware that the search is only poorly supported by them, but the result set is reduced.
    11 Avoid select/select single statements in loops.
    ... if they are going to the database! If the tables are buffered, then these statements are perfect!
    12 Try to use 'binary search' in READ internal table. Ensure table is sorted before using BINARY SEARCH.
    .... Actually try to avoid standard tables, use sorted tables instead. If you must use a standard table, than the recommendation is true.
    13 Avoid using aggregate functions (SUM, MAX etc) in selects ( GROUP BY , HAVING,)
    .... no, use them if required. Again, if table is buffered, then they MUST be avoided.
    14 Avoid using ORDER BY in selects
    ... if it is not ORDER BY PRIMARY KEY. Again, if the table is buffered, then other orders MUST be avoided.
    15 Avoid Nested Selects
    ... use join. Again, if the tables are buffered, then Nested SELECTs are fine!
    16 Avoid Nested Loops of Internal Tables
    .... impossible, there is no other option. Use sorted tables and verything is fine!
    17 Try to use FIELD SYMBOLS.
    ... what means try? Use ASSIGNING fieldsymbol in LOOPs, but use it in READs only for very wide tables (>1kB). Use it always for tables with tables in the workarea!
    18 Try to avoid into Corresponding Fields of
    ... see 6) is wrong!
    19 Avoid using Select Distinct, Use DELETE ADJACENT.
    .... no, use it if required and if it can reduce the result set by a factor of 2 or more. Again, if table is buffered, then it MUST be avoided.
    Wenn Sie mit der Performance Ihres ABAP Programms nicht zufrieden sind, werfen Sie doch einen Blick in mein neues Buch:
    Siegfried Boes: Performance-Optimierung von ABAP®-Programmen Nov. 2009 464 Seiten  59u20AC
    Leseproben und weitere Informationen: http://www.dpunkt.de/buecher/3096.html
    Edited by: Thomas Zloch on Dec 3, 2010 10:53 AM

Maybe you are looking for

  • Automatic Creation PO from Sales Order

    Hi All, I'd like to make automatic PO Creation check box (Sales Order - logistics tab) is checked by default (not blank).  Do you have any idea how to do this? Currently I use SAP B1 2005B version. Thanks and Regards

  • Upload to BLOB

    How can you do an upload into a blob using ADF/JSP/Struts? I've seen the demo for OrdDoc but would rather have the blob as it would be easier to move between instances over a db link (cannot do with object type). Thoughts/tips/code? I can provide wha

  • Table does not exists.

    I M TRYING TO TAKE EXPORT OF A TABLE BUT I M GETTING ERROR THAT TABLE DOES NOT EXISTS BUT ACTUALLY TABLE EXISTS... PLEASE SUGGEST Y I M GETTING THIS ERROR. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production Wit

  • Optimizer in simulation version

    We are running SNP Optimization for a simulation version, while we are running the optimizer job, the planners who are working in active version are complaining about system slowness.  Any body come across this situation? if so, what your recommendat

  • Big Issue with BackUp

    I made the back up (Z10) so I have the BBB file, my Z10 had an accident so I bought an Android phone while the ensurance is hiving me another Z10 but hey said it will take about 1 month, so how can I open the BBB file to import those contacts(phones,