Performance of PL/SQL vs external C function.

Do anyone know how much performance difference there is for a high computation function implemented in PL/SQL vs a external C function? I know that this is a impossible question to answer precisely. But I'm interested in peoples experiences with this.

Depends on the processing taking place and how much you PL/SQL is using built in functionality. From 10g anything built into oracle has supposedly been rewritted by Oracle in C for performance.
However, you can also compile your PL/SQL natively which turns it into C code and can give up to (according to Oracle training) 30% increase in speed. It does not really give any improvement on SQL statements as they are just statements handled by the SQL engine, so they can't really get any faster, but if it is computational PL/SQL then there will definitely be an improvement.
;)

Similar Messages

  • Invalid state in SQL query for a function that was created with no errors.

    SQL> CREATE OR REPLACE FUNCTION overlap(in_start1 IN TIMESTAMP, in_end1 IN TIMESTAMP, in_start2 IN TIMESTAMP, in_end2 IN TIMESTAMP) RETURN NUMBER
    2 IS
    3
    4 BEGIN
    5 IF (in_start1 BETWEEN in_start2 AND in_end2 OR in_end1 BETWEEN in_start2 AND in_end2 OR in_start2 BETWEEN in_start1 AND in_end1) THEN
    6 RETURN 0;
    7 ELSE
    8 RETURN 1;
    9 END IF;
    10 END;
    11 /
    Function created.
    SQL> show errors;
    No errors.
    SQL>
    SQL> SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0;
    SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0
    ERROR at line 1:
    ORA-06575: Package or function OVERLAPS is in an invalid state
    I do not understand why overlaps is returned as in invalid state in the query, when it was created with no errors earlier. Could anyone help me?

    Marius
    Looking at the logic you are trying to create it looks like you are looking for overlapping time periods.
    Consider two date/time ranges:
    Range 1 : T1 - T2
    Range 2 : T3 - T4
    Do they overlap?
    1) No: T1 < T4 (TRUE)  T2 > T3 (FALSE)
    T1 --- T2
               T3 --- T4
    2) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 ---------- T2
               T3 --- T4
    3) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 -------------------- T2
               T3 --- T4
    4) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
                   T1 ----- T2
               T3 --- T4
    5) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
               T1 --- T2
           T3 ------------ T4
    5) No: T1 < T4 (FALSE) T2 > T3 (TRUE)
                    T1 --- T2
           T3 --- T4Answer: Yes they overlap if:
    T1 < T4 AND T2 > T3
    So you can code the logic in your SQL as simply:
    SELECT *
    FROM tbl
    WHERE range1_start < range2_end
    AND    range_1_end > range2_startIf you go around implementing PL/SQL functions for simple logic that can be achieved in SQL alone then you cause context switching between the SQL and PL/SQL engines which degrades performance. Wherever possible stick to just SQL and only use PL/SQL if absolutely necessary.

  • What is the best way to Optimize a SQL query : call a function or do a join?

    Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement or do a simple join?

    Hi,
    If you're even considering a join, then it will probably be faster.  As Justin said, it depends on lots of factors.
    A user-defined function is only necessary when you can't figure out how to do something in pure SQL, using joins and built-in functions.
    You might choose to have a user-defined function even though you could get the same result with a join.  That is, you realize that the function is slow, but you believe that the convenience of using a function is more important than better performance in that particular case.

  • FRM-40734 when calling external DLL Function from Forms 6

    Even though some answers were given to my previous help request ("Again: Forms 6 and user-defined data types") I wasn't able to solve the problem of passing a parameter of an user-defined type to an external DLL function residing in the SECURSIGN.DLL library (the closest solution was to declare that "composite" parameter using the ROWTYPE clause referencing a custom-made table created just for the sake of defining that perticular datatype).
    So I concentrated on SECURSIGN.DLL functions using more trivial data types, like a function requiring just four character strings as parameters.
    I generated the necessary PL/SQL support using the FFI.
    I discovered that also the simplest calls to external functions fail at runtime with the generic error FRM-40734.
    I located the error: it happens just at the moment of calling the function from within the FFI-generated package body. Before that, the DLL is loaded with no problem, the function is correctly registered, and a function handle is regularly returned.
    As long as I can regularly issue the very same call with the very same parameters from Visual Basic, I can't understand what's going wrong (ALL the needed DLL are in the same directory as the FMB/FMX forms).
    I will greatly appreciate any help that You may be able to provide.

    I have noticed just now that a dump file having a name like ifrun60_dump_299, is generated by FORMS every time I issue the aborted call to the foreign function.
    Inside the form dump file, apart from useless info like Registers and so on, the message:
    "Could not find Module32First"
    By a FILE/FIND/CONTAINING TEXT I searched all the DLLs, and I noticed that Module32First is a routine that can be found within each of the following DLLs:
    Cl32
    d2kwut32
    d2kwut60
    I tried to load those DLLs along with SECURSIGN.DLL by modifying the PROCEDURE LoadLibrary into the FFI-generated PLL code, and I have apparently no problem in loading all the DLLs that I wish, but the error persists, and that dump file is constantly generated, always looking for the "Module32First" routine.
    How can I avoid all that mess and the FRM-40734 error??

  • Wrapper for invoking external DLL-function

    I want to run a Host-Command (e.g. rwrun60 report=xyz.rdf batch=yes) invoked by a trigger that fires when a new record is inserted.
    I wrote a DLL which has an exported function that accepts a commandline (with parameters) and invokes the command via ShellExecute.
    The problem is, that when i invoke the PL/SQL-wrapper, the DLL-function is properly run, but the program i want to run is only visible in the taskmanager(NT) and does nothing.
    So what i need is a correct wrapper for the function:
    DLL-function: OExecSysCmd(cmdLine *char)
    Wrapper:
    PROCEDURE OExecSysCmd(p_SysCmd in char)
    IS EXTERNAL
    NAME "OExecSysCmd"
    LIBRARY demolib;
    Thanks in advance
    Dannys

    Hi Russ,
    with "invoke an external dll" I mean that I have to wite a log file to register my fdk client events and to do this I have to use an external dll wich exposes some functions to write to a common log file. I have imported the external dll in my client project and at the beginning of client code I have included the dll header file:
    #include "LogDll.h"
    Then I've tried to invoke a LogDll function (not within F_ApiInitialize (), but in a custom dialog box event):
    int retval=LogDllFunction();
    The code compiles, but if I start FM, I receive the message error. If I comment the line above, FM and my client start normally.
    Thanks,
    Stefano

  • SQL Expression in decode function or case statement?

    Can I put SQL expressions in decode function or case statement?
    For example,
    select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
    from element le;
    or
    select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
    ELSE 'Y'
    from element le;
    None of the above work.
    Can anyone tell me how to make it work?
    Is there any workaround?
    Thanks,
    J

    You simply needed and END to your CASE statement;
    SQL> with profile_data as (
       select 'XXXX_AFTER' name, 1 object_id from dual),
         element as (
       select 1 profile from dual union all
       select 2 from dual)
    select le.profile,
       case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
       THEN 'N'
       ELSE 'Y'
       END new_col
    from element le
       PROFILE N
             1 Y
             2 N

  • PL/SQL Network Address Type Functions

    Hi,
    I'm wondering if anyone knows of a PL/SQL package(s) that provides similar capabilities as the following postgreSQL network address type functions:
    http://www.sql.org/sql-database/postgresql/manual/functions-net.html
    I don't see anything in the standard Oracle 10g packages, so I'm wondering if anyone else has dealt with this problem and posted the package.
    Thanks,
    - Greg.

    I think the easiest way of getting some of this functionality would be to write a PL/SQL wrapper to a Java Stored Procedure that implements calls to the Java InetAddress class. It doesn't haven't the full set of operators but I'm not sure what 'less than' actually means in the context of an IP address . If you really need them you could always extend the InetAddress class to implement such tests.
    Cheers, APC

  • I have an iPad 2 and iPhone 4 and for them I use I cloud I have also 1 pc windows and at work place I use windows pc ; until now my files are stored on an external disk drive could' I use iCloud to perform the backup of my external disk drive ? Thanks

    I have an iPad 2 and iPhone 4 and for them I use I cloud I have also 1 pc windows and at work place I use windows pc ; until now my files are stored on an external disk drive could' I use iCloud to perform the backup of my external disk drive ? Thanks
    Loredano

    These are the options you have.
    Budget $1299.
    http://www.apple.com/macbookair/
    http://www.apple.com/macbookpro/
    Best.

  • How can i perform a search on my external hard drive on my mac pro os x 10.9.2 ?

    how can i perform a search on my external hard drive on my mac pro os x 10.9.2 ?

    Mac OS X 10.9.2 is 12 years newer than 9.2.x.    You need to make sure that Spotlight has indexed the external hard drive by adding it and removing it from Apple menu -> System Preferences -> Spotlight -> Privacy.   Check the menu for it:
    to determine if indexing is still going on, as it will say indexing.
    Alternatively, you can use a non-Spotlight tool, such as:
    http://apps.tempel.org/FindAnyFile/
    http://www.devontechnologies.com/products/freeware/ - EasyFind
    http://www.osxbytes.com/ - iFileX (note the MacUpdate link provided on osxbytes page has a Malware advertisement for MacKeeper, do not download).
    http://www.barebones.com/ Textwrangler has a Search file for content, which works on any Text file.

  • Need clear steps for doing performance tuning on SQL Server 2008 R2 (DB Engine, Reporting Services and Integration Services)

    We have to inverstigate about a reporting solution where things are getting slow (may be material, database design, network matters).
    I have red a lot in MSDN and some books about performance tuning on SQL Server 2008 R2 (or other) but frankly, I feel a little lost in all that stuff
    I'am looking for practical steps in order to do the tuning. Someone had like a recipe for that : a success story...
    My (brain storm) Methodology should follow these steps:
     Resource bottlenecks: CPU, memory, and I/O bottlenecks
     tempdb bottlenecks
     A slow-running user query : Missing indexes, statistics,...
     Use performance counters : there are many, can one give us the list of the most important
    how to do fine tuning about SQL Server configuration
    SSRS, SSIS configuration ? 
    And do the recommandations.
    Thanks
    "there is no Royal Road to Mathematics, in other words, that I have only a very small head and must live with it..."
    Edsger W. Dijkstra

    Hello,
    There is no clear defined step which can be categorized as step by step to performance tuning.Your first goal is to find out cause or drill down to factor causing slowness of SQL server it can be poorly written query ,missing indexes,outdated stats.RAM crunch
    CPU crunch so on and so forth.
    I generally refer to below doc for SQL server tuning
    http://technet.microsoft.com/en-us/library/dd672789(v=sql.100).aspx
    For SSIS tuning i refer below doc.
    http://technet.microsoft.com/library/Cc966529#ECAA
    http://msdn.microsoft.com/en-us/library/ms137622(v=sql.105).aspx
    When I face issue i generally look at wait stats ,wait stats give you idea about on what resource query was waiting.
    --By Jonathan KehayiasSELECT TOP 10
    wait_type ,
    max_wait_time_ms wait_time_ms ,
    signal_wait_time_ms ,
    wait_time_ms - signal_wait_time_ms AS resource_wait_time_ms ,
    100.0 * wait_time_ms / SUM(wait_time_ms) OVER ( )
    AS percent_total_waits ,
    100.0 * signal_wait_time_ms / SUM(signal_wait_time_ms) OVER ( )
    AS percent_total_signal_waits ,
    100.0 * ( wait_time_ms - signal_wait_time_ms )
    / SUM(wait_time_ms) OVER ( ) AS percent_total_resource_waits
    FROM sys.dm_os_wait_stats
    WHERE wait_time_ms > 0 -- remove zero wait_time
    AND wait_type NOT IN -- filter out additional irrelevant waits
    ( 'SLEEP_TASK', 'BROKER_TASK_STOP', 'BROKER_TO_FLUSH',
    'SQLTRACE_BUFFER_FLUSH','CLR_AUTO_EVENT', 'CLR_MANUAL_EVENT',
    'LAZYWRITER_SLEEP', 'SLEEP_SYSTEMTASK', 'SLEEP_BPOOL_FLUSH',
    'BROKER_EVENTHANDLER', 'XE_DISPATCHER_WAIT', 'FT_IFTSHC_MUTEX',
    'CHECKPOINT_QUEUE', 'FT_IFTS_SCHEDULER_IDLE_WAIT',
    'BROKER_TRANSMITTER', 'FT_IFTSHC_MUTEX', 'KSOURCE_WAKEUP',
    'LAZYWRITER_SLEEP', 'LOGMGR_QUEUE', 'ONDEMAND_TASK_QUEUE',
    'REQUEST_FOR_DEADLOCK_SEARCH', 'XE_TIMER_EVENT', 'BAD_PAGE_PROCESS',
    'DBMIRROR_EVENTS_QUEUE', 'BROKER_RECEIVE_WAITFOR',
    'PREEMPTIVE_OS_GETPROCADDRESS', 'PREEMPTIVE_OS_AUTHENTICATIONOPS',
    'WAITFOR', 'DISPATCHER_QUEUE_SEMAPHORE', 'XE_DISPATCHER_JOIN',
    'RESOURCE_QUEUE' )
    ORDER BY wait_time_ms DESC
    use below link to analyze wait stats
    http://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/
    HTH
    PS: for reporting services you can post in SSRS forum
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Need help in improving the performance for the sql query

    Thanks in advance for helping me.
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. The data count which is updated in the target table is 2 million records and the target table has 15 million records.
    Any suggestions or solutions for improving performance are appreciated
    SQL query:
    update targettable tt
    set mnop = 'G',
    where ( x,y,z ) in
    select a.x, a.y,a.z
    from table1 a
    where (a.x, a.y,a.z) not in (
    select b.x,b.y,b.z
    from table2 b
    where 'O' = b.defg
    and mnop = 'P'
    and hijkl = 'UVW';

    987981 wrote:
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. And that meant what? Surely if you spend all that time and effort to try various approaches, it should mean something? Failures are as important teachers as successes. You need to learn from failures too. :-)
    The data count which is updated in the target table is 2 million records and the target table has 15 million records.Tables have rows btw, not records. Database people tend to get upset when rows are called records, as records exist in files and a database is not a mere collection of records and files.
    The failure to find a single faster method with the approaches you tried, points to that you do not know what the actual performance problem is. And without knowing the problem, you still went ahead, guns blazing.
    The very first step in dealing with any software engineering problem, is to identify the problem. Seeing the symptoms (slow performance) is still a long way from problem identification.
    Part of identifying the performance problem, is understanding the workload. Just what does the code task the database to do?
    From your comments, it needs to find 2 million rows from 15 million rows. Change these rows. And then write 2 million rows back to disk.
    That is not a small workload. Simple example. Let's say that the 2 million row find is 1ms/row and the 2 million row write is also 1ms/row. This means a 66 minute workload. Due to the number of rows, an increase in time/row either way, will potentially have 2 million fold impact.
    So where is the performance problem? Time spend finding the 2 million rows (where other tables need to be read, indexes used, etc)? Time spend writing the 2 million rows (where triggers and indexes need to be fired and maintained)? Both?

  • Problem with DBMS_OUTPUT and SQL statment with a function

    I am using SQL Developer version 3.0.04 and I have a function that has a dbms_output statment in it. I am running the following SQL to select the output of that statment.
    select A.A_FUCTION('TEST') from dual;
    The output works fine but the dbms_output line does not show in the dbms_output window. I turned on the output window etc. and i can get the select to print out the output if i wrap it in a declare begin end wrapper... and then change the query to insert the return value into variable.
    just wondering if there is way to get the dbms_output to flush out with just an SQL statment instead of in a begin end wrapper etc.

    just wondering if there is way to get the dbms_output to flush out with just an SQL statment instead of in a begin end wrapper etc.works fine in sql*plus, so I guess it must be a preference or sth. in sql*developer:
    SQL> set serverout on
    SQL> create or replace function f1 (r int)
      2    return int
      3  as
      4  begin
      5    dbms_output.put_line ('Hello World ' || r);
      6    return r;
      7  end f1;
      8  /
    Function created.
    SQL>
    SQL> select f1 (rownum) f1 from dual connect by level <= 3
      2  /
            F1
             1
             2
             3
    3 rows selected.
    Hello World 1
    Hello World 2
    Hello World 3
    SQL>

  • Queries on pl/sql tables within a function

    hi,
    how can i execute regular sql-queries within a function on a pl/sql table which the function has recieved as a parameter ? i have tried quite a bit and always get type mismatches or internal errors. anybody has a good example on this ?
    thanks in advance,
    stephan

    hi,
    okay, i will not post the actual code i have, because it won't make too much sense out of the context, but here are the relevant parts...
    i have a few object definitions that represent the records of the three tables (two input and one output)...
    create type t1 as object (...);
    create type t2 as object (...);
    create type t3 as object (...);
    and a package with the table definitions
    create or replace package t_defs as
    type tab_t1 is table of t1;
    type tab_t2 is table of t2;
    type tab_t3 is table of t3;
    end t_defs;
    and here is a rough sketch what the function should look like later:
    CREATE OR REPLACE FUNCTION some_function (
    tab1 IN t_defs.tab_t1, tab2 IN t_def.tab_t2)
    RETURN t_defs.tab_t3 PIPELINED IS
    TYPE refcur IS REF CURSOR;
    cur0 refcur;
    curr_rec t3 := t3(NULL, ....);
    BEGIN
    open cur0 for 'here is the statement i could not do';
    LOOP
    FETCH cur0 INTO curr_rec.....;
    EXIT WHEN cur0%NOTFOUND;
    . -- (manipulate the record) --
    PIPE ROW(curr_rec);
    END LOOP;
    RETURN;
    END;

  • Problem with external PHP function

    I am working on a registration page. This is the list of
    statements I have that must be true for the registration to
    succeed:
    if(isset($_POST['register']))
    if($_POST['username'] != ''
    &&(strlen($_POST['username']) >= 4)
    &&(strlen($_POST['username']) <= 20)
    && alpha_numeric($_POST['username']) == TRUE
    && $_POST['password'] != ''
    &&(strlen($_POST['password']) >= 4)
    &&(strlen($_POST['password']) <= 20)
    && alpha_numeric($_POST['password']) == TRUE
    && $_POST['password2'] == $_POST['password']
    && $_POST['email'] != ''
    && valid_email($_POST['email']) == TRUE
    && $_POST['email2'] == $_POST['email']
    && $_POST['agree'] == TRUE
    && checkUnique('user_data', 'username',
    $_POST['username']) == TRUE
    && checkUnique('user_data', 'email',
    $_POST['email']) == TRUE)
    The external 'checkUnique' functions at the bottom simply
    don't seem to work. I am easily able to sign up with a username or
    email that already exists in the database.
    This is the code for the external function:
    function checkUnique($table, $field, $compared)
    $query = mysql_query('SELECT
    '.mysql_real_escape_string($field).' FROM
    '.mysql_real_escape_string($table).' WHERE
    "'.mysql_real_escape_string($field).'" =
    "'.mysql_real_escape_string($compared).'"');
    if(mysql_num_rows($query)==0)
    return TRUE;
    else
    return FALSE;
    }

    AngryCloud wrote:
    > I just had to add
    > 'get_' in front of 'magic_quotes_gpc'.
    Oops, sorry about that.
    > Is there a way to find out
    > which of the statements (from my first post) came out
    false and set the $error
    > variable accordingly, without having to make a separate
    if statement for each
    > one?
    No.
    > Also, so more than one error can be displayed at once,
    is it possible to add
    > text to a variable? For example, if the username was
    invalid, $error =
    > 'Username is invalid'. But if the email addresses also
    did not match, could
    > '<br />Emails do not match' be added to the
    variable?
    Yes. There are two ways of doing it. One is to use the
    combined
    concatenation operator (.=) to add something to the end of an
    existing
    string. You use it like this:
    $error = '';
    if ($_POST['username'] == '') {
    $error .= 'You must supply a username<br />';
    if (strlen($_POST['username']) < 4 ||
    strlen($_POST['username']) > 20 ||
    !alpha_numeric($_POST['username'])) {
    $error .= 'Username must be 4-20 characters and contain only
    letters or numbers<br />';
    A more elegant way of doing it is to create an array like
    this:
    $error = array();
    if ($_POST['username'] == '') {
    $error[] = 'You must supply a username';
    if (strlen($_POST['username']) < 4 ||
    strlen($_POST['username']) > 20 ||
    !alpha_numeric($_POST['username'])) {
    $error[] = 'Username must be 4-20 characters and contain
    only
    letters or numbers';
    To display the array, use this:
    if (isset($error) && !empty($error)) {
    echo '<ul>';
    foreach ($error as $item) {
    echo "<li>$item</li>";
    echo '</ul>';
    This displays the array as a bulleted list.
    Whichever method you use, you can test whether to insert the
    details in
    the database with this simple test:
    if (!$error) {
    // insert details in DB
    PHP treats an empty string or empty array as false, so
    !$error equates
    to TRUE if no errors have been triggered.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • SQL Query With analytical function

    Hi
    Below is the scenario which i am looking for in sql query using analytical functions
    I/p
    Col1
    50
    0
    -150
    -200
    300
    -100
    -300
    500
    -100
    O/p
    Col1          col2
    50                 0
    0                   0
    -150          -100
    -200              -200
    300               0
    -100              0
    -300              -100
    500               400
    -100              0Any help really appreciated
    Thanks in advance
    Edited by: unique on Aug 10, 2010 4:53 AM
    Edited by: unique on Aug 10, 2010 4:55 AM
    Edited by: unique on Aug 10, 2010 4:55 AM

    Oh,In this case,There is OLAP solution ;-)
    OLAP samples of my homepage http://www.geocities.jp/oraclesqlpuzzle/oracle-sql1-olap.html
    with work(SK,Val) as(
    select  1,  50 from dual union
    select  2,   0 from dual union
    select  3,-150 from dual union
    select  4,-200 from dual union
    select  5, 300 from dual union
    select  6,-100 from dual union
    select  7,-300 from dual union
    select  8, 500 from dual union
    select  9,-100 from dual)
    select SK,Val,GID,
    case when Val > 0
         then greatest(0,sum(Val) over(partition by GID))
         else Least(0,Val+greatest(0,sum(Val) over(partition by GID
                                     order by SK rows between unbounded preceding
                                                          and 1 preceding)))
         end as COL3
    from (select SK,Val,
          sum(greatest(0,sign(Val))) over(order by SK) as GID
          from work)
    order by SK;
    SK   VAL  GID  COL3
    1    50    1     0
    2     0    1     0
    3  -150    1  -100
    4  -200    1  -200
    5   300    2     0
    6  -100    2     0
    7  -300    2  -100
    8   500    3   400
    9  -100    3     0

Maybe you are looking for