About Optimization Of PL/SQL Constructs

Hi All,
I am asking very silly question, some one asked to me how to optimize pl/sql procedure or function.i had explained all the things for optimization of the sql query or we can put the pl/sql subprogram into package.
But from the face expression of the person,i think he wants more from my side,but really i did not know any thing except of these things.
I want to know ideas of the experts on this issue.
Thanks a lot

If by optimization that person was asking about techniques then there are a few general rules. Keeping in mind that general rules are starting points and require validation is every specific case.
1. Never use PL/SQL to do what you can do with SQL.
2. Never use single-row processing when you can process a set
So, for example, you can write three anonymous blocks to do some piece of work ... one that uses SQL such as:
BEGIN
  INSERT INTO t1
  SELECT * FRM t2;
  COMMIT;
END;
Then another that does the same thing with BULK COLLECT and FORALL and finally a third using a cursor loop. Which will be fastest and more efficient doing the same work is reasonably certain.
The second interpretation of the question would be how does one determine the efficiency of PL/SQL and for that I would refer you to the built-in DBMS_PROFILER (10g and before) and DBMS_HPROF (11g) packages.
There are a number of authors that have written very good materials on the subject among which I would suggest you explore asktom.oracle.com, Tom Kyte's many excellent books and Steven Feuerstein. There are many others but this will give you a good starting point.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Why is optimizer different in sql than in pl/sql?

    Hello, I am running Oracle database 9i, it is running on an On-Demand hosted server, its purpose is to serve our Oracle Payroll application.
    I have a certain query, and first tried it as a stand-alone query. It displayed the results almost immediatly.
    Then I inserted the exact same query in a pl/sql block. It took more than one hour and canceled it. By looking at the session browser in TOAD, I saw that it was stuck on that query.
    I also saw that the explain-plan for the query changed drastically from running as stand-alone sql to running inside pl/sql.
    Why is this happening? How can I avoid this?
    Please note that I do not intend to use optimizer hint since the indexes are built by oracle On-Demand and not me, so I don't know which indexes exist.
    Here is the explain plan when running from stand-alone SQL:
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE          1           65                     
    bq. SORT AGGREGATE          1      72
    bq. bq. TABLE ACCESS BY INDEX ROWID     HR.PAY_ELEMENT_ENTRY_VALUES_F     1      13      4
    bq. bq. bq. NESTED LOOPS          1      72      65
    bq. bq. bq. bq. MERGE JOIN CARTESIAN          1      59      61
    bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID     HR.PAY_ELEMENT_ENTRY_VALUES_F     1      13      4
    bq. bq. bq. bq. bq. bq. NESTED LOOPS          1      36      33
    bq. bq. bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID     HR.PAY_ELEMENT_ENTRIES_F     1      23      29
    bq. bq. bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN     HR.PAY_ELEMENT_ENTRIES_F_N50     44           3
    bq. bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN     HR.PAY_ELEMENT_ENTRY_VALUES_F_N50     9           3
    bq. bq. bq. bq. bq. BUFFER SORT          1      23      57
    bq. bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID     HR.PAY_ELEMENT_ENTRIES_F     1      23      28
    bq. bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN     HR.PAY_ELEMENT_ENTRIES_F_N50     44           2
    bq. bq. bq. bq. INDEX RANGE SCAN     HR.PAY_ELEMENT_ENTRY_VALUES_F_N50     9           3
    And here is the plan when running inside pl/sql:
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 293463
    bq. SORT AGGREGATE 1 48
    bq. bq. MERGE JOIN CARTESIAN 1 M 56 M 293463
    bq. bq. bq. MERGE JOIN CARTESIAN 78 3 K 3771
    bq. bq. bq. bq. MERGE JOIN CARTESIAN 1 34 57
    bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRIES_F 1 17 29
    bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRIES_F_N50 44 3
    bq. bq. bq. bq. BUFFER SORT 1 17 28
    bq. bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRIES_F 1 17 28
    bq. bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRIES_F_N50 44 2
    bq. bq. bq. BUFFER SORT 15 K 107 K 3743
    bq. bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRY_VALUES_F 15 K 107 K 3714
    bq. bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRY_VALUES_F_N1 15 K 39
    bq. bq. BUFFER SORT 15 K 107 K 289749
    bq. bq. bq. TABLE ACCESS BY INDEX ROWID HR.PAY_ELEMENT_ENTRY_VALUES_F 15 K 107 K 3714
    bq. bq. bq. bq. INDEX RANGE SCAN HR.PAY_ELEMENT_ENTRY_VALUES_F_N1 15 K 39
    As you can see, the cost goes way up when running inside a pl/sql block.
    Thank you very much for your help.
    Eduardo Schñadower
    Edited by: shinaco on Dec 12, 2008 4:10 PM
    Added indentation. Sorry for that, I didn't realize copy-paste didn't work well here.

    I meant to add,
    Why is optimizer different in sql than in pl/sql? It is not different, it is the same optimizer.
    If you replace bind variables with literals then you have a totally different query, with much more information available to the optimizer. If you are seeing the same statement with the same literal values get a different plan within PL/SQL than in SQL*Plus or TOAD etc then there must be something else different. Unfortunately there is a lot less diagnostic info available in 9i (and I don't have 9i around to test on). Perhaps you can get a 10053 trace from each session and see if you can see what is different.
    btw I still can't read the execution plan. There is more information in the DBMS_XPLAN output, and it needs to be formatted using ** tags or equivalent HTML.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • (V7.3)NEW FEATURES ABOUT OPTIMIZATION IN RELEASE 7.2 & 7.3

    제품 : ORACLE SERVER
    작성날짜 : 2003-02-24
    (V7.3)NEW FEATURES ABOUT OPTIMIZATION IN RELEASE 7.2 & 7.3
    ==========================================================
    PURPOSE
    Oracle RDBMS V7.2와 V7.3에서 Optimization에 관한 new feature를
    알아보기로 한다.
    Explanation
    다음과 같은 대표적인 기능 9가지가 있습니다.
    1> Direct Database Reads
    Parallel query 프로세스들은 필터링이나, 소팅, 조인과 같은 작업을
    수행하기 위해서는 아주 큰 테이블을 scanning해야 합니다. Direct Database
    Reads는 read efficiency와 성능의 향상을 위해 contiguous memory read를
    가능하게 해줍니다.
    또한, concurrent OLTP와 같은 작업을 수행시 따르는 경합을 없애기
    위해 버퍼 캐쉬를 bypass합니다.
    2> Direct Database Writes
    Parallel query 프로세스들은 intermediate sort runs, summarization
    (CREATE TABLE AS SELECT), index creation(CREATE INDEX)과 같은 작업의
    수행 결과를 디스크에 종종 기록해야 합니다.
    Direct Database Writes는 write efficiency와 성능의 향상을 위해
    direct contiguous memory로 하여금 contiguous disk writes를 가능하게
    해줍니다.
    또한, concurrent OLTP 작업과 DBWR 프로세스에 의한 경합을 없애기 위해
    버퍼 캐쉬를 bypass합니다.
    결론적으로, Direct Database Reads와 Writes는 concurrent OLTP와 DSS
    작업에 따르는 복잡한 부하를 조절하면서 Oracle 7 서버를 분리된 형태로,
    또한 최적의 튜닝을 가능하게 해줍니다.
    3> Asynchronous I/O
    Oracle 7은 이미 sorts, summarization, index creation, direct-path
    loading 에 대한 asynchronous write 기능을 제공하고 있습니다.
    Release 7.3부터는 보다 나은 성능의 향상을 위해 asynchronous
    read-ahead 기능을 제공하여 최대한 processing과 I/O의 병행성을 증가
    시켜 줍니다.
    4> Parallel Table Creation
    CREATE TABLE ... AS SELECT ...와 같은 구문을 제공하여 상세한 데이타를
    갖는 큰 테이블의 조회된 결과를 저장하기 위해 임시 테이블을 생성합니다.
    이 기능은 보통 intermediate operation의 결과를 저장하기 위해
    drill-down 분석을 할 때 사용됩니다.
    5> Support for the Star Query Optimization
    Oracle 7은 수행 속도의 향상을 위해 star 스키마가 존재하고, star query
    optimization을 invoke 합니다. Star query는 먼저 여러 개의 작은 테이블을
    join하고, 그런 후에, 그 결과를 하나의 큰 테이블로 join합니다.
    6> Intelligent Function Shipping
    Release 7.3부터 parallel query를 처리하는 coordinator 프로세스는
    non-shared memory machine(cluster 또는 MPP) 내의 노드들을 처리하기
    위해 디스크나 데이타들 간의 유사성에 대해 인식하게 될 것입니다.
    이 사실에 근거하여, coordinator는 data들이 machine의 shared
    interconnect를 통해 전달될 필요가 없다는 점에서, 특정 node-disk pair로
    수행되고 있는 프로세스들에게 parallel query operation을 지정할 수
    있습니다.
    이 기능은 연관된 cost나 overhead없이 'shared nothing' 소프트웨어
    아키텍쳐의 잇점을 제공하면서 효율성과 성능, 확장성을 개선할 수 있습니다.
    7> Histograms
    Release 7.3부터 Oracle optimizer는 테이블의 컬럼 내에 있는 데이타 값의
    분포에 관한 더 많은 정보를 이용할 수 있습니다. Value와 상대적 빈도수를
    나타내는 histogram은 optimizer에게 index의 상대적'selectivity'에 관한
    정보와 어떤 index를 사용해야할 지에 관한 더 좋은 아이디어를 제공해
    줄 것입니다.
    적절한 선택을 한다면, query의 수행시간을 몇 분, 심지어 몇 시간씩이나
    단축시킬 수가 있습니다.
    8> Parallel Hash Joins
    Release 7.3부터 Oracle 7은 join 처리시간의 단축을 위하여 hash join을
    제공합니다. 해슁 테크닉을 사용하면 join을 하기 위해 데이타를 소트하지
    않아도 되며, 기존에 존재하는 인덱스를 사용하지 않으면서 'on-the-fly'
    라는 개념을 제공합니다. 따라서, star schema 데이타베이스에 전형적으로
    적용되는 small-to-large 테이블 join의 수행 속도를 향상시킬 것입니다.
    9> Parallel UNION and UNION ALL
    Release 7.3부터 Oracle 7은 UNION과 UNION ALL과 같은 set operator를
    사용하여 완전히 parallel하게 query를 수행할 수 있습니다. 이러한
    operator를 사용하면, 큰 테이블들을 여러 개의 작은 테이블의 집합으로
    나누어 처리하기가 훨씬 쉬워질 것입니다.
    Example
    none
    Reference Documents
    none

    Sorry for the confusion!
    I'll clear it up right now - I'm currently running 10.7.2 - please disregard SL 10.6.8, that was from the past. I updated to 10.7.3, the new checkmark appeared. I noticed a few other stability issues in 10.7.3, so returned to 10.7.2. As for Mountain Lion - I saw a friend's Mac running ML (I assume he had a Dev account), and noticed the new checkmark as well.
    Here's the pictures to show the comparison:
    10.7.2 Checkmark
    10.7.3/ML Checkmark:
    See the difference? My question is, I don't want the new checkmark in 10.7.3. I think, personally, it's hideous and very iOS-like. Is there a way I can "hack" a resource file, or copy over a file from 10.7.2 into 10.7.3 to bring back the original checkmark used in 10.7.2 and all prior versions of OSX? I'm not sure, but it seems like some kind of font is used for the checkmark, but I'm not sure. I'm still a bit new to OSX.
    If anyone knows, or has any idea, that would be much appreciated! Again, I know it's a bit nitpicky

  • Asking about the most simplest SQL technique

    select table1.field1,table1.field2
    from table1, table2
    where table2.category = 'A' and
    table1.pk = table2.fk
    =========================================
    If table1 contains 500 records while table2 contain 400,000 records, then table2 should be placed to the most righthand side ?
    If table2 has 1000 category 'A' record while
    table2 has 80,000 records contain the pk of table1, then table1.pk = table2.fk should be placed on the most lower part in the where clause ?

    It used to be the case that you had to consider these issues with some DBMS's, but generally not any more.
    Sophisticated systems like Oracle can maintain sets of statistics on tables, and on the distribution of values within fields. If the DBA chooses to, he can run commands to make Oracle analyze individual tables and columns, and the statistics produced will be considered when choosing an access path for the data.
    So, the database will know how many records are in the tables in your example query, and roughly how many category 'A' records are in table2 etc.. It will also know whether there are indexes on the columns, and will work out roughly how many bytes must be read to return the result depending on whether the indexes are used, which table is scanned first, and what join technique should be used.
    Look in the Oracle documentation for the description of the ANALYZE command, the SQL*Plus command "set autotrace traceonly explain", and in the section on performance have a read of everything to do with the optimizer. It's an important area to know more about if you want to get the most out of Oracle, and is quite an eye-opener if you are moving to Oracle (or any complex RDBMS) frm simpler products (Foxpro, Access etc). Good luck.

  • A question about the impact of SQL*PLUS SERVEROUTPUT option on v$sql

    Hello everybody,
    SQL> SELECT * FROM v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0  Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL>
    OS : Fedora Core 17 (X86_64) Kernel 3.6.6-1.fc17.x86_64I would like to ask a question about the SQL*Plus SET SERVEROUTPUT ON/OFF option and its impact on queries on views such as v$sql and v$session. Here is the problem
    Actually I define three variables in SQL*Plus in order to store sid, serial# and prev_sql_id columns from v$session in order to be able to use them later, several times in different other queries, while I'm still working in the current session.
    So, here is how I proceed
    SET SERVEROUTPUT ON;  -- I often activate this option as the first line of almost all of my SQL-PL/SQL script files
    SET SQLBLANKLINES ON;
    VARIABLE mysid NUMBER
    VARIABLE myserial# NUMBER;
    VARIABLE saved_sql_id VARCHAR2(13);
    -- So first I store sid and serial# for the current session
    BEGIN
        SELECT sid, serial# INTO :mysid, :myserial#
        FROM v$session
        WHERE audsid = SYS_CONTEXT('UserEnv', 'SessionId');
    END;
    PL/SQL procedure successfully completed.
    -- Just check to see the result
    SQL> SELECT :mysid, :myserial# FROM DUAL;
        :MYSID :MYSERIAL#
           129   1067
    SQL> Now, let's say that I want to run the following query as the last SQL statement run within my current session
    SELECT * FROM employees WHERE salary >= 2800 AND ROWNUM <= 10;According to Oracle® Database Reference 11g Release 2 (11.2) description for v$session
    http://docs.oracle.com/cd/E11882_01/server.112/e25513/dynviews_3016.htm#REFRN30223]
    the column prev_sql_id includes the sql_id of the last sql statement executed for the given sid and serial# which in the case of my example, it will be the above mentioned SELECT query on the employees table. As a result, right after the SELECT statement on the employees table I run the following
    BEGIN
        SELECT prev_sql_id INTO :saved_sql_id
        FROM v$session
        WHERE sid = :mysid AND serial# = :myserial#;
    END;
    PL/SQL procedure successfully completed.
    SQL> SELECT :saved_sql_id FROM DUAL;
    :SAVED_SQL_ID
    9babjv8yq8ru3
    SQL> Having the value of sql_id, I'm supposed to find all information about cursor(s) for my SELECT statement and also its sql_text value in v$sql. Yet here is what I get when I query v$sql upon the stored sql_id
    SELECT child_number, sql_id, sql_text
    FROM v$sql
    WHERE sql_id = :saved_sql_id;
    CHILD_NUMBER   SQL_ID          SQL_TEXT
    0              9babjv8yq8ru3    BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;Therefore instead of
    SELECT * FROM employees WHERE salary >= 2800 AND ROWNUM <= 10;for the value of sql_text I get the following value
    BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES);Which is not of course what I was expecting to find in v$sql for the given sql_id.
    After a bit googling I found the following thread on the OTN forum where it had been suggested (well I think maybe not exactly for the same problem) to turn off SERVEROUTPUT.
    Problem with dbms_xplan.display_cursor
    This was precisely what I did
    SET SERVEROUTPUT OFFafter that I repeated the whole procedure and this time everything worked pretty well as expected. I checked SQL*Plus documentation for SERVEROUTPUT
    and also v$session page, yet I didn't find anything indicating that SERVEROUTPUT should be switched off whenever views such as v$sql, v$session
    are queired. I don't really understand the link in terms of impact that one can have on the other or better to say rather, why there is an impact
    Could anyone kindly make some clarification?
    thanks in advance,
    Regards,
    Dariyoosh

    >
    and also v$session page, yet I didn't find anything indicating that SERVEROUTPUT should be switched off whenever views such as v$sql, v$session
    are queired. I don't really understand the link in terms of impact that one can have on the other or better to say rather, why there is an impact
    Hi Dariyoosh,
    SET SERVEROUTPUT ON has the effect of executing dbms_output.get_lines after each and every statement. Not only related to system view.
    Here below what Tom Kyte is explaining in this page:
    Now, sqlplus sees this functionality and says "hey, would not it be nice for me to dump this buffer to screen for the user?". So, they added the SQLPlus command "set serveroutput on" which does two things
    1) it tells SQLPLUS you would like it <b>to execute dbms_output.get_lines after each and every statement</b>. You would like it to do this network rounding after each call. You would like this extra overhead to take place (think of an install script with hundreds/thousands of statements to be executed -- perhaps, just perhaps you don't want this extra call after every call)
    2) SQLPLUS automatically calls the dbms_output API "enable" to turn on the buffering that happens in the package.Regards.
    Al

  • Question about using objects in SQL query.

    I had posted this question in the SQL/PLSQL forum but I guess nobody took the time to understand exactly what I am asking so I decided to try here hoping to get the answer. So here is the thing:
    I have created generic object type "tree" - the constructor takes as a parameter sql query which returns "node_id" and "parent_node_id" - this is all we need to have a tree. The object has all related to a tree structure member functions and one of them is "oldest_relative" (the tree may not be fully connected - it may be more like a set of many trees, so it's not necessary all nodes to have the same root).
    I also have departments table with the following fields: department_id, parent_department_id, department_name,...
    all records in the table w/out parent_departments (parent_department_id is null) are considered divisions.
    Now if I run the following query:
    SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT_NAME", tree('select department_id "node_id", parent_department_id "parent_node_id" from departments').oldest_relative("DEPARTMENT_ID") "DIVISION_ID" FROM departments
    my question is: Is the tree object created for every row or does Oracle somehow caches the object since the object itself is not changing but only the parameter for the oldest_relative member function.
    The table only has a few hunderd records and I can't see much of a difference in the execution time btw the query above and query like this:
    SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT_NAME", b.t.oldest_relative("DEPARTMENT_ID") "DIVISION_ID"
    FROM departments left join (select tree('select department_id "node_id", parent_department_id "parent_node_id" from departments') t from dual) b on 1 = 1
    where the object is clearly created just ones. (there is probably a better way to do it instead of this join)
    Pls elaborate
    George

    Not exactly sure what the question is...
    As I understand, you are comparing the following two constructor calls:
    +select..  tree('select department_id "node_id", parent_department_id "parent_node_id" from departments').oldest_relative("DEPARTMENT_ID") ... FROM ...+
    +select tree('select department_id "node_id", parent_department_id "parent_node_id" from departments') ... FROM dual+
    These calls are the same (besides the 1st one doing an immediate implicit call to a method of the object being constructed). The number of times these are being called depends on the number of times this SQL projection is applied - and that is determined by the number of rows being projected by the SELECT.
    The latter one is against DUAL which only has a single row. So that constructor is only called once. The former can be against multiple rows. Obviously a single pass through a data set is desirable - which means that the sub-select (use by the constructor) should ideally only be executed once and makes the 2nd method more desirable.
    However, I'm having a hard time understanding why the class and constructor are at all needed. Why pull data from a SQL table into PL memory? As that is where the class will need to cache and store the results of that construction parameter SQL SELECT. And once in PL memory, how does the object effectively access, search and use this cached data?
    PL memory is expensive. It is not sharable.
    PL data structures are primitive - these cannot be compared to SQL structures in the form of tables and columns that can be stored in a number of physical ways (index tables, hash tables, partitioned tables, clustered tables, etc). Cannot be indexed like SQL structures using B+tree, bitmap, function and other indexing methods. Cannot be sorted, grouped, analysed, filtered, etc like SQL structured data.
    It makes very little sense to read SQL data into a class and then deal with that data, cached in expensive PL memory, using primitive PL structures.
    And the same would be true if Java or C# was used. The best place for data is inside the SQL engine. That is the most superior environment for data. It can processes more data, scale better, perform better and offer more flexibility, than pulling data from it and then crunch that data using PL or Java or C#.

  • About creating functions in SQL Developer

    I have successfully installed Oracle SQL Developer.Also I have got a book on Oracle SQL Developer by Dan Hotka.
    After going through the book I could not a solution for creating and compiling functions without any errors.

    What errors?
    How about going through the tutorial inside the online help (Help - Table of Contents - Tutorial)?
    Have fun,
    K.

  • Question about B1if-Database in SQL-Mgmt-Studio

    Hello,
    We have made some changes in the configuration in SLD.
    We made some more Di-Proxy-Ports and then made Proxygroups for the Databases.
    Nearly every half hour, in SQL-Mgmt Studio we can see this "task" ?
    During the time, this task is online, the Queue-Monitor collects all Jobs... but not more.
    After this Job has finished... B1i begins to work up the jobs.
    Can anyone tell me something about "Rollback Transac" in  B1if-Database ?
    Thanks
    Markus

    Passing the exam and becoming certified are not a matter of simply reading a book or taking a training class. While books and classroom materials as well as in-class training are all important steps in preparing for an exam, experience and research are just as important. I cannot tell you that there are 53 questions on the exam and every single question maps directly back to page 13, paragraph 3 in XX book. However, If you have the classroom material, and you have the list of exam topics, you should be able to find most of the information you need. In some cases, if you are not completely familiar with a specific topic, or you don't feel like the information in the book gives you all the information you need, you may need to do a little additional research. This is all part of preparing for an exam. This process is what makes you successful as a certified professional.
    Your focus seems to be solely on the course materials that you have and what volumes and chapters you should read. I'm trying to give you a different perspective - preparing for an exam is not necessarily about taking one course or reading one book and being ready. You need to review the exam topics and be sure that you are familiar with each topic.
    Regards,
    Brandye Barrington

  • Performance and optimization from R - SQL in Oracle

    Hello,
    I'm assessing the adoption of Oracle R. I've glanced some of the Learning R Series files and forum threads but didn't find the answers I need.
    My questions are:
    1: Given any R source code, how to view the resulting SQL (or maybe PL/SQL) script?
    2. Would "my" optimization of db objects (e.g. creating an index, ALTERing a procedure) disrupt functionality?
    3. Are Vectorize, tapply, lapply, etc fully implemented in Oracle R? I'm guessing the answer will be yes.
    4. Is every line in R submitted to the db, or do any portions run purely in R? This relates to scenarios (if any) where an operation might be more efficient on SQL than on R or viceversa.
    Thank you.

    1. Given any R source code, how to view the resulting SQL (or maybe PL/SQL) script?We do not expose this.
    2. Would "my" optimization of db objects (e.g. creating an index, ALTERing a procedure) disrupt functionality?It will be considered by the query optimizer when building a plan.
    3. Are Vectorize, tapply, lapply, etc fully implemented in Oracle R? I'm guessing the answer will be yes.There is support for some predefined functions. To work with custom functions we have a family of <tt>ore.*Apply</tt> functions.
    4. Is every line in R submitted to the db, or do any portions run purely in R? This relates to scenarios (if any) where an operation might be more efficient on SQL than on R or viceversa.It is a mixed mode. ORE makes the decision. But in general not every line is executed right away. The execution is deferred to the point when the results are requested on the client side.
    Denis

  • About optimizer mode

    Hi,
    How to change the optimizer mode from ALL_ROWS
    Thanks

    Whether we do not know the OP's Oracle version, we can assume it is not 8i or 9i. Do you realize the link you provided is very old. Still speaking about RULE optimizer, "analyze table" command (both becoming obsolete then depracted) without telling anything about more modern database such as 10g+. Moreover there're some rule of thumbs which can mislead query tuning.
    Much better to refer to the Oracle document that Pierre linked to in first place.
    And why not ask to the OP, why he/she wants to modify the optimizer from ALL_ROWS to what value with what expected results, based on what analyzes...
    Nicolas.

  • Optimization of CURSORS/SQL inside PL/SQL

    Hi Friends
    I have a query regarding optimization working with CURSOR FOR loops and embedded SQL stmts inside PL/SQL procedure.
    I have a code where i am using a Cursor holding multiple rows and than LOOP over it to process individual rows. I am using nested Cursor FOR Loops too.
    I want to know what optimizations are possible in this kind of scenario, where i ahve to process each row of a Cursor.
    Kindly Guide....
    Thanks and Regards

    Hello Friends.....
    Thanks so very much for your reply!!
    I am attaching my code for your reference. Will also go through the links u have provided.
    Kindly, suggest what can be done in this kind of scenario:
    CREATE OR REPLACE procedure insert_sfdc_account
    as
    --DECLARE
    CURSOR C1 IS
    SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
    address, city, postal_code, country_key, zzcust_type, vat_code
    FROM load_cust_general
    WHERE account_group = 'ZSIT';
    v_cust_cur c1%ROWTYPE;
    -- type sales_tab is table of load_cust_sales_area%rowtype;
    v_sales_area load_cust_sales_area%ROWTYPE;
    -- v_sales_area sales_tab;
         v_salesorg varchar2(10);
         v_sales_district varchar2(10);
         v_salesoff varchar2(10);
         v_custgrp varchar2(10);
         v_salesgrp varchar2(10);
    v_type varchar2(20);
    v_nature varchar2(10);
    v_partner_code varchar2(10);
    v_parent_cust varchar2(20);
    v_credit_blk varchar2(20);
    BEGIN
    open c1;
    loop
    fetch c1 into v_cust_cur;
    exit when c1%NOTFOUND;
    for i in (SELECT customer_code, salesorg from load_cust_partner
    where customer_code = v_cust_cur.customer_code ) LOOP
    dbms_output.put_line(v_cust_cur.customer_code );
    -- BEGIN
                        SELECT partner_code into v_partner_code from load_cust_partner
    where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
    dbms_output.put_line(v_partner_code||i.customer_code);
    SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
              WHERE customer_code = i.customer_code and salesorg = i.salesorg;
                   dbms_output.put_line(v_salesorg||i.salesorg);
                   dbms_output.put_line('Customer_Code : '|| i.customer_code);
                   dbms_output.put_line('SalesOrg : '|| i.salesorg);
         /*     SELECT parent_customer INTO v_parent_cust
    from load_cust_hierarchy
    WHERE customer_code = '1234'
    and salesorg = 'abc'
    and hierarchy_type = 'G'; */
                        SELECT parent_customer
    INTO v_parent_cust
    FROM load_cust_hierarchy
    WHERE lower(customer_code) = lower(trim(i.customer_code))
    AND lower(salesorg) = lower(trim(i.salesorg))
    AND hierarchy_type = 'G';
                   /*     SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
    WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
    dbms_output.put_line(v_parent_cust);
                             dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
    exception
    WHEN NO_DATA_FOUND THEN
    v_parent_cust := 'ACHINSUMAN';*/
         --          END;
                        SELECT credit_block INTO v_credit_blk from load_cust_company_cod
              WHERE customer_code = i.customer_code;
    dbms_output.put_line(v_credit_blk);
    for j in (SELECT account_group, customer_type from load_cust_general
    where customer_code IN (select customer_code from load_cust_partner
                                  where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
                                                      LOOP
    -- exit when j%NOTFOUND;
         dbms_output.put_line(j.account_group);
    if (j.account_group = 'ZDIS') THEN
    v_type := 'DISAC';
              v_nature := '06';
         --     EXIT ;
    else
    v_type := 'SPACC';
    v_nature := '01';
    -- ********************* Part to be extended**************
    END IF;
    dbms_output.put_line(v_type||' '||v_nature);
    END LOOP;
    INSERT INTO sfdc_account
              (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
    INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
    CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
    SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
    VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
    v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
    v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
    v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
    v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
    v_salesgrp, v_nature, v_cust_cur.vat_code);
    end loop;
    end loop;
    CLOSE c1;
    -- Delete data from Load Table
    -- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
    /* truncate table load_cust_partner;
    truncate table load_cust_hierarhy;
    truncate table load_cust_sales_area;
    truncate table load_cust_company_cod;
    commit;
    exception
    WHEN NO_DATA_FOUND THEN
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    when others then
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    END;
    Thanks and Regards

  • Ask about an Error in SQL 2014

    Hi all,
    I got an error in SSIS package when I upgraded from Sql server 2008 to 2014 as below
    I have a format file with "Text qualifier" is "||" and "Column dilimiter" is "|" as below data example and it run well in SSIS 2008. But I got an error after I upgraded to Sql server to 2014 because SSIS 2014 did not
    know this kind of format. Is this a bug for new Sql 2014?
    As I know, some first releases of Sql server 2008 also had this error and then it's fixed after that. Now, it happen again in new release of Sql server 2014. Is there any fix for that?
    Error: "[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on MediaType returned error code 0xC0202091.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning
    of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure."
    Example data:
    ||MediaTypeID|||||MediaTypeCode||
    ||xxx|||||yyy||
    ||ccc|||||zzz||
    Thanks all.

    Hi khoana,
    Based on my research, the issue is caused by the Column Delimiter gets first preference and then Text Qualifier. So the values would be parsed as 10 columns based on the Column Delimiter, lack of Text Qualifier cause the issue. This is by design in SQL Server
    2014.
    Personally, I recommend you that submit the requirement at
    https://connect.microsoft.com/SQLServer/. If the requirement mentioned by customers for many times, the product team may consider to add this feature in the next SQL Server version. Your feedback is valuable for us to improve our products and increase
    the level of service provided.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • About cluster table in sql server or SAP

    Hello Gurus,
            we have a cluster table "KONV" in our sql server 2008 , is that feature for cluster table native feature in sql server or in sap?
    because some professonal said there is no concept for cluster table in sql server just like oracle database. so please help me for
    clarification.
    Many thanks,

    I agree, this is ABAP Dictionary specific way of data encapulation, not the DB type dependant one. Basically it stores the data in RAW or LRAW format.
    Also be aware that we distinguish b/w [data clusters|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3bf8358411d1829f0000e829fbfe/frameset.htm] and [cluster tables|http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f083446011d189700000e8322d00/content.htm].
    Regards
    Marcin

  • Question about 'direct' parameter in sql loader utility

    Hi eveyone,
    Today I was asked what the advantages and disadvantages of 'direct' parameter of sql loader.
    In my opinion, if swithing direct on, oracle use direct path load.
    And it has no difference from the append hind in insert statement.
    The core merits are less redo hence faster.
    The main shortcoming is since little redo generated, we have to ask DBA to back up the data according to the rules immediately after the loading.
    Does my answer make sense or not? Plesae help to point out the important things I missed.
    best regards,
    Leon

    Hi,
    Direct path Export is much faster than conventional path Export because the data is read from disk into the buffer cache and rows are transferred directly to the Export client.
    Some conditions to use DIRECT parameter are,
    1. The Export parameter BUFFER applies only to conventional path Exports. For direct path Export, use the RECORDLENGTH parameter to specify the size of the buffer that Export uses for writing to the export file.
    2. You cannot use direct path when exporting in tablespace mode (TRANSPORT_TABLESPACES=Y).
    3. The QUERY parameter cannot be specified in a direct path Export.
    Thanks

  • Another question about using objects in SQL queries

    Hi gurus, I need your thoughts on this:
    I have created generic object type "tree" - the constructor takes as a parameter sql query returning "node_id" and "parent_node_id". As a tree - the object has all related to a tree structure member functions and one of them is "oldest_relative" (the tree may not be fully connected - it may be more like a set of many trees, so it's not necessary all nodes to have the same root).
    I also have departments table with the following fields: department_id, parent_department_id, department_name,...
    all records in the table w/out parent_departments (parent_department_id is null) are considered divisions.
    Now if I run the following query:
    SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT", tree('select department_id "node_id", parent_department_id "parent_node_id" from departments').oldest_relative("DEPARTMENT_ID") "DIVISION_ID" FROM departments
    my question is: Is the tree object created for every row or does Oracle somehow caches the object since the object itself is not changing but only the parameter for the oldest_relative member function.
    The table only has a few hunderd records and I can't see much of a difference in the execution time btw the query above and query like this:
    SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT", b.t.oldest_relative("DEPARTMENT_ID") "DIVISION_ID"
    FROM departments left join (select tree('select department_id "node_id", parent_department_id "parent_node_id" from departments') t from dual) b on 1 = 1
    where the object is clearly created just ones. (there is probably a better way to do it instead of this join)
    Pls elaborate
    George

    Hi, TREE is not a function but PL/SQL object type I have written representing tree structure. The Oracle version is 10g.

Maybe you are looking for

  • Printing problem on HP Photosmart C5280 All-in-One

    Hi, I'm trying to print a single page calendar but it's coming out with streaks in 3 places.  I tried 3x and the streaks are always in the same place.  I'm using Konica Inkjet Paper QP Premium Photo Glossy, which is supposed to be suitable for all mo

  • 1 : n interface

    HI I have an interface which gets a file from a sending system and XI has to send  it to 10 different receiver. I have gone through couple of weblogs and forum threads but I dint get the clear picture for the development approach. Qs 1: Is it possibl

  • RMI observer problem

    Hello I want to write a client server application using rmi and eclipse, where many clients are able to register to the server. The server has a string attribute and a client should be able to pass a string object to the server and the server replace

  • MBP late 2009 getting delays/timeouts while mount/dismount or plug/unplug

    sigh Running a MBP late 2009 with 3GHz, 8GB RAM and 500GB HDD (300GB free). When I mount/dismount a drive it takes up to 1 min for the finder to respond again (getting the whirling ball). When I plug/unplug headphones it takes up to 1 min for the fin

  • Broken Speaker on 8900 HELP!!

    I just bought by 8900 from a t-mobile retailer. Unfortunally I, by accident, dropped my phone on my bowl of cereal and it became submerged in MILK!!!..... anyways.. everything works fine on the phone no damage on the lcd.. all keys work... except my