Bind variable & LIKE :1 - Performance issue

I'm using ODP.NET version 10.2 and I'm facing a performance problem with LIKE key word in statements.
I'm doing the following :
OracleConnection conn = new OracleConnection();
conn.ConnectionString = connectionString;
string strQuery;
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
strQuery = "SELECT field FROM table WHERE field LIKE :1";
cmd.Parameters.Add(":1", OracleDbType.Varchar2, 2, "x%",ParameterDirection.Input);
-> This takes quite a long time to retrieve the data.
If I do the following (without Parameters.Add) it flies :
strQuery = "SELECT field FROM table WHERE field LIKE 'x%'";
cmd.CommandText = strQuery;
OracleDataAdapter da = new OracleDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "table");
What am I doing wrong ?
Thanks in advance
Philippe

Hi,
Is this behavior specific to ODP.NET? Do you get the same behavior testing sqlplus with bind variables? If you're not sure how, here's how you can try it..
Cheers,
Greg
SQL> var abc varchar2(100);
SQL> exec :abc := 'K%';
PL/SQL procedure successfully completed.
SQL> set timing on
SQL> select * from emp where ename like :abc;
EMPNO ENAME JOB MGR
HIREDATE SAL COMM DEPTNO
7839 KING PRESIDENT
17-NOV-81 5000 10
Elapsed: 00:00:00.00
SQL> select * from emp where ename like 'K%';
EMPNO ENAME JOB MGR
HIREDATE SAL COMM DEPTNO
7839 KING PRESIDENT
17-NOV-81 5000 10
Elapsed: 00:00:00.01
SQL>

Similar Messages

  • DB links, Bind variables & APEX reports performance

    Hello,
    So the problem is simply that I have two databases:
    A : Has table T1
    B : (APEX database)
    I have an APEX report that simply does the following
    Select col1, col2.. from A@dblink
    This is abviously straighforward, however, I start having considrable performance issues if I have any filters applied to this query using APEX items ( bind variables) :
    Select col1, col2.. from T1@dblink_A_B
    where col1 > :PX_item
    I ran the explain plan and noticed that using the bind variables forces the query to be done on database B, not A which is causing the performance issues.
    I am sure that many of you ran into this issue before, but does anyone know how to resolve this issue ? I am thinking about using Pipelined functions, but am not sure if that will work well if I have a lot of records returned by the query or if this will resolve the issue at all.... your thoughts are appreciated..
    Thanks,
    Sam

    I've always been able to work around my DB link issues in Apex. As suggested, driving_site hint should be tried. Oracle documentation on it isn't great, but I follow this:
    - don't bother including other hints together with driving_site, as they get stripped out when your sql is passed to the remote DB (as per driving_site hint).
    - if you have have subqueries - specifiy driving_site hint in that section of the SQL too. I don't have any proof that this is really required - but it doesnt hurt.
    - include driving_site hint even if all tables are remote. Careful of refs to pseudo cols like sysdate, user etc. I think they are taken as local refs - not remote. I havent tested this properly to confirm.
    - dumb down your test case to eliminate refs to sysdate, subqueries etc.
    - remember that items are text, so you'd need to do to_number(), to_date() on them where appropriate on them in your SQL at the least.
    Seeing as you control the content of your items, SQL injection is a reduced risk. Assuming that's not your top concern anyway, don't get carried away with the bind-variable vs literals debate. Apex does lots of nasty inefficient stuff like IR searches. I'd never use an IR in something that really needs to be scalable anyway. Soo... construct SQL with littlerals based on your items (assuming item refs are the cause of your issue).
    region type=SQL Query (PL/SQL function body returning SQL query)
    begin
      return 'SELECT /*+ DRIVING_SITE(a) */ a.empno,a.ename,a.job,a.mgr,a.loc
            FROM emp@MY_DBLNK A
           WHERE  a.empno = '||:P123_EMPNO||'
           ORDER BY 1,2,3';
    end;Assuming your queries are expensive to execute (local or remote) and dont return too many records (else collection table can get really big), then caching the resultset in a collection gives you nice fast pagination, when using a PPR report. Keep a watch on the size of the collection table - truncate it manually if you accidentally populate it with a big cartesean product etc, else performance could degrade.
    Do main query to populate collection before header. PPR pagination doesnt reload the page, so before-header process only runs once. In my case it works like:
    -- reload button to re-load page, to force a query re-run. The html_Submit_Progress thing loads an 'busy processing' image.
    <input type="button" value="Run query" onclick="javascript:this.disabled=true;this.value='Running...';html_Submit_Progress(this);"  id="SUBMIT"  />
    -- On Load - before header process to populate collection (call in a regular region to see errors, until ironed out)
    declare
      q varchar2(4000);
      v_t0   PLS_INTEGER := DBMS_UTILITY.get_time;
    begin
       :P0_QSEC := '0';
      IF APEX_COLLECTION.COLLECTION_EXISTS(P_COLLECTION_NAME=> 'Q1')
      THEN
        APEX_COLLECTION.DELETE_COLLECTION(P_COLLECTION_NAME=>'Q1');
      END IF;
      if (:P0_DBLNK is not null) then
        q:= 'SELECT /*+ DRIVING_SITE(a) */ a.empno,a.ename,a.job,a.mgr,a.loc
            FROM emp@'||:P0_DBLNK||' a
           WHERE a.job like "M%"
            AND a.empno = #EMPNO#
           ORDER BY 1,2,3';
        q:= replace(q, '"', '''');
        q:= replace(q, '#EMPNO#', :P123_EMPNO);
        -- bulk
        APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY_B(
            P_COLLECTION_NAME => 'Q1',
            P_QUERY => Q);
       -- record count
       -- APEX_COLLECTION.collection_member_count
      end if;
      -- display in page footer or whatever
      :P0_QSEC := TO_CHAR ((DBMS_UTILITY.get_time - v_t0) / 100, '000.00') || ' sec';
    exception
      when others then
      raise_application_error(-20501, :P0_DBLNK||'< br >'||sqlerrm||'< br >'||q );
    end;
    -- then PPR report is just like
    Select C001, C002, C003, C004, C005
    From apex_collections
    Where collection_name = 'Q1'
    order by seq_id;Edited by: maceyah on Sep 7, 2011 9:26 AM
    Useful link on bind variables for CREATE_COLLECTION_FROM_QUERY_B ==> https://forums.oracle.com/forums/thread.jspa?threadID=2305634&tstart=0
    Edited by: maceyah on Mar 2, 2012 3:18 PM

  • Report Variable F4 help performance issue

    Hi,
    I have a BI report on DSO >> Multiprovider.
    When i choose F4 Variable help it takes around 2-3 minutes to display the data for selection.
    Currently XXXX chars is with -- Only Posted Values for Navigation. I have tried the below options but could not see any improvement in variable f4 help performance.
    -- Only Values in Infoprovider
    -- Values In Master Data table
    Could someone please suggest if you have faced the similar issue.
    Thanks
    Ashok

    Hello Ashok,
    Ideally you should never built a report based on a DSO, this is because it stores data at a line item level. The way the filter works is that looks at all records (SIDs) lying in the range of selection in the info provider and then displays the filter pane after it populates the records.
    There can only be 1 check in this case, is to check if your DB statistics are up-to-date. The DB statistics decide if an index is to be used or not. So check for the DSO active table and all related SID tables in transaction DB20. Check the date of creation of the statistics, if it's too much in the past, then the DB does not effectively use the indices and hence it takes time.
    You can use program RSANAORA to recompute the statistics.
    Regards,
    Ansel D'Souza

  • Performance Issue with Selection Screen Values

    Hi,
    I am facing a performance issue(seems like a performance issue ) in my project.
    I have a query with some RKFs and sales area in filters (single value variable which is optional).
    Query is by default  restricted by current month.
    The Cube on which the query operates has around 400,000 records for a month.
    The Cube gets loaded every three hours
    When I run the query with no filters I get the output within 10~15 secs.
    The issue I am facing is that,  when I enter a sales area in my selection screen the query gets stuck in the data selection step. In fact we are facing the same problem if we use one or two other characteristics in our selection screen
    We have aggregates/indexes etc on our cube.
    Has any one faced a similar situation?
    Does any one have any comments on this ?
    Your help will be appreciated. Thanks

    Hi A R,
    Goto RSRT--> Give ur query anme --> Execute =Debug
    --> No a pop up ill come with many check boxes select "Display Aggregates found" option --> now give ur
    selections in variable screen > first it will give the already existing aggregate names> continue> now after displaying all the aggregates it will display the list of objects realted to cube wise> try to copy these objects into notepad> again go with ur drill downs now u'll get the already existing aggregates for this drill down-> it will display the list of objects> copy them to notepad> now sort all the objects related to one cube by deleting duplicate objects in the note pad>goto that Infocube> context>maintain aggregates> create aggregate on the objects u copied into note pad.
    now try to execyte the report... it should work properly with out delays for those selections.
    I hope it helps you...
    Regards,
    Ramki.

  • Do not use bind variable notations for p_session_id argument...

    Hi there,
    ... in apex_custom_auth.login the Apex doc says. Does anyone know why not?
    LOGIN Procedure
    Also referred to as the "Login API," this procedure performs authentication and session registration.
    p_session_id Current Oracle Application Express session ID.
    Note: Do not use bind variable notations for p_session_id argument.Thanks
    Luis

    I tend to avoid assigning values to bind variables like that - but it may be due to the nature of much of my code residing in PL/SQL packages.
    And due to the strange encounters I have had with this, like your linked discussions, I've tended towards using apex_util instead.
    You may also enjoy this discussion
    http://www.danielmcghan.us/2012/08/implicit-commits-in-apex.html
    Scott

  • RE: Case 59063: performance issues w/ C TLIB and Forte3M

    Hi James,
    Could you give me a call, I am at my desk.
    I had meetings all day and couldn't respond to your calls earlier.
    -----Original Message-----
    From: James Min [mailto:jminbrio.forte.com]
    Sent: Thursday, March 30, 2000 2:50 PM
    To: Sharma, Sandeep; Pyatetskiy, Alexander
    Cc: sophiaforte.com; kenlforte.com; Tenerelli, Mike
    Subject: Re: Case 59063: performance issues w/ C TLIB and Forte 3M
    Hello,
    I just want to reiterate that we are very committed to working on
    this issue, and that our goal is to find out the root of the problem. But
    first I'd like to narrow down the avenues by process of elimination.
    Open Cursor is something that is commonly used in today's RDBMS. I
    know that you must test your query in ISQL using some kind of execute
    immediate, but Sybase should be able to handle an open cursor. I was
    wondering if your Sybase expert commented on the fact that the server is
    not responding to commonly used command like 'open cursor'. According to
    our developer, we are merely following the API from Sybase, and open cursor
    is not something that particularly slows down a query for several minutes
    (except maybe the very first time). The logs show that Forte is waiting for
    a status from the DB server. Actually, using prepared statements and open
    cursor ends up being more efficient in the long run.
    Some questions:
    1) Have you tried to do a prepared statement with open cursor in your ISQL
    session? If so, did it have the same slowness?
    2) How big is the table you are querying? How many rows are there? How many
    are returned?
    3) When there is a hang in Forte, is there disk-spinning or CPU usage in
    the database server side? On the Forte side? Absolutely no activity at all?
    We actually have a Sybase set-up here, and if you wish, we could test out
    your database and Forte PEX here. Since your queries seems to be running
    off of only one table, this might be the best option, as we could look at
    everything here, in house. To do this:
    a) BCP out the data into a flat file. (character format to make it portable)
    b) we need a script to create the table and indexes.
    c) the Forte PEX file of the app to test this out.
    d) the SQL staement that you issue in ISQL for comparison.
    If the situation warrants, we can give a concrete example of
    possible errors/bugs to a developer. Dial-in is still an option, but to be
    able to look at the TOOL code, database setup, etc. without the limitations
    of dial-up may be faster and more efficient. Please let me know if you can
    provide this, as well as the answers to the above questions, or if you have
    any questions.
    Regards,
    At 08:05 AM 3/30/00 -0500, Sharma, Sandeep wrote:
    James, Ken:
    FYI, see attached response from our Sybase expert, Dani Sasmita. She has
    already tried what you suggested and results are enclosed.
    ++
    Sandeep
    -----Original Message-----
    From: SASMITA, DANIAR
    Sent: Wednesday, March 29, 2000 6:43 PM
    To: Pyatetskiy, Alexander
    Cc: Sharma, Sandeep; Tenerelli, Mike
    Subject: Re: FW: Case 59063: Select using LIKE has performance
    issues
    w/ CTLIB and Forte 3M
    We did that trick already.
    When it is hanging, I can see what is doing.
    It is doing OPEN CURSOR. But not clear the exact statement of the cursor
    it is trying to open.
    When we run the query directly to Sybase, not using Forte, it is clearly
    not opening any cursor.
    And running it directly to Sybase many times, the response is always
    consistently fast.
    It is just when the query runs from Forte to Sybase, it opens a cursor.
    But again, in the Forte code, Alex is not using any cursor.
    In trying to capture the query,we even tried to audit any statementcoming
    to Sybase. Same thing, just open cursor. No cursor declaration anywhere.==============================================
    James Min
    Technical Support Engineer - Forte Tools
    Sun Microsystems, Inc.
    1800 Harrison St., 17th Fl.
    Oakland, CA 94612
    james.minsun.com
    510.869.2056
    ==============================================
    Support Hotline: 510-451-5400
    CUSTOMERS open a NEW CASE with Technical Support:
    http://www.forte.com/support/case_entry.html
    CUSTOMERS view your cases and enter follow-up transactions:
    http://www.forte.com/support/view_calls.html

    Earthlink wrote:
    Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? Well, we're missing a lot here.
    Like:
    - a database version
    - how did you test
    - what data do you have, how is it distributed, indexed
    and so on.
    If you want to find out what's going on then use a TRACE with wait events.
    All nessecary steps are explained in these threads:
    HOW TO: Post a SQL statement tuning request - template posting
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
    Another nice one is RUNSTATS:
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551378329289980701

  • How do I use bind variables for the SQL statements having IN clause

    SELECT id, name FROM t
    WHERE id in (10,20,30)
    As the IN list will have 'n' number of values, I am not able to specify fixed number of bind
    variables like
    SELECT id, name FROM t
    WHERE id in (?,?,?....)

    452051 wrote:
    I am not able to specify fixed number of bind variablesYou could use collection:
    SQL> create or replace force
      2    type NumList
      3      as
      4        table of number
      5  /
    SQL> select ename from emp where deptno member of NumList(10)
      2  /
    ENAME
    CLARK
    KING
    MILLER
    SQL> select ename from emp where deptno member of NumList(10,20,30)
      2  /
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    ENAME
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> This way you have one bind variable - collection.
    SY.

  • Bind Variable NOT working in APEX 4.0 within charts SQL

    All,
    I had a chart working fine in 3.2 which had a bind variable like :P11_EMP_NAME, when I created the same chart in 4.0 using the same query it did not work, until I changed the variable to v('P11_EMP_NAME'). Does anyone have experienced the same behaviour?
    Thanks
    Venkat

    Hi Deb,
    Both of your queries are using multi-series syntax i.e. returning more than one series of data, therefore your generated chart is actually generating 6 series rather than just the two that you're aiming for. You could try changing your queries to ensure they each generate a single series of information, which would then result in the extra Y-axis being applied to your "Series 2". Here's an example of what I mean:
    Series 1:
    select null link, label, value from (
    select 'test' label, 1 value from dual
    union all
    select 'test2' label, 2 value from dual
    union all
    select 'test3' label, 3 value from dual
    )Series 2:
    select null link, label, value from (
    select 'test' label, 100 value from dual
    union all
    select 'test2' label, 200 value from dual
    union all
    select 'test3' label, 300 value from dual
    )I hope this helps.
    Regards,
    Hilary

  • How to use bind variable

    Hi,
    I have the below cursor 1 which is working already.For my requirement i want to use bind variable like second cursor.But its telling Bind Variable "p_col_list" is NOT DECLARED.Please any onehelp me on this.
    How to use bind variable Here.
    Cursor1:
    DECLARE
    emp_cv sys_refcursor;
    iid NUMBER := 1;
    i_sql varchar2(100);
    p_col_list varchar2(2000) := 'aaa,bbb,ccc,ddd';
    BEGIN
    i_sql := 'select '''||REPLACE(p_col_list, ',', ''',''')||''' from dual '||CHR(10) ;
    dbms_output.put_line(i_sql);
    OPEN emp_cv FOR i_sql ;
    END;
    Cursor2:
    DECLARE
    emp_cv sys_refcursor;
    iid NUMBER := 1;
    i_sql varchar2(100);
    p_col_list varchar2(2000) := 'aaa,bbb,ccc,ddd';
    BEGIN
    i_sql := 'select '''||REPLACE(:p_col_list, ',', ''',''')||''' from dual '||CHR(10) ;
    dbms_output.put_line(i_sql);
    OPEN emp_cv FOR i_sql using p_col_list;
    END;

    hello,
    the reports parameterform capabilities are limited. if you want
    to create sophisticated parameterforms, you should do that with
    oracle forms or html forms.
    regards,
    the oracle reports team --pw                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Re-using bind variables in Pro*C

    Using dynamic SQL method 4. Application originally written back in, oh 1999-ish, using Oracle 7. We've upgraded to Oracle 10g. I've looked through the old manuals ( Pro*C Supplement to the ORACLE Precompilers Guide Version 1.5) for an answer to a question and can't find it in the old manuals. I haven't tried looking through the online manuals for the newer version yet, so if the answer is readily available there I apologize.
    The question is, "Can a bind variable be used more than once within a SQL command?"
    Example: find all employees whose first or last name is not Lee.
    SELECT first_name, last_name
    FROM employee
    WHERE first_name <> :criteria1
    AND last_name <> :criteria2;
    In an example like this, both bind variables contains the same value (Lee). Is it still required to have separate bind variables? Or could I re-use a bind variable, like this:
    SELECT first_name, last_name
    FROM employee
    WHERE first_name <> :criteria1
    AND last_name <> :criteria1;
    Obviously, this is a simplified example. In my application, there are some large unioned SQL statements that re-use the user's id over a dozen times. It would be nice to use just one bind variable repeatedly, rather than having ":userid1, :userid2, :userid3, ..., userid12".
    Thanks in advance,
    Darren

    Got it... you mean, do I ever use a bind variable to store the result of a SQL statement (query). Answer is no, the bind variables are always criteria that are used by the SQL. Output is obtained by using FETCH.
    So I ought to be safe then.
    Thank you,
    Darren

  • Request for "WHERE  -   IN" Combination with Bind Variables.

    Hi,
    In ADF BC
    Im Creating the Bind Variables Searching methodolgy in ViewObject.
    SQL Editor:
    Query Like
    SELECT * FROM SEASON season WHERE season.MMYEAR IN (102007,112007) Here Done this query.
    In ViewObject Bind Variable Like B_MMYear .
    SQL Statement : SELECT season.Code,season.Location,season.MMYEAR FROM SEASON season already is there in SQL Statement in ViewObject
    Just im adding this conditon "WHERE season.MMYEAR IN (:B_MMYear)"
    after
    Drag&drop the ExecutewithParams form
    and im giving the MMYear like *102007,112008* then push ExecutewithParams....no Rows to Display...
    when im giving the only one vlaue like 102007 (Or ) 112007 then displays the suitable Row.
    how i can give the query Like "WHERE - IN" Combination in Bind Variables.
    Thanks,
    Rama.
    Edited by: user634195 on Oct 17, 2008 6:37 AM

    Thanks for rply Mr Timo.
    my BindVariable is not Numeric Type...it as a String. ok
    i already checks the debugging
    but i didn't get Exact Query
    query seems without Values same As SQL Statement in ViewOBject.
    like this
    SELECT season.Code,season.Location,season.MMYEAR FROM SEASON season WHERE season.MMYEAR IN (:B_MMYear)
    you Know...India Season of the Culture....
    see.
    In India Colture have Two Seasions
    1.Rabi.
    2.Kharif.
    example:
    Present Year : 2008 ok
    Rabi Season Strats from Oct2008 to March2009.
    Kharif Season Starts from Apr2008 to Sep2008.
    ok
    In my JSP Page one DropDown is there that is Season ok.
    when i select the Rabi....Then Rabi Months comes to page in CoreTable.
    i already done in DB:
    For Rabi:
    SELECT season.Code,season.Location,season.MMYEAR FROM SEASON season WHERE season.MMYEAR IN (10,11,12,01,02,03) done.
    For Kharif:
    SELECT season.Code,season.Location,season.MMYEAR FROM SEASON season WHERE season.MMYEAR IN (04,05,06,07,08,09) also done.
    the realtion b/w Bind Variable and Value....i think is somethink diff.
    Edited by: user634195 on Oct 17, 2008 7:50 AM

  • HOW to get the bind variables list.

    I've the following problem : I've some SQL queries stored in my DB as VARCHAR2 values.
    I need to use DBMS_SQL in order to execute them.
    In theese SQL statements I have some bind variables like :NUMORD. (ex. SELECT 'X' FROM YYYY WHERE FIELD_1 = :NUMORD).
    I don't know "a priori" names and number of such variables.
    Is there any way to have a list of such bind variables ?
    I found DBMS_DESCRIBE but is seems to act only on stored procedures/functions.
    I know I can tray to inspect the code looking for every ':' but a cleaner solution woulf be appreciated.
    Tks
    Tullio

    I don't know "a priori" names and number of such variables.
    Is there any way to have a list of such bind variables ?The names are probably not important, but you can get the count (and other useful information) like this:
    SQL> var cur refcursor
    SQL> declare
        cl clob;
    begin
        dbms_lob.createtemporary (cl, true);
        sys.utl_xml.parsequery (user, 'select e.deptno, :x x from emp e where deptno = :deptno', cl);
        open :cur for select cl cl from dual union all
                      select 'Count binds: ' || xmlquery('count(//BIND_VARIABLE)' passing xmltype(cl) returning content).getclobval() from dual;
        dbms_lob.freetemporary (cl);
    end;
    PL/SQL procedure successfully completed.
    SQL> print cur
    CL                                                                             
    <QUERY>                                                                        
      <SELECT>                                                                     
        <SELECT_LIST>                                                              
          <SELECT_LIST_ITEM>                                                       
            <COLUMN_REF>                                                           
              <SCHEMA>MICHAEL</SCHEMA>                                             
              <TABLE>EMP</TABLE>                                                   
              <TABLE_ALIAS>E</TABLE_ALIAS>                                         
              <COLUMN>DEPTNO</COLUMN>                                              
            </COLUMN_REF>                                                          
          </SELECT_LIST_ITEM>                                                      
          <SELECT_LIST_ITEM>                                                       
            <BIND_VARIABLE>1</BIND_VARIABLE>                                       
            <COLUMN_ALIAS>X</COLUMN_ALIAS>                                         
          </SELECT_LIST_ITEM>                                                      
        </SELECT_LIST>                                                             
      </SELECT>                                                                    
      <FROM>                                                                       
        <FROM_ITEM>                                                                
          <SCHEMA>MICHAEL</SCHEMA>                                                 
          <TABLE>EMP</TABLE>                                                       
          <TABLE_ALIAS>E</TABLE_ALIAS>                                             
        </FROM_ITEM>                                                               
      </FROM>                                                                      
      <WHERE>                                                                      
        <EQ>                                                                       
          <COLUMN_REF>                                                             
            <SCHEMA>MICHAEL</SCHEMA>                                               
            <TABLE>EMP</TABLE>                                                     
            <COLUMN>DEPTNO</COLUMN>                                                
          </COLUMN_REF>                                                            
          <BIND_VARIABLE>2</BIND_VARIABLE>                                         
        </EQ>                                                                      
      </WHERE>                                                                     
    </QUERY>                                                                       
    Count binds: 2                                                                 
    2 rows selected.

  • Bind variables in Toplink

    Hi,
    I’m trying to use bind variables in all my SQL calls via Toplink. My understanding is that bind variables gives better performance than the non-bind variables. If I use bindAllParameters() in the query object then only my search parameters are using the bind variables but the relationship object select statements are using hard-coded values. On the other hand if I set should-cache-all-statements to true then all the generated SQL uses bind variables.
    What is the best practice?
    Thanks
    -Mani

    The best way to use parameterized SQL is to enable it for the entire session, not on a per query basis.
    On the login (or in the sessions.xml) you must configure both the bindAllParameters and the cacheAllStatements for it to be effective. If you just bind parameters without caching the statements there will be no performance gain.
    TopLink can only cache statements when using it own connection pooling. If you are using external connection pooling or JTA you must only enable bindAllParameters in TopLink and not cacheAllStatements. You must enable statement caching in your DataSource or server's connection pool. In OC4J statement caching in configured in the datasources.xml file.

  • Report Performance with Bind Variable

    Getting some very odd behaviour with a report in APEX v 3.2.1.00.10
    I have a complex query that takes 5 seconds to return via TOAD, but takes from 5 to 10 minutes in an APEX report.
    I've narrowed it down to one particular bind. If I hard code the date in it returns in 6 seconds, but if I let the date be passed in from a parameter it takes 5+ minutes again.
    Relevant part of the query (an inline view) is:
    ,(select rglr_lect lect
    ,sum(tpm) mtr_tpm
    ,sum(enrols) mtr_enrols
    from ops_dash_meetings_report
    where meet_ev_date between to_date(:P35_END_DATE,'DD/MM/YYYY') - 363 and to_date(:P35_END_DATE,'DD/MM/YYYY')
    group by rglr_lect) RPV
    I've tried replacing the "to_date(:P35_END_DATE,'DD/MM/YYYY') - 363" with another item which is populated with the date required (and verified by checking session state). If I replace the :P35_END_DATE with an actual date the performance is fine again.
    The weird thing is that a trace file shows me exactly the same Explain Plan as the TOAD Explain where it runs in 5 seconds.
    Another odd thing is that another page in my application has the same inline view and doesn't hit the performance problem.
    The trace file did show some control characters (circumflex M) after each line of this report's query where these weren't anywhere else on the trace queries. I wondered if there was some sort of corruption in the source?
    No problems due to pagination as the result set is only 31 records and all being displayed.
    Really stumped here. Any advice or pointers would be most welcome.
    Jon.

    Don't worry about the Time column, the cost and cardinality are more important to see whther the CBO is making different decisions for whatever reason.
    Remember that the explain plan shows the expected execution plan and a trace shows the actual execution plan. So what you want to do is compare the query with bind variables from an APEX page trace to a trace from TOAD (or sqlplus or whatever). You can do this outside APEX like this...
    ALTER SESSION SET EVENTS '10046 trace name context forever, level 1';Enter and run your SQL statement...;
    ALTER SESSION SET sql_trace=FALSE;This will create a a trace file in the directory returned by...
    SELECT value FROM v$parameter WHERE name = 'user_dump_dest' Which you can use tkprof to format.
    I am assuming that your not going over DB links or anything else slightly unusual?
    Cheers
    Ben

  • SLOW report performance with bind variable

    Environment: 11.1.0.7.2, Apex 4.01.
    I've got a simplified report page where the report runs slowly compared to running the same query in sqldeveloper. The report region is based on a pl/sql function returning a query. If I use a bind variable in the query inside apex it takes 13 seconds to run, and if I hard code a string it takes only a few hundredths of a second. The query returns one row from a table which has 1.6 million rows. Statistics are up-to-date and the columns in the joins and where clause are indexed.
    I've run traces using p_trace=YES from Apex for both the bind variable and hard coded strings. They are below.
    The sqldeveloper explain plan is identical to the bind variable plan from the trace, yet the query runs in 0.0x seconds in sqldeveloper.
    What is it about bind variable syntax in Apex that is causing the bad execution plan? Apex Bug? 11g bug? Ideas?
    tkprof output from Apex trace with bind variable is below...
    select p.master_id link, p.first_name||' '||p.middle_name||' '||p.last_name||' '||p.suffix personname,
    p.gender||' '||p.date_of_birth g_dob, p.master_id||'*****'||substr(p.ssn,-4) ssn, p.status status
    from persons p
    where
       p.person_id in (select ps.person_id from person_systems ps where ps.source_key  like  LTRIM(RTRIM(:P71_SEARCH_SOURCE1)))
    order by 1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.01          0          1         27           0
    Fetch        2     13.15      13.22      67694      72865          0           1
    total        4     13.15      13.23      67694      72866         27           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62  (ODPS_PRIVACYVAULT)   (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT ORDER BY (cr=72869 pr=67694 pw=0 time=0 us cost=29615 size=14255040 card=178188)
          1   FILTER  (cr=72869 pr=67694 pw=0 time=0 us)
          1    HASH JOIN RIGHT SEMI (cr=72865 pr=67694 pw=0 time=0 us cost=26308 size=14255040 card=178188)
          1     INDEX FAST FULL SCAN IDX$$_0A300001 (cr=18545 pr=13379 pw=0 time=0 us cost=4993 size=2937776 card=183611)(object id 68485)
    1696485     TABLE ACCESS FULL PERSONS (cr=54320 pr=54315 pw=0 time=21965 us cost=14958 size=108575040 card=1696485)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   SORT (ORDER BY)
          1    FILTER
          1     HASH JOIN (RIGHT SEMI)
          1      INDEX   MODE: ANALYZED (FAST FULL SCAN) OF
                     'IDX$$_0A300001' (INDEX)
    1696485      TABLE ACCESS   MODE: ANALYZED (FULL) OF 'PERSONS' (TABLE)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      db file scattered read                       1276        0.00          0.16
      db file sequential read                       812        0.00          0.02
      direct path read                             1552        0.00          0.61
    ********************************************************************************Here's the tkprof output with a hard coded string:
    select p.master_id link, p.first_name||' '||p.middle_name||' '||p.last_name||' '||p.suffix personname,
    p.gender||' '||p.date_of_birth g_dob, p.master_id||'*****'||substr(p.ssn,-4) ssn, p.status status
    from persons p
    where
       p.person_id in (select ps.person_id from person_systems ps where ps.source_key  like  LTRIM(RTRIM('0b')))
    order by 1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.02       0.04          0          0          0           0
    Execute      1      0.00       0.00          0          0         13           0
    Fetch        2      0.00       0.00          0          8          0           1
    total        4      0.02       0.04          0          8         13           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 62  (ODPS_PRIVACYVAULT)   (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT ORDER BY (cr=10 pr=0 pw=0 time=0 us cost=9 size=80 card=1)
          1   FILTER  (cr=10 pr=0 pw=0 time=0 us)
          1    NESTED LOOPS  (cr=8 pr=0 pw=0 time=0 us)
          1     NESTED LOOPS  (cr=7 pr=0 pw=0 time=0 us cost=8 size=80 card=1)
          1      SORT UNIQUE (cr=4 pr=0 pw=0 time=0 us cost=5 size=16 card=1)
          1       TABLE ACCESS BY INDEX ROWID PERSON_SYSTEMS (cr=4 pr=0 pw=0 time=0 us cost=5 size=16 card=1)
          1        INDEX RANGE SCAN IDX_PERSON_SYSTEMS_SOURCE_KEY (cr=3 pr=0 pw=0 time=0 us cost=3 size=0 card=1)(object id 68561)
          1      INDEX UNIQUE SCAN PK_PERSONS (cr=3 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 68506)
          1     TABLE ACCESS BY INDEX ROWID PERSONS (cr=1 pr=0 pw=0 time=0 us cost=2 size=64 card=1)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   SORT (ORDER BY)
          1    FILTER
          1     NESTED LOOPS
          1      NESTED LOOPS
          1       SORT (UNIQUE)
          1        TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                       'PERSON_SYSTEMS' (TABLE)
          1         INDEX   MODE: ANALYZED (RANGE SCAN) OF
                        'IDX_PERSON_SYSTEMS_SOURCE_KEY' (INDEX)
          1       INDEX   MODE: ANALYZED (UNIQUE SCAN) OF 'PK_PERSONS'
                      (INDEX (UNIQUE))
          1      TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                     'PERSONS' (TABLE)

    Patrick, interesting insight. Thank you.
    The optimizer must be peeking at my bind variables with it's eyes closed. I'm the only one testing and I've never passed %anything as a bind value. :)
    Here's what I've learned since my last post:
    I don't think that sqldeveloper is actually using the explain plan it says it is. When I run explain plan in sqldeveloper (with a bind variable) it shows me the exact same plan as Apex with a bind variable. However, when I run autotrace in sqldeveloper, it takes a path that matches the hard coded values, and returns results in half a second. That autotrace run is consistent with actually running the query outside of autotrace. So, I think either sqldeveloper isn't really using bind variables, OR it is using them in some other way that Apex does not, or maybe optimizer peeking works in sqldeveloper?
    Using optimizer hints to tweak the plan helps. I've tried both /*+ FIRST_ROWS */ and /*+ index(ps pk_persons) */ and both drop the query to about a second. However, I'm loath to use hints because of the very dynamic nature of the query (and Tom Kyte doesn't like them either). The hints may end up hurting other variations on the query.
    I also tested the query by wrapping it in a select count(1) from ([long query]) and testing the performance in sqldeveloper and in Apex. The performance in that case is identical with both bind variables and hard coded variables for both Apex and SqlDeveloper. That to me was very interesting and I went so far as to set up two bind variable report regions on the same page. One region wrapped the long query with select count(1) from (...) and the other didn't. The wrapped query ran in 0.01 seconds, the unwrapped took 15ish seconds with no other optimizations. Very strange.
    To get performance up to acceptable levels I have changed my function returning query to:
    1) Set the equality operator to "=" for values without wildcards and "like" for user input with wildcards. This makes a HUGE difference IF no wildcard is used.
    2) Insert a /*+ FIRST_ROWS */ hint when users chose the column that requires the sub-query. This obviously changes the optimizer's plan and improves query speed from 15 seconds to 1.5 seconds even with wildcards.
    I will NOT be hard coding any user supplied values in the query string. As you can probably tell by the query, this is an application where sql injection would be very bad.
    Jeff, regarding your question about "like '%' || :P71_SEARCH_SOURCE1 || '%'". I've found that putting wildcards around values, particularly at the beginning will negate any indexing on the column in question and slows performance even more.
    I'm still left wondering if there isn't something in Apex that is breaking the optimizer "peeking" that Patrick describes. Perhaps something in the way it switches contexts from apex_public_user to the workspace schema?

Maybe you are looking for

  • Illustrator keeps crashing on launch

    Hi I have been using Illustrator on my Mac Pro now for approx 6 months with no issues, today I was working in illustrator, quit out to use Vectorworks. Had to go back into Illustrator and now will not start up. I get the splash screen and once the fo

  • Default Document Size

    I recently was working on a design for a #10 commercial envelope in InDesign. Ever since then, it seems that #10 envelope has become the default document size that InDesign selects when I create a New File. How can I change the default new document s

  • Do pictures in photo stream have to be downloaded to my iphoto library?

    When I look at my iPhoto Library I see photo stream broken down by month.  Do I need to download these pictures so that they show up in Events?

  • Can I Connect my G5 iPod to my Bose Wave Radio

    I have a Bose Wave system and would like to connect my iPod. What's the best way to do this to get the best sound? Do I need a universal dock or is that necessary? iMac   Mac OS X (10.3.9)  

  • Nokia E71 Case

    My E71 fell out of my bag this morning, and though I'm thankful it's still working perfectly, there's now a small chipped area top-left of the back side. My unit is a White Steel, and at the back part, the rounded corner, just near the power button,