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

Similar Messages

  • Calling a .rdf report from a link on a apex report column

    Hi,
    I want to call a xxx.rdf report from a link on a apex report column.
    Can anyone help me on this ?
    Best regards,
    JCN

    Hi,
    Sorry - I should have read a bit further in your last post!
    The url variable that you're defining should just be the URL string that you want to create, so you only need the "http://........" part. There's also a + missing after the "&TODT..." string.
    The "DEA_PERMIT_ID=&G_PERMIT_ID." part at the end should have an & at the start to indicate a new parameter in the URL. Otherwise, &G_PERMIT_ID. would be replaced by the value stored in the session for the G_PERMIT_ID item (presumably that is an Application Item?).
    So:
    function callPopup()
    var url = "'http://snapper.accsp.org/reports/rwservlet?destype=cache&desformat=PDF&report=edr_landings_dollars_by_vessel.rdf&userid=evtr_report/chicken99@safis&FROMDT=" + $v("P810_FROM") + "&TODT=" + $v("P810_TO") + "&DEA_PERMIT_ID=&G_PERMIT_ID.";
    popupURL(url);
    }Andy

  • Poor performance when using bind variable in report

    I have a report that takes 1 second to run if i 'hardcode' a particular value into the where clause of the report. However, if i now replace the hardcoded value with a bind variable and set the default value for the bind variable to be the (previous) hard coded value the report now takes 50 seconds to run instead of 1 second!!
    Has anyone else seen this behaviour - any suggestions to workaround this will be gratefully received

    More info
    SELECT patch_no, count(*) frequency
    FROM users_requests
    WHERE patchset IN (SELECT arps2.patchset_name
    FROM aru_bugfix_relationships abr, aru_bugfixes ab, aru_status_codes ac,
    aru_patchsets arps, aru_patchsets arps2
    WHERE arps.patchset_name = '11i.FIN_PF.E'
    AND abr.bugfix_id = ab.bugfix_id
    AND arps.bugfix_id = ab.bugfix_id
    AND abr.relation_type = ac.status_id
    AND arps2.bugfix_id = abr.related_bugfix_id
    AND abr.relation_type IN (601, 602))
    AND included ='Y'
    GROUP BY patch_no
    order by frequency desc, patch_no
    Runs < 1 sec from SQL navigator and from portal (if i hardcode the value for fampack.
    Takes ~50 secs if i replace with :fampack and set default value to 11i.FIN_PF.D

  • Apex report performance is very poor with apex_item.checkbox row selector.

    Hi,
    I'm working on a report that includes some functionality to be able to select multiple records for further processing.
    The report is based on a view that contains a couple of hundred thousand records.
    When i make a selection from this view in sqlplus , the performance is acceptable but the apex report based on the same view performes very poorly.
    I've noticed that when i omit the apex_item.checkbox from my report query, performance is on par with sqlplus. (factor 10 or so quicker).
    Explain plan appears to be the same with or without checkbox function in the select.
    My query is:
    select apex_item.checkbox(1,tan_id) Select ,
    brt_id
    , tan_id
    , message_id
    , conversation_id
    , action
    , to_acn_code
    , information
    , brt_created
    , tan_created
    from (SELECT brt.id brt_id, -- view query
    MAX (TAN.id) tan_id,
    brt.message_id,
    brt.conversation_id,
    brt.action,
    TAN.to_acn_code,
    TAN.information,
    brt.created brt_created,
    TAN.created tan_created
    FROM (SELECT brt_id, id, to_acn_code, information, created
    FROM xxcjib_transactions
    WHERE tan_type = 'DELIVER' AND status = 'FINISHED') TAN,
    xxcjib_berichten brt
    WHERE brt.id = TAN.brt_id
    GROUP BY brt.id,
    brt.message_id,
    brt.conversation_id,
    brt.action,
    TAN.to_acn_code,
    TAN.information,
    brt.created,
    TAN.created)
    What could be the reason for the poor performance of the apex report?
    And is there another way to select multiple report records without the apex_item.checkbox function?
    I'm using apex 3.2 on oracle 10g database.
    Thanks,
    Niels Ingen Housz
    Edited by: user11986529 on 19-mrt-2010 4:06

    Thanks for your reply.
    Unfortunately changing the pagination doesnt make much of a difference in this case.
    Without the checkbox the query takes 2 seconds.
    With checkbox it takes well over 30 seconds.
    The second report region on this page based on another view seems to perform reasonably well with or without the checkbox.
    It has about the same number of records but with a different view query.
    There are also a couple of filter items in the where clause of the report queries (same for both reports) based on date and acn_code and both reports have a selectlist item displayed in their regions based on a simple lov. These filter items don't seem to be of influence on the performance.
    I have also recreated the report on a seperate page without any other page items or where clause and the same thing occurs.
    With the checkbox its very very slow (more like 20 times slower).
    Without it , the report performs well.
    And another thing, when i run the page with debug on i don't see the actual report query:
    0.08: show report
    0.08: determine column headings
    0.08: activate sort
    0.08: parse query as: APEX_CMA_ONT
    0.09: print column headings
    0.09: rows loop: 30 row(s)
    and then the region is displayed.
    I am using databaselinks in the views b.t.w
    Edited by: user11986529 on 19-mrt-2010 7:11

  • Calling A BI Publisher Report From A Link In An Apex Report

    I have a report on my page
    select id, aa, bb
    from table_x
    What I want to do is to have an extra column or use the id column as a link (which says Print Report) to call an BI Publisher report. This call should pass over the id and open the report in a popup window.
    For certain reasons I do not want to use the built in report queries and layouts in apex, just call the report straight for BI.
    I call other BI reports in my application, but always from a button.
    Help appreciated
    Gus

    Hi,
    All that such a button does is submit the page and branch to page zero passing in the request field something like this:
    PRINT_REPORT=my_report
    So, to do the same in a dynamic action, use an "execute javascript code" action with something like this in it:
    location.href = 'f?p=&APP_ID.:0:&SESSION.:PRINT_REPORT=my_report';
    Luis

  • 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>

  • View Link Bind variable issue

    All,
    I have a view link defined which and both the VO are part of my AM.
    At run time i am supposed to get the list of notes for a particular line. (the view link establishes this connection). However when i run my application i am not getting any records. Below SQL is getting fired for each request
    SELECT * FROM (SELECT note_type_meaning, note_status_meaning, creation_date, created_by_name,
           notes, row_id, jtf_note_id, notes_detail_size, entered_by,
           source_object_id, source_object_code, note_type, note_status, CONTEXT,
           attribute1, attribute2, attribute3, attribute4, attribute5, attribute6,
           attribute7, attribute8, attribute9, attribute10, attribute11,
           attribute12, attribute13, attribute14, attribute15, created_by,
           entered_date, last_updated_by, last_update_date, last_update_login
      FROM apps.ast_notes_details_vl
    WHERE source_object_id = :bLeadNumber) QRSLT  WHERE SOURCE_OBJECT_CODE = :Bind_LeadNumber
    <logQueryStatementAndBindParameters> BindVars:(bLeadNumber=null,Bind_LeadNumber=23040400)OK, the above sql is used to get the count but i am a bit lost as to why the bind variable is taking value at only one place.
    Please advise
    Jdev 11.1.1.5

    Sorry for this stupid post.

  • Passing value from MD form to bind variable in report

    I have an MD form, after I insert I want to redirect to a form and pass a value out of the detail section to the form to use as the value of it's bind variable. This works well on normal forms, but I cant seem to get it to work on the MD form. Below is an easy example and this doesnt work for me.
    MD form master dept/detail emp, code under the save button:
    doSave;
    declare
    l_empno integer;
    l_url varchar2(2000);
    begin
    l_empno := p_session.get_value_as_NUMBER(
    p_block_name => 'DETAIL_BLOCK',
    p_attribute_name => 'A_EMPNO',
    p_index => 1);
    l_url := 'SCOTT.EMP_RPT.show?'&#0124; &#0124;
    'p_arg_names=empno&p_arg_values='
    &#0124; &#0124;l_empno;
    portal30.wwa_app_module.set_target(l_url,'CALL');
    end;
    The form displays the empolyee information based on the value of empno from the MD form. The url looks like this http://hostname/pls/portal30/scott.emp_rpt.show?l_arg_names=empno&l_arg_values=
    so no rows get returned because there is no value, if i fill it in with a empno it works, so i know the report works, it just isnt the get_value isnt grabbing the empno from the MD form.
    null

    I figured it out, the save button on a MD form, the doSave; clears out the form fields so do a get_value_as will not work b/c there is nothing there, you need to get the value before the doSave; the below code will work.
    declare
    l_empno number;
    l_url varchar(2000);
    begin
    l_empno := p_session.get_value_as_NUMBER(
    p_block_name => 'DETAIL_BLOCK',
    p_attribute_name => 'A_EMPNO',
    p_index => 1);
    doSave;
    l_url := 'scott.EMP_RPT.show?'&#0124; &#0124;
    'p_arg_names=empno&p_arg_values='
    &#0124; &#0124; l_empno;
    portal30.wwa_app_module.set_target(l_url, 'CALL');
    end;

  • How to pass bind variable in report

    I'm trying to add tables and chart based of the value selected by the user using the filters.
    l_param_values := MGMT_IP_PARAM_VALUE_LIST();
    l_param_values.extend(13);
    l_param_values(1) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.sqlStatement',
    'SELECT TO_DATE(TO_CHAR (alloc.timestamp, ''MON RR''),''MON RR'') AS CALENDAR_MONTH,ROUND(AVG(alloc.avg_size_mb/1024),2) AS SIZE_GB,ROUND(AVG(used.avg_used_mb/1024), 2) AS USED_GB,
    ROUND (AVG ((alloc.avg_size_mb - used.avg_used_mb )/1024), 2) AS FREE_GB
    FROM
    (SELECT m.metric_column AS metric_column,m.rollup_timestamp AS timestamp,sum (m.average) AS avg_size_mb
    FROM
    mgmt$metric_daily m, mgmt$target_type t
    WHERE t.target_name LIKE ??EMIP_BIND_PARAMNAME??
    AND (t.target_type = ''rac_database''
    OR (t.target_type = ''oracle_database'' AND t.TYPE_QUALIFIER3 != ''RACINST''))
    AND m.target_guid = t.target_guid AND m.metric_guid = t.metric_guid AND t.metric_name = ''tbspAllocation''
    AND (t.metric_column = ''spaceAllocated'')
    and m.rollup_timestamp >= ??EMIP_BIND_START_DATE??
    and m.rollup_timestamp <= ??EMIP_BIND_END_DATE??
    GROUP BY m.rollup_timestamp, m.metric_column) alloc,
    ( SELECT m.metric_column AS metric_column, m.rollup_timestamp AS timestamp, sum (m.average) AS avg_used_mb
    FROM mgmt$metric_daily m, mgmt$target_type t
    WHERE t.target_name = ??EMIP_BIND_PARAMNAME??
    AND (t.target_type = ''rac_database''
    OR (t.target_type = ''oracle_database'' AND t.TYPE_QUALIFIER3 != ''RACINST''))
    AND m.target_guid = t.target_guid AND m.metric_guid = t.metric_guid AND t.metric_name = ''tbspAllocation''
    AND (t.metric_column = ''spaceUsed'')
    and m.rollup_timestamp >= ??EMIP_BIND_START_DATE??
    and m.rollup_timestamp <= ??EMIP_BIND_END_DATE??
    GROUP BY m.rollup_timestamp, m.metric_column) used
    WHERE alloc.timestamp = used.timestamp
    GROUP BY TO_CHAR (alloc.timestamp, ''MON RR'') order by 1');
    l_param_values(2) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterNames','NAME');
    l_param_values(3) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterPromptNAME','Database Name');
    l_param_values(4) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterTipNAME','Filter on the target names');
    l_param_values(5) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterPromptTYPE','Target Type');
    l_param_values(6) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterTipTYPE','Filter on the target types');
    l_param_values(7) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterStartEmpty', 'yes');
    l_param_values(8) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterEmptyTableHeaders','Calender Month, Size GB,Used GB,Free GB');
    l_param_values(9) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterSqlNAME',
    'select distinct t.target_name from mgmt$target t where (t.target_type = ''rac_database'' OR (t.target_type = ''oracle_database'' AND t.TYPE_QUALIFIER3 != ''RACINST'')) order by 1');
    l_param_values(10) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.numberOfColumnsShowed','4');
    l_param_values(11) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterHeaderText','DB Filter');
    l_param_values(12) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterTipText','My Tip Text');
    l_param_values(13) := MGMT_IP_PARAM_VALUE_RECORD (
    'oracle.sysman.eml.ip.render.elem.TableRender.filterButtonText','Get Growth');
    l_element_guid := mgmt_ip.add_element_to_report_def (
    p_report_guid => l_report_guid,
    p_element_name_nlsid => 'user_table_from_sql',
    p_element_type_nlsid => 'any_target_type',
    p_header_nlsid => 'Select DB for 6 Month Growth Summary',
    p_element_order => 1,
    p_element_row => 1,
    p_parameters => l_param_values,
    p_targets => null);
    Is there a way to pass the EMIP_BIND_PARAMNAME to a new element added to the report ?

    The report framework dev response was that the code was not designed for this use case (e.g. a report filter bind parameter used in multiple report elements). They said it is possible that this may work by chance (go ahead and try to pass the same filter parameters into other report elements and see what happens). If that does not work then you can work with your Oracle support contact to file an enhancement request.
    Edited by: cfowler on May 20, 2010 2:46 PM

  • Update before a report shows with bind variable

    I need to update a table before a report shows. This report have bind variable and I need bind variable value for clause where in update, how can I do that?
    I would thank so much any idea

    Mery,
    If I understand correctly your application should display a report when it is called.
    But first, before the report is displayed, you want to update a table, using a bind variable passed into the report when it is called. Do I understand correctly so far?
    So while editing the report, in the last tab option you have (Additional PL/SQL Code), you need to put some pl/sql code into section titled '...before displaying the page.'
    declare
    begin
    update table_x
    set column_x = somevalue
    where column_y = bind_variable;
    end;
    I haven't yet passed bind variables into reports so I'm not quite sure how to retrieve them, but I'm sure there are other postings here about that.
    I'm mostly just trying to clarify if this is what your asking, and maybe somebody else can answer the rest of your questions.
    Good luck.
    Kurt

  • Error with clob column: "No pl/sql translation for the blind type given for this bind variable"

    This is reports 11g
    I've got a clob column. Reports seems to recognize its type, but if I try to reference it in a format trigger, I get this error at compile time:
    "No pl/sql translation for the blind type given for this bind variable"

    Actually, Reports is in something better than Forms.
    Neither Forms nor Reports do not have "complete" SQL engine (both have only "complete" PL/SQL engine), but have their own SQL parser, which does not understand SQL commands after the database 8.0.
    But, in Reports Data Model - SQL Query Statement, we can write "modern" SQL statement (> database 8.0), because Reports sent it directly to the database, without using their own SQL parser.
    For example, in Reports Data Model - SQL Query Statement, we can write this (scalar subquery expressions, in bold):
    select empno,
           ename,
           deptno,
           (select dname from dept where deptno = emp.deptno) dname
      from emp
    order by empno;
    although scalar subquery expressions was introduced in the database 9.0.1, and in databases 8.0 and 8.1 we should write someting like this:
    select emp.empno,
           emp.ename,
           emp.deptno,
           dept.dname
      from emp,
           dept
    where dept.deptno = emp.deptno
    order by empno;
    Regards,
    Zlatko

  • Setting bind variable value programmatically for master and child VO's

    Defined following BC:
    Serv VO - Master VO, has Bind_cNum (bind variable)
    ServDetail VO - Child VO, has Bind_cNum2 (bind variable)
    ServViewLink VL - View link between Serv VO & ServDetail VO
    in AMModule Impl have custom WS:
    public List<ViewRowImpl> getMyServices(String cNum)
    List<ViewRowImpl> result = new ArrayList<ViewRowImpl>();
    ViewObjectImpl vo1 = getServ(); //Master VO
    vo1.setNamedWhereClauseParam("Bind_cNum", cNum);
    vo1.setForwardOnly(true);
    ViewObjectImpl vo2 = getServDetail(); //Child VO
    vo2.setNamedWhereClauseParam("Bind_cNum2", cNum);
    vo1.executeQuery();
    while (vo1.hasNext()) {
    result.add((ViewRowImpl)vo1.next());
    return result;
    I am passing same cNum parameter to both Serv VO (Master VO) and ServDetail VO (child VO) as above. (this is in addition to view link bind variable :Id)
    It shows in the logs that it is setting the values correctly:
    <ViewRowSetImpl> <setNamedWhereClauseParam> [382] Serv ViewRowSetImpl.setNamedWhereClauseParam(Bind_cNum, 11771370)
    <ViewRowSetImpl> <setNamedWhereClauseParam> [383] ServDetail ViewRowSetImpl.setNamedWhereClauseParam(Bind_cNum2, 11771370)
    <ViewRowSetImpl> <doSetWhereClauseParam> [383] Serv ViewRowSetImpl.doSetWhereClause(-1, Bind_cNum, 11771370)
    <ViewRowSetImpl> <execute> [385] Serv ViewRowSetImpl.execute caused params to be "un"changed
    <OracleSQLBuilderImpl> <bindParamValue> [394] Binding param "Bind_cNum": 11771370
    <ADFLogger> <addContextData> Execute query
    -- when executing view link
    <ViewRowSetImpl> <setParamValues> [425] ServViewLink_0 ViewRowSetImpl.setParamValues params changed
    <ViewRowSetImpl> <doSetWhereClauseParam> [426] ServViewLink_0 ViewRowSetImpl.doSetWhereClause(-1, Bind_cNum2, null)
    <ViewObjectImpl> <bindParametersForCollection> [436] For RowSet : ServViewLink_0
    <OracleSQLBuilderImpl> <bindParamValue> [437] Binding null of type 12 for "Bind_cNum2"
    <OracleSQLBuilderImpl> <bindParamValue> [438] Binding param "Bind_Id": 5018
    from above log, when ServViewLink_0 is executed, it is changing Bind_cNum2 bind variable to null.
    how can i pass same bind variable value to both Master and Child view objects from AM Impl.java
    Edited by: bsrao on Oct 11, 2012 6:07 PM
    Edited by: bsrao on Oct 11, 2012 6:10 PM
    Edited by: bsrao on Oct 11, 2012 6:12 PM

    Try executing the vo1 query before setting the bind variable for vo2, then execute the vo2 query (if that's what you want to do).

  • 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

  • Work Status Report Date and Time Setting

    Hi all We are running BPC10 on servers configured with Central European Time which is currently 2 hours ahead of GMT allowing for Daylight Savings Time. From what i can see in BPC10 date and times are now stored in GMT (Zulu time) in the Audit activi

  • What is HAWB in a procedure ?

    Hi All, What is HAWB in a procedure ? Thnx

  • Contact Form positioning, cells mis-aligned?

    I built a contact form and put it up at http://www.newood.com/catreq.htm For some reason, a couple of the cells that hold form fields are not aligned correctly, both in IE and in Firefox. Is there someone here that could check the code for me and mig

  • 5.0.5 so slow to load

    I have a new MacBook Pro running 10.6.8 and all of my browsers run well and load quickly EXCEPT Safari which is painfully slow to load EVERY single time. I have cleared cache and more... anyone else having this problem? It is as if SAFARI runs in MOL

  • Received DATABASE_ERROR

    I have been using berkeley xml db with a java server for a while now and I have been just recently, in the past few days, been getting these errors. I have not made any changes to my java code. I have only been changing some queries stored in text fi