Generic extension where clause

I have two structs that are basically the same, both have two of the same public properties. I am trying to combine some extensions however when you define:
private static Dictionary<string, List<string>> ToDictionary<T>(this T source) where T : IEnumerable<StructA>, IEnumerable<StructB>
foreach (var item in source)
item.Name ...
Obviously source must now inherit from both IEnumerable interfaces, not one or the other. The problem is I am accessing the properties (such as .Name) and if I use a single interface, IEnumerable<object> the extension does not know if the properties exist.
Can this be done?
Thanks!

>>Obviously source must now inherit from both IEnumerable interfaces, not one or the other.
You cannot enforce the type argument to be of type IEnumerable<StructA>
OR IEnumerable<StructB>.
>>I have two structs that are basically the same
There is no "basically the same" in object-oriented programming. Either they are of the same type or they are not.
>>The problem is I am accessing the properties (such as .Name) and if I use a single interface, IEnumerable<object> the extension does not know if the properties exist.
If both structs have the same public property you could define an interface which declares this property and then make both structs implement the interface:
public interface HasName
string Name { get; set; }
public struct StructA : HasName
public string Name { get; set; }
public struct StructB : HasName
public string Name { get; set; }
You can then use the interface as the type constraint:
private static Dictionary<string, List<string>> ToDictionary<T>(this T source) where T : IEnumerable<HasName>
Note that an IEnumerable<StructA> cannot be implicitly converted to an IEnumerable<HasName> though so you still won't be able to call the extension method on a field declared as IEnumerable<StructA> rather than IEnumerable<HasName>.
Just because a StructA can be implicitly converted to a HasName it doesn't mean that a IEnumerable<StructA> can be converted to a IEnumerable<HasName>.
But you will be able to access the name property of any struct that implements the HasName interface, e.g:
List<HasName> sa = new List<HasName>();
sa.Add(new StructA());
sa.Add(new StructB());
var dict = sa.MyToDictionary(...);
If you want to treat a StructA differently to StructB in any way, it makes no sense to use a single generic method for both types. Then you should use a method per type instead.
Hope that helps.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question.

Similar Messages

  • Qualifying Expression and WHERE CLAUSE Extension

    I would like to know the exact difference between 'Qualifying Expression and WHERE CLAUSE Extension'. Since both are meant to contain some CONDITION that would facilitate the Edit Check's success, So I am sometimes a bit confused with these too as to when to use what.
    Can someone help Please??

    As you can tell from my previous posts (requests!) - I'm a newbie to OC.
    From the documentation - it appears that both Qualifying expression and Where Clause work the same way but the way they execute is different.
    Qualifying expression is applied after the fetch (key fields and question response data from DCM cursor i.e., after the cursor fetches the data) and Where clause filters before QG fetch.
    HTH

  • Expenditure Type LOV-- Adding where clause with controller extension- help

    Hi Gurus,
    I'm new to OA Framework and Java and I need to extend the controller for the expenditure type lov in iProcurement. I need to add a where clause to the VO to show only those expenditure
    types that will pass transactions controls based on the project and task.
    Name of the VO:ExpenditureTypeNoAwardLOVVO
    controller:oracle.apps.icx.lov.webui.ExpenditureTypeLovCO
    Original Query from the VO:
    select * from (SELECT et.expenditure_type, et.sys_link_start_date_active,
    et.sys_link_end_date_active, 1 as dummy_number
    FROM pa_expenditure_types_expend_v et
    WHERE et.system_linkage_function = 'VI'
    and (trunc(sysdate) between et.expnd_typ_start_date_active and
    nvl(et.expnd_typ_end_date_active, trunc(sysdate+1)))
    and (trunc(sysdate) between et.sys_link_start_date_active and
    nvl(et.sys_link_end_date_active, trunc(sysdate+1))) QRSLT
    ((WHERE UPPER(EXPENDITURE_TYPE) like UPPER(:1)
    AND (UPPER(EXPENDITURE_TYPE) like :2 or UPPER(EXPENDITURE_TYPE) like :3
    or UPPER(EXPENDITURE_TYPE) like :4 or UPPER(EXPENDITURE_TYPE) like :5)))
    I created a custom database function xxpa_check_txnctl which takes project_id, task_id and expenditure type as parameters and returns "Y" if that expenditure type is valid or
    returns "N" if it is not valid.
    What I need to add to the where clause of the above query is
    and *'Y' = ( select xxpa_check_txnctl(project_id,task_id,et.expenditure_type) from dual)* to the standard VO query so that only valid expenditure types will show up in the LOV for that
    project/task combination.
    I enabled the Debug Log from Diagnostics and able to see the values of project_id and task_id in the controller attached to the LOV (oracle.apps.icx.lov.webui.ExpenditureTypeLovCO) as shown
    below. Please tell me how I can add the where condition to the custom controller .
    I really appreciate your help.
    Thanks in Advance,
    Shree.
    ==========================================================================================
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# ProjectId=13
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:lov criteria item from dictionary in getLovItemNumber():
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# TaskId=796
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:VO used in ExpenditureTypeLovCO.java:
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# voName=ExpenditureTypeNoAwardLovVO
    ==========================================================================================
    Here is the code for the standard controller:
    ==========================================================================================
    package oracle.apps.icx.lov.webui;
    import com.sun.java.util.collections.ArrayList;
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.OAApplicationModule;
    import oracle.apps.fnd.framework.OAViewObject;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import oracle.apps.fnd.framework.webui.beans.form.OAFormValueBean;
    import oracle.apps.fnd.framework.webui.beans.layout.OAListOfValuesBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
    import oracle.apps.icx.por.req.webui.CheckoutInfoBaseCO;
    import oracle.jbo.domain.Number;
    public class ExpenditureTypeLovCO extends CheckoutInfoBaseCO
    public static final String RCS_ID = "$Header: ExpenditureTypeLovCO.java 120.1 2006/07/25 06:33:16 sudsubra noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: ExpenditureTypeLovCO.java 120.1 2006/07/25 06:33:16 sudsubra noship $",
    "oracle.apps.icx.lov.webui");
    public ExpenditureTypeLovCO()
    public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processRequest(oapagecontext, oawebbean);
    java.util.Dictionary dictionary = oapagecontext.getLovCriteriaItems();
    Number number = getLovItemNumber(oapagecontext, dictionary, "ReqAwardId");
    Number number1 = getLovItemNumber(oapagecontext, dictionary, "ProjectId");
    Number number2 = getLovItemNumber(oapagecontext, dictionary, "TaskId");
    String s = null;
    if(number == null)
    s = "ExpenditureTypeNoAwardLovVO";
    } else
    ArrayList arraylist = new ArrayList(1);
    arraylist.add("getDefaultAwardId");
    Number number3 = (Number)executeServerCommand(oapagecontext, oapagecontext.getApplicationModule(oawebbean), "CheckoutLovSvrCmd", arraylist);
    if(isLoggingEnabled(oapagecontext, 1))
    logParam(this, oapagecontext, "defaultAwardId", number3, 1);
    if(number.equals(number3))
    s = "ExpenditureTypeWithDefaultAwardLovVO";
    OAViewObject oaviewobject = (OAViewObject)oapagecontext.getApplicationModule(oawebbean).findViewObject("ExpenditureTypeWithDefaultAwardLovVO");
    oaviewobject.setWhereClauseParam(0, number1);
    oaviewobject.setWhereClauseParam(1, number2);
    } else
    s = "ExpenditureTypeWithAwardLovVO";
    OAViewObject oaviewobject1 = (OAViewObject)oapagecontext.getApplicationModule(oawebbean).findViewObject("ExpenditureTypeWithAwardLovVO");
    oaviewobject1.setWhereClauseParam(0, number);
    if(isLoggingEnabled(oapagecontext, 1))
    logMsg(this, oapagecontext, "VO used in ExpenditureTypeLovCO.java:", 1);
    logParam(this, oapagecontext, "voName", s, 1);
    OAMessageStyledTextBean oamessagestyledtextbean = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("ExpenditureType");
    oamessagestyledtextbean.setViewUsageName(s);
    OAMessageStyledTextBean oamessagestyledtextbean1 = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("StartDate");
    oamessagestyledtextbean1.setViewUsageName(s);
    OAMessageStyledTextBean oamessagestyledtextbean2 = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("EndDate");
    oamessagestyledtextbean2.setViewUsageName(s);
    OAFormValueBean oaformvaluebean = (OAFormValueBean)oawebbean.findIndexedChildRecursive("ReqAwardId");
    oaformvaluebean.setViewUsageName(s);
    OAFormValueBean oaformvaluebean1 = (OAFormValueBean)oawebbean.findIndexedChildRecursive("ProjectId");
    oaformvaluebean1.setViewUsageName(s);
    OAFormValueBean oaformvaluebean2 = (OAFormValueBean)oawebbean.findIndexedChildRecursive("TaskId");
    oaformvaluebean2.setViewUsageName(s);
    ((OAListOfValuesBean)oawebbean).setViewUsageName(s);
    public void processFormRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processFormRequest(oapagecontext, oawebbean);
    ==========================================================================================

    Hi, I will try to look into the issue. I have also done customizations like this in past.
    To achieve this, we must read the Process request of CO properly and understand the places, where you have to make changes. In my case, I identify such places and also I couldn't extend the controller class. SO I took the code from standard CO, changed it at couple of places and created a class file with same code as standard CO but with changed at some places. After that I gave newly created CO name in personalization property, so that the page will follow newly created custom CO.
    So I would suggest to read the CO properly, to understand which line is doing what......

  • How To change the ADF View Object  query where-clause at RunTime?

    I am trying to create a simple display page which will display user data (username, assoc_dist_id, assoc_agent_id, status , etc). The User data is stored in a database table and i am using an ADF Read Only table based on the View Object to display the data on the JSF page.
    However, i want to display only the users that a particular person accessing the page has the AUTH LEVEL to see. e.g. If the person accessing the page is an 'ApplicationAdministrator' then the page should display all users in the table, If its a 'DistributorAdministrator' then the page should display only users associated with that Distributor (i.e. assoc_dist_id = :p_Dist_id ) and If its an 'AgentAdministrator' , then the page should display only users associated with that Agent ( i.e. assoc_agent_id = :p_Agent_id).
    Currently my af:table component displays all the users in the table because the query for the view object is (select * from users) . However, i want to use the same viewobject and just set the where-clause at runtime with the appropriate parameter to restrict the dataset returned.
    Do anyone knows how to accomplish this ?

    David,
    See the custom method initializeDynamicVariableDefaults() in the SRViewObjectImpl.java class in the FrameworkExtentions project in the SRDemoSampleADFBC sample application. You can find out how to install the demo if you haven't already from the ADF Learning Center at:
    http://www.oracle.com/technology/products/adf/learnadf.html
    This class is a framework extension class for view objects that adds a neat, generic feature to be able to dynamic default the value of named bind variables. You can read more about what framework extension classes are and how to use them in Chapter 25, "Advanced Business Components Techniques" of the ADF Developer's Guide for Forms/4GL Developers, also available at the learning center above.
    It is an example of generic framework functionality that "kicks in" based on the presence of custom metadata properties on a named bind variable. See section 25.3.3 "Implementing Generic Functionality Driven by Custom Properties" in the dev guide for more details. Using this sample code, if you add a bind variable to a view object, and define a custom metadata property named "DynamicDefaultValue" on that bind variable, and set this custom metadata property to the value "CurrentUser", then that bind variable will have its value dynamically defaulted to the name of the authenticated user logged in. If instead you set this custom property to the value "UserRole", then the bind variable will be set to the comma-separated string containing the list of roles that the authenticated user is part of.
    Once you've created a framework extension class for view objects like this, you can have the view objects you create inherit this generic functionality.See section 25.1.4 "How to Base an ADF Component on a Framework Extension Class" in the dev guide for more info on this.
    By adapting a technique like this (or some idea similar that better suits your needs) you can have your view object query contain bind variables whose values automatically take on the defaults based on something in the user-session environment.

  • Dynamic where clause in my query

    I am using a view
    select * from vw_pt_inv_customer
    My requirement is have a web page where users can search for customers by filling in a form which has the following feilds: - User can fill in the form with all the feilds or not. I want a dynamic where clause.. how can i get this work for me?
    Title
    Firstname
    Surname
    Address1
    Address2
    Postcode
    Telephone No

    879796 wrote:
    I am using a view
    select * from vw_pt_inv_customer
    My requirement is have a web page What web frame work is used? Apex? Something else?
    where users can search for customers by filling in a form which has the following feilds: - User can fill in the form with all the feilds or not. I want a dynamic where clause.. how can i get this work for me?Dynamic where clauses are a Very Bad Idea (tm).
    And having an open ended search function on a web page is also not a great idea.
    If you are using Apex, the for performance (and even query flexibility) it will be better creating a separate reporting region for each unique query. A boolean rendering condition checks the existing bind variables in order to determine if that specific reporting region should be executed.
    This results in a reporting region having a proper and dedicated SQL query (no hacking of the where clause) and that region only being rendered for the proper combination of supplied filter criteria.
    A slightly more complex, but more flexible approach, is using a generic reporting region that calls a PL/SQL function that creates returns the SQL query for execution and rendering. The approach to this is very similar to constructing a SQL ref cursor (dynamically) for a client. The only difference is that instead of creating the actual ref cursor, the code simply needs to return the SQL source code statement - with bind variables. The Apex run-time does the rest (does the binds and execution and rendering).
    If you are not using Apex - you should still consider these approaches. And not hacking a single SQL to cater for all different types of filter conditions.

  • Where clause in COUNT function and joining two queries

    I have a table that I am trying to count the number of course passed, and also list the modules passed as well.
    the first problem I am having is what to put in the where variable , so that its not specific to a customer(I can use the query below for a particular customer and a particular course)but I will like a generic query where the result will be distinct in terms
    of user and course like the one below
    select FirstName,LastName,CourseTitle,Noofmodules, count (Coursecompleted) as modulescompleted from EStudentsprogress where Coursecompleted = '1'and EmailAddress = '[email protected]'
    and CourseTitle = 'Microsoft MOS 2010 EXCEL' Group by FirstName, LastName, CourseTitle, Noofmodules ;
    How can i make it list the result as above, whereby i dont specify the email address or course title(trying to get the result for all the clients )
    . Also I have a query that list the courses that is passed by the customer, I will like the column with the list of courses passed be added to the result above, but as a column for each course.
    select FirstName,LastName,CourseTitle, EmailAddress, CourseModule as coursepassed from EStudentsprogress where coursecompleted =1
    cheers

    Do you mean this?
    select FirstName,
    LastName,
    CourseTitle,
    Noofmodules,
    count (Coursecompleted) as modulescompleted,
    STUFF((SELECT ',' + CourseTitle
    FROM EStudentsprogress
    WHERE FirstName = e.FirstName
    AND LastName = e.LastName
    WHERE Coursecompleted = '1'
    FOR XML PATH('')),1,1,'') AS CoursesCompleted
    from EStudentsprogress e
    where Coursecompleted = '1'
    Group by FirstName, LastName, CourseTitle, Noofmodules ;
    If not please provide some sample data and explain the output you want
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page
    I AM HAVING Incorrect syntax near the keyword 'WHERE'. 
    It was a typo
    try this
    select FirstName,
    LastName,
    CourseTitle,
    Noofmodules,
    count (Coursecompleted) as modulescompleted,
    STUFF((SELECT ',' + CourseTitle
    FROM EStudentsprogress
    WHERE FirstName = e.FirstName
    AND LastName = e.LastName
    AND Coursecompleted = '1'
    FOR XML PATH('')),1,1,'') AS CoursesCompleted
    from EStudentsprogress e
    where Coursecompleted = '1'
    Group by FirstName, LastName, CourseTitle, Noofmodules ;
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page
    its populating all the result for a particular customer, so i added another clause to  it and it worked
    select FirstName,
    LastName,
    CourseTitle,
    Noofmodules, 
    count (Coursecompleted) as modulescompleted,
    STUFF((SELECT ','  + CourseTitle
    FROM EStudentsprogress 
    WHERE FirstName = e.FirstName
    AND LastName = e.LastName
    AND Coursecompleted = '1'
    AND CourseTitle = e.CourseTitle
    FOR XML PATH('')),1,1,'') AS CoursesCompleted
    from EStudentsprogress e
    where Coursecompleted = '1'
    Group by FirstName, LastName, CourseTitle, Noofmodules ;
    but the result of the column is long , so i tried to used the course module, which is a column with numbers, and i tried modifying the query , but i had Error converting data type varchar to float.( i checked and saw that stuff is for concatinating
    strings) is there a way around it.
    i used 
    select FirstName,
    LastName,
    CourseModule,
    CourseTitle,
    Noofmodules, 
    count (Coursecompleted) as modulescompleted,
    STUFF((SELECT ','  + CourseModule
    FROM EStudentsprogress 
    WHERE FirstName = e.FirstName
    AND LastName = e.LastName
    AND Coursecompleted = '1'
    AND CourseTitle = e.CourseTitle
    FOR XML PATH('')),1,1,'') AS CoursesCompleted
    from EStudentsprogress e
    where Coursecompleted = '1'
    Group by FirstName, LastName,CourseModule, CourseTitle, Noofmodules ;

  • Where clause on portal queries

    we'd like to apply a 'where clause' on the 'query' option of a portal form based on a table. Is there a generic procedure we can use in the pl/sql event handler block to do this? I've seen p_session.set_value used in the generated package with parameters '_block', '_WHERE_CLAUSE', and p_value - but not sure what syntax this is expecting and whether I can use it here.......
    any help appreciated.....

    Yes, it can be specified, exactly as it is set in the generated form package:
    p_session.set_value(
    p_block_name => "_block",
    p_attribute_name => '_WHERE_CLAUSE',
    p_value => <varchar2 string>,
    p_index => 1
    And syntax is the same as in the WHERE clause in a SELECT statement :
    .... WHERE empno=1234 and ename = 'BLAH' .... etc.....
    null

  • DYNAMIC WHERE CLAUSE in PROCEDURE

    I am trying to pass in the IN portion of the where clause to an update statement within a procedure and it is not updating any rows. I want to update 2 columns where the ID's are in the string of ID's I am passing in.
    PROCEDURE upd_corebio
    (p_dup_string     IN          VARCHAR2,
    p_source     IN          VARCHAR2,
    p_title          IN          VARCHAR2)
    IS
    BEGIN
    UPDATE corebio
    SET corettlbar = p_title, coresource = p_source
    WHERE coreid IN (p_dup_string);
    END upd_corebio;
    upd_corebio('1001,2002,3003','SOURCE','TITLE')
    FYI...COREID IS CHAR(10)
    CORETTLBAR IS CHAR(30)
    CORESOURCE IS CHAR(6)

    The rownum hint seems to work on my system (Windows, 9.2.0.1)
    First, we'll set up the objects
    create table collection_test (
      col1 NUMBER,
      col2 VARCHAR2(100)
    create sequence coll_seq
      start with 1
      increment by 1
      cache 100;
    begin
      for x in (select * from all_objects)
      loop
        insert into collection_test
          values( coll_seq.nextval, x.object_name );
      end loop;
    end;
    create unique index coll_test_idx
      on collection_test( col1 );
    analyze index coll_test_idx compute statistics
    analyze table collection_test compute statistics;Now, try with the "generic" approach, with the CARDINALITY hint, which won't work, and the rownum trick, which appears to work
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT *
      2    FROM collection_test
      3*  WHERE col1 IN (SELECT * FROM TABLE(CAST(f_number_table('1,2,3') as numberTable)))
    SQL> /
          COL1
    COL2
             1
    /1005bd30_LnkdConstant
             2
    /10076b23_OraCustomDatumClosur
             3
    /10297c91_SAXAttrList
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=297327 Card=1 Bytes=
              28)
       1    0   NESTED LOOPS (SEMI) (Cost=297327 Card=1 Bytes=28)
       2    1     TABLE ACCESS (FULL) OF 'COLLECTION_TEST' (Cost=19 Card=2
              7028 Bytes=756784)
       3    1     COLLECTION ITERATOR (PICKLER FETCH) OF 'F_NUMBER_TABLE'
    Statistics
            687  recursive calls
              0  db block gets
            331  consistent gets
              6  physical reads
             68  redo size
            546  bytes sent via SQL*Net to client
            503  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
             19  sorts (memory)
              0  sorts (disk)
              3  rows processed
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT *
      2    FROM collection_test
      3*  WHERE col1 IN (SELECT /*+ CARDINALITY(t 10) */ * FROM TABLE(CAST(f_number_table('1,2,3') as nu
    SQL> /
          COL1
    COL2
             1
    /1005bd30_LnkdConstant
             2
    /10076b23_OraCustomDatumClosur
             3
    /10297c91_SAXAttrList
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=297327 Card=1 Bytes=
              28)
       1    0   NESTED LOOPS (SEMI) (Cost=297327 Card=1 Bytes=28)
       2    1     TABLE ACCESS (FULL) OF 'COLLECTION_TEST' (Cost=19 Card=2
              7028 Bytes=756784)
       3    1     COLLECTION ITERATOR (PICKLER FETCH) OF 'F_NUMBER_TABLE'
    Statistics
              0  recursive calls
              0  db block gets
            177  consistent gets
              0  physical reads
              0  redo size
            546  bytes sent via SQL*Net to client
            503  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              3  rows processed
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT *
      2    FROM collection_test
      3*  WHERE col1 IN (SELECT /*+ CARDINALITY(t 10) */ * FROM TABLE(CAST(f_number_table('1,2,3') as nu
    SQL> /
          COL1
    COL2
             1
    /1005bd30_LnkdConstant
             2
    /10076b23_OraCustomDatumClosur
             3
    /10297c91_SAXAttrList
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=23 Card=10 Bytes=410
       1    0   NESTED LOOPS (Cost=23 Card=10 Bytes=410)
       2    1     VIEW OF 'VW_NSO_1' (Cost=11 Card=10 Bytes=130)
       3    2       SORT (UNIQUE)
       4    3         COUNT
       5    4           FILTER
       6    5             COLLECTION ITERATOR (PICKLER FETCH) OF 'F_NUMBER
              _TABLE'
       7    1     TABLE ACCESS (BY INDEX ROWID) OF 'COLLECTION_TEST' (Cost
              =1 Card=1 Bytes=28)
       8    7       INDEX (UNIQUE SCAN) OF 'COLL_TEST_IDX' (UNIQUE)
    Statistics
              0  recursive calls
              0  db block gets
             14  consistent gets
              0  physical reads
              0  redo size
            546  bytes sent via SQL*Net to client
            503  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
              3  rows processedUnless I'm missing the boat, it seems like the last approach is using the more appropriate index access path.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • REPORT with dynamic WHERE CLAUSE (run RDF or REP) ?

    Hi:
    When running a REPORT (myreport.rep) with dynamic where clause using a lexical parameter, I got this error:
    REP-1439: Cannot compile .REP or .PLX file as it does not have source
    If i run the report specifiying RDF extension (myreport.rdf) the report run successfully! Is this normal ?
    If I specify RDF extension will Report Server COMPILE the report everytime I execute it ?
    When using dynamic WHERE CLAUSE I will have to run RDF files instead of REP ?
    I'm running Reports 9i under Linux, with IDS under Windows.
    Waiting Help
    Joao Oliveira

    It sounds like you are building the .rep files on one platform (windows) and running them on another (linux). The reason that the .rdf file continues to work is that Reports recompiles the PL/SQL within the report when you move from one platform to another or change schemas. .rep files can't be re-compiled in this way so you need to ensure they are compiled successfully when converting them.
    You need to convert from .rdf to .rep on the platform that you are intending to run on. Try running rwconverter on the linux platform with "compile_all=yes" to produce the .rep file and running that .rep file.

  • OID: Matching rule where clause is null

    Hi All,
    I've installed OIM 11.1.1.5.0 BP02 with OID connector 9.0.4.14. I am able to provision to OID and to run the "OID User Target Recon" scheduled task successfully. However, when I run the "OID User Trusted Recon" scheduled task, I get the error below. Does anyone know why this error is occurring and how to solve it?
    [2012-05-15T22:55:11.791+02:00] [oim_server1] [NOTIFICATION] [IAM-5010000] [oracle.iam.reconciliation.impl] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] Generic Information: ignoreEvent Input Data : {Telephone=, Organization=Xellerate Users, Location=, Preferred Language=, Middle Name=, Xellerate Type=End-User Administrator, Title=, User ID=COETZETH, Manager ID=, Container DN=cn=Users, ssouid=, Status=Active, orclGuid=BA2694539E2C432F852460915924D067, [email protected], modifytimestamp=20120515192927z, Common Name=COETZETH, Role=Consultant, Server Name=OID IT Resource, TimeZone=, Department=, Last Name=Coetzee, First Name=Theuns} dateFormat : yyyy/MM/dd HH:mm:ss z
    [2012-05-15T22:55:11.792+02:00] [oim_server1] [NOTIFICATION] [IAM-5010000] [oracle.iam.reconciliation.impl.config] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] Generic Information: Xellerate User from cache
    [2012-05-15T22:55:11.792+02:00] [oim_server1] [ERROR] [IAM-5010000] [oracle.iam.reconciliation.impl] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] Generic Information: {0}[[
    oracle.iam.reconciliation.exception.ReconciliationException: Matching rule where clause is null
    at oracle.iam.reconciliation.impl.ReconOperationsServiceImpl.getMatchingRule(ReconOperationsServiceImpl.java:490)
    at oracle.iam.reconciliation.impl.ReconOperationsServiceImpl.ignoreEvent(ReconOperationsServiceImpl.java:390)
    at oracle.iam.reconciliation.impl.ReconOperationsServiceImpl.ignoreEvent(ReconOperationsServiceImpl.java:355)
    at Thor.API.Operations.tcReconciliationOperationsIntfEJB.ignoreEventx(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor1849.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
    at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
    at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy372.ignoreEventx(Unknown Source)
    at Thor.API.Operations.tcReconciliationOperationsIntfEJB_troehf_tcReconciliationOperationsIntfRemoteImpl.__WL_invoke(Unknown Source)
    at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:40)
    at Thor.API.Operations.tcReconciliationOperationsIntfEJB_troehf_tcReconciliationOperationsIntfRemoteImpl.ignoreEventx(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor1848.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:85)
    at $Proxy169.ignoreEventx(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor1847.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
    at $Proxy356.ignoreEventx(Unknown Source)
    at Thor.API.Operations.tcReconciliationOperationsIntfDelegate.ignoreEvent(Unknown Source)
    at com.thortech.xl.integration.OID.schedule.tasks.tcTskOIDUserReconciliation.reconcileUser(Unknown Source)
    at com.thortech.xl.integration.OID.schedule.tasks.tcTskOIDUserReconciliation.processRecord(Unknown Source)
    at com.thortech.xl.integration.OID.util.tcUtilLDAPOperations.pagingReconSearch(Unknown Source)
    at com.thortech.xl.integration.OID.schedule.tasks.tcTskOIDUserReconciliation.doReconSearch(Unknown Source)
    at com.thortech.xl.integration.OID.schedule.tasks.tcTskOIDUserReconciliation.processChange(Unknown Source)
    at com.thortech.xl.integration.OID.schedule.tasks.tcTskOIDUserReconciliation.execute(Unknown Source)
    at com.thortech.xl.scheduler.tasks.SchedulerBaseTask.execute(SchedulerBaseTask.java:384)
    at oracle.iam.scheduler.vo.TaskSupport.executeJob(TaskSupport.java:145)
    at sun.reflect.GeneratedMethodAccessor565.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at oracle.iam.scheduler.impl.quartz.QuartzJob.execute(QuartzJob.java:196)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
    [2012-05-15T22:55:11.794+02:00] [oim_server1] [ERROR] [] [XL_INTG.OID] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] ====================================================
    [2012-05-15T22:55:11.794+02:00] [oim_server1] [ERROR] [] [XL_INTG.OID] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] com.thortech.xl.integration.OID.schedule.tasks.tcTskOIDUserReconciliationException when reconciling COETZETH
    [2012-05-15T22:55:11.795+02:00] [oim_server1] [ERROR] [] [XL_INTG.OID] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] ====================================================[[
    [2012-05-15T22:55:11.795+02:00] [oim_server1] [ERROR] [] [XL_INTG.OID] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] ====================================================
    [2012-05-15T22:55:11.795+02:00] [oim_server1] [ERROR] [] [XL_INTG.OID] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] Exception in OID:tcTskOIDUserReconciliation:reconcileUser() oracle.iam.reconciliation.exception.ReconciliationException: Matching rule where clause is null
    [2012-05-15T22:55:11.796+02:00] [oim_server1] [ERROR] [] [XL_INTG.OID] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JTHLa8WBp20LVyCCyc1FgcIi000002,0] [APP: oim#11.1.1.3.0] ====================================================

    user10233157 wrote:
    Could anyone please explain to me how reconciliation and the various design console forms in OIM fit together? I am struggling to understand how resource objects, reconciliation fields, reconciliation action rules, reconciliation field mappings and reconcilaition rules all fit together... As for my original question, I have installed the OID connector and not made any modifications. I expected to see users created in OIM when running the trusted recon task.... When I run the target recon task existing users are associated with accounts in OID (as expected).Most times with OIM, following the documentation will not work. It requires knowledge of the product to find the missed steps, or missed pieces. You really need to get a baseline skill set with the product either through the Oracle By Examples or taking an Oracle University course. You are basically asking the community for all the answers but you haven't done your part.
    -Kevin

  • Derive found flag in SQL with where clause using TABLE(CAST function

    Dear All,
    Stored procedure listEmployees
    ==========================
    CREATE OR REPLACE TYPE STRING_ARRAY AS VARRAY(8000) OF VARCHAR2(15);
    empIdList STRING_ARRAY
    countriesList STRING_ARRAY
    SELECT EMP_ID, EMP_COUNTRY, EMP_NAME, FOUND_FLAG_
    FROM EMPLOYEE WHERE
    EMP_ID IN
    (SELECT * FROM TABLE(CAST(empIdList AS STRING_ARRAY))
    AND EMP_COUNTRY IN
    (SELECT * FROM TABLE(CAST(countriesList AS STRING_ARRAY))
    =================
    I have a stored procedure which lists the employees using above simple query.
    Here I am using table CAST function to find the list of employees in one go
    instead of looping through each and every employee
    Everything fine until requirements forced me to get the FOUND_FLAG as well.
    Now I wanted derive the FOUND_FLAG by using rownum, rowid, decode functions
    but I was not successful
    Can you please suggest if there is any intelligent way to say weather the
    row is found for given parameters in the where clause?
    If not I may have to loop through each set of empIdList, countriesList
    and find the values individually just to set a flag. In this approach I can’t use
    the TABLE CAST function which is efficient I suppose.
    Note that query STRING_ARRAY is an VARRAY. It is very big in size and this procedure
    suppose to handle large sets of data.
    Thanks In advance
    Regards
    Charan
    Edited by: kmcharan on 03-Dec-2009 09:55
    Edited by: kmcharan on 03-Dec-2009 09:55

    If your query returns results, you have found them... so your "FOUND" flag might be a constant,...

  • Index usage in depending on where clause changes.

    Hello Friends,
    I need your help for one issue.
    I have one query , which is using two table Say T1 and T2, where C1 is common column using which both are joined.
    C1 is primary key in T1, but no index available in T2 for C1. T1C2 is the column which we want to select.
    (Note that Either of table can be a Master table)
    Now see the query:
    Select T1C2
    From T1, T2
    where T2.C1 = T1.C1
    Here where clause may have other conditions and From clause may have others tables as per requirements.
    I want to know that, if, I change the query like following to let my query use the available index of T1.C1.
    Select T1C2
    from T1, T2
    where T1.C1 = T2.C1
    Then, Will the query use the available index of T1. and Will i get better performance. Even a little improvement in performance may help me a lot as this kind of query is being used within a where loop (so it is going to be executed multiple times).
    Please advise on this..
    Regards,
    Dipali..

    Hi,
    18:43:17 rel15_real_p>create table t1(c1 number primary key, c2 number);
    Table created.
    18:43:26 rel15_real_p>create table t2(c1 number, c2 number);
    18:45:08 rel15_real_p>
    18:45:09 rel15_real_p>begin
    18:45:09   2  for i in 1..100
    18:45:09   3  loop
    18:45:09   4        insert into t1(c1,c2) values (i,i+100);
    18:45:09   5  end loop;
    18:45:09   6  commit;
    18:45:09   7  end;
    18:45:09   8  /
    PL/SQL procedure successfully completed.
    18:45:09 rel15_real_p>
    18:45:09 rel15_real_p>
    18:45:09 rel15_real_p>begin
    18:45:09   2  for i in 1..100
    18:45:09   3  loop
    18:45:09   4        insert into t2(c1,c2) values (i,i+200);
    18:45:09   5  end loop;
    18:45:09   6  commit;
    18:45:09   7  end;
    18:45:09   8  /
    18:45:23 rel15_real_p>select count(*) from t1;
      COUNT(*)
           100
    18:45:30 rel15_real_p>select count(*) from t2;
      COUNT(*)
           100
    18:45:49 rel15_real_p>select index_name,index_type from user_indexes where table
    _name='T1';
    INDEX_NAME                     INDEX_TYPE
    SYS_C0013059                   NORMAL
    18:48:21 rel15_real_p>set autotrace on
    18:52:25 rel15_real_p>Select T1.C2
    18:52:29   2  From T1, T2
    18:52:29   3  where T2.C1 = T1.C1
    18:52:29   4  /
            C2
           101
           102
           103
           104
           105
            C2
           200
    100 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=7 Card=100 Bytes=
              900)
       1    0   HASH JOIN (Cost=7 Card=100 Bytes=3900)
       2    1     TABLE ACCESS (FULL) OF 'T1' (TABLE) (Cost=3 Card=100 By
              es=2600)
       3    1     TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 By
              es=1300)
    Statistics
              0  recursive calls
              0  db block gets
             21  consistent gets
              0  physical reads
              0  redo size
           1393  bytes sent via SQL*Net to client
            562  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            100  rows processed
    18:52:31 rel15_real_p>analyze table t1 compute statistics;
    Table analyzed.
    18:55:35 rel15_real_p>analyze table t2 compute statistics;
    18:55:38 rel15_real_p>set autotrace on
    18:55:42 rel15_real_p>Select T1.C2
    18:55:43   2  From T1, T2
    18:55:45   3  where T2.C1 = T1.C1
    18:55:46   4  /
            C2
           101
           102
           103
           104
           105
            C2
           200
    100 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=100 Bytes=7
              00)
       1    0   MERGE JOIN (Cost=6 Card=100 Bytes=700)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'T1' (TABLE) (Cost=2 Ca
              rd=100 Bytes=500)
       3    2       INDEX (FULL SCAN) OF 'SYS_C0013059' (INDEX (UNIQUE)) (
              Cost=1 Card=100)
       4    1     SORT (JOIN) (Cost=4 Card=100 Bytes=200)
       5    4       TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 B
              ytes=200)
    Statistics
              1  recursive calls
              0  db block gets
             23  consistent gets
              0  physical reads
              0  redo size
           1393  bytes sent via SQL*Net to client
            562  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
            100  rows processed
    18:56:56 rel15_real_p>Select T1.C2
    18:56:56   2  From T1, T2
    18:56:56   3  where T1.C1 = T2.C1
    18:56:58   4  /
            C2
           101
           102
           103
           104
           105
            C2
           200
    100 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=100 Bytes=7
              00)
       1    0   MERGE JOIN (Cost=6 Card=100 Bytes=700)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'T1' (TABLE) (Cost=2 Ca
              rd=100 Bytes=500)
       3    2       INDEX (FULL SCAN) OF 'SYS_C0013059' (INDEX (UNIQUE)) (
              Cost=1 Card=100)
       4    1     SORT (JOIN) (Cost=4 Card=100 Bytes=200)
       5    4       TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=3 Card=100 B
              ytes=200)
    Statistics
              1  recursive calls
              0  db block gets
             23  consistent gets
              0  physical reads
              0  redo size
           1393  bytes sent via SQL*Net to client
            562  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
            100  rows processed- Pavan Kumar N

  • Urgent: Performance problem with where clause using IN and an OR condition

    Select statement is:
    select fl.feed_line_id
    from ap_expense_feed_lines_all fl
    where ((:1 is not null and
    fl.feed_line_id in (select distinct r2.object_id
    from xxdl_pcard_wf_routing_lists r2,
         per_people_f hr2
    where upper(hr2.full_name) like upper(:1||'%')
              and hr2.person_id = r2.person_id
    and r2.fyi_list is null
              and r2.sequence_number <> 0))
    or
    (:1 is null))
    If I modify the statement to remove the "or (:1 is null))" part at the bottom of the where clause, it returns in .16 seconds. If I modify the statement to only contain the "(:1 is null))" part of the where clause, it returns in .02 seconds. With the whole statement above, it returns in 477 seconds. Anyone have any suggestions?
    Explain plan for the whole statement is:
    (1) SELECT STATEMENT CHOOSE
    Est. Rows: 10,960 Cost: 212
    FILTER
    (2) TABLE ACCESS FULL AP.AP_EXPENSE_FEED_LINES_ALL [Analyzed]
    (2) Blocks: 8,610 Est. Rows: 10,960 of 209,260 Cost: 212
    Tablespace: APD
    (6) TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F [Analyzed]
    (6) Blocks: 4,580 Est. Rows: 1 of 85,500 Cost: 2
    Tablespace: HRD
    (5) NESTED LOOPS
    Est. Rows: 1 Cost: 4
    (3) TABLE ACCESS FULL XXDL.XXDL_PCARD_WF_ROUTING_LISTS [Analyzed]
    (3) Blocks: 19 Est. Rows: 1 of 1,303 Cost: 2
    Tablespace: XXDLD
    (4) UNIQUE INDEX RANGE SCAN HR.PER_PEOPLE_F_PK [Analyzed]
    Est. Rows: 1 Cost: 1
    Thanks in advance,
    Peter

    Thanks for the reply, but I have already checked what you are suggesting and I am pretty sure those are not causing the problem. The hr2.full_name column has an upper index and the (4) line of the explain plan shows that index being used. In addition, that part of the query executes on its own quickly.
    Because the sql is not displayed in an indented format on this page it is a little hard to understand the structure so I am going to restate what is happening.
    My sql is:
    select a_column
    from a_table
    where ((:1 is not null) and a_column in (sub-select statement)
    or
    (:1 is null))
    The :1 bind variable is set to a varchar2 entered on the screen of an application.
    If I execute either part of the sql without the OR condition, performance is good.
    If the :1 bind variable is null with the whole sql statement (so all rows or a_table are returned), performance is still good.
    If the :1 bind variable is a not-null value with the whole sql statement, performance stinks.
    As an example:
    where (('wa' is not null) and a_column in (sub-select statement)) -- fast
    where (('wa' is null)) -- fast
    where (('' is not null) and a_column in (sub-select statement) -- fast
    or
    ('' is null))
    where (('wa' is not null) and a_column in (sub-select statement) -- slow
    or
    ('wa' is null))

  • Cardinality estimator 2014 is off with OR in where clause

    Here is my test setup on SQL Server 2014.
    -- Create big table
    CREATE TABLE [dbo].[Store](
    Id int IDENTITY(1,1) NOT NULL,
    City int NOT NULL,
    Size int NOT NULL,
    Name varchar(max) NULL,
    CONSTRAINT [PK_Store] PRIMARY KEY CLUSTERED ([Id] ASC)
    GO
    CREATE NONCLUSTERED INDEX [IX_Store] ON [dbo].[Store] (City ASC, Size ASC)
    GO
    -- Fill with 100k rows
    INSERT Store
    SELECT i % 101, i % 11, 'Store ' + CAST(i AS VARCHAR)
    FROM
    (SELECT TOP 100000 ROW_NUMBER() OVER (ORDER BY s1.[object_id]) AS i
    FROM sys.all_objects s1, sys.all_objects s2) numbers
    GO
    -- Create small table
    CREATE TABLE #StoreRequest (City int NOT NULL, Size int NOT NULL)
    GO
    INSERT #StoreRequest values (55, 1)
    INSERT #StoreRequest values (66, 2)
    Now I execute the following query (I force the index to show statistics estimates)
    SELECT s.City
    FROM #StoreRequest AS r
    INNER JOIN Store AS s WITH(INDEX(IX_Store), FORCESEEK)
    ON s.City = r.City AND s.Size = r.Size
    WHERE s.Size <> 1 OR r.City <> 55
    Here are the estimates that I get (I'm not allowed to upload pictures):
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 50000
    Fixing WHERE clause to use one table not two makes the estimate perfect:
    SELECT s.City
    FROM #StoreRequest AS r
    INNER JOIN Store AS s WITH(INDEX(IX_Store), FORCESEEK)
    ON s.City = r.City AND s.Size = r.Size
    WHERE s.Size <> 1 OR s.City <> 55
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 89.74
    Switching to 2012 compatibility mode gives estimate of 1 in both cases:
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 1
    Could anyone explain the first result? I'm a bit worried about it. The fix in this case is trivial, but this problem gave us quite some headache in more complex real life queries with multiple joins.
    Thank you!

    But not full statistics on a field basis, just sometimes some default stats like total row count that some plans will build.  Even your StoreRequest table only has one two-field index that will have a full histogram.
    But I've seen SQL Server make massively bad plans on two-field indexes.
    I've seen SQL Server go wrong one-column indexes, so that is not a very relevant point.
    Temp tables or not, the estimate here is clearly incorrect. SQL Server knows the density of Size and City. It knows the cardinality of the temp table. The density information gives how many rows the the join will produce. The WHERE clause will then remove
    a certain number of rows. With no statistics for the temp table, it does not now how many, but it will apply some standard guess.
    50000 is a completely bogus number, because the join cannot produce that many rows, and SQL Server is able to compute the join with out the WHERE clause decently. (Well, it estimates 90, when the number is 180.) No, this is obviously a case of the cardinality
    estimator giving up completely.
    It is worth noting that both these WHERE clauses gives reasonable estimates:
     WHERE r.Size <> 11 OR r.City <> 550
     WHERE s.Size <> 11 OR s.City <> 550
    Whereas these two gives the spooky 50000:
     WHERE s.Size <> 11 OR r.City <> 550
     WHERE r.Size <> 11 OR s.City <> 550
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Trouble with OR in where clause

    Hello,
    I'm having trouble with execution speed. The problem seems to be with using OR in my where clause.
    Here's the meat of the function where i_pledge_number is an input parm:
    BEGIN
    SELECT /*+ INDEX (pp) */ SUM(pp.prim_pledge_amount)
    INTO return_amount
    FROM
    primary_pledge pp
    WHERE
    -- Get total if multiple allocations
    pp.prim_pledge_number IN
    (SELECT pc.pledge_number
    FROM pledge_codes pc
    WHERE pc.pledge_code_type = 'M'
    AND pc.pledge_code = 'AC'
    AND lpad(pc.pledge_comment,10,'0') = i_pledge_number)
    -- Get total if single allocation
    OR pp.prim_pledge_number = i_pledge_number;
    RETURN return_amount;
    END;
    If I comment out either half of the OR statement (either the subquery or the pp.prim_pledge_number = i_pledge_number half) the function returns a value in .02 seconds. If I leave the OR in, it takes 2.764 seconds to execute?? Can someone please show me a better way (faster) to do this? I tried using nvl() around the subquery but couldn't get it to compile.
    Thanks

    These things are difficult to diagnose remotely, but here is something you can try....
    SELECT */ SUM(pp.prim_pledge_amount)
    INTO return_amount
    FROM   primary_pledge pp
    WHERE  pp.prim_pledge_number IN (SELECT pc.pledge_number
                                     FROM pledge_codes pc
                                     WHERE pc.pledge_code_type = 'M'
                                     AND pc.pledge_code = 'AC'
                                     AND lpad(pc.pledge_comment,10,'0') = i_pledge_number
    UNION ALL
    SELECT i_pledge_number FROM dual)
       RETURN return_amount;
    END;If that doesn't do anything (and it might well not) there are a large number of different ways we can recast this query. To save us further guessing please give us more details: execution plans, database version number, volumetrics.
    Cheers, APC

Maybe you are looking for

  • E1000 Dies After Streaming from Mac to Apple TV - Needs Reboot Every Time

    Hey everyone: I got an Apple TV a few weeks back and we've been using it a lot, especially to stream Netflix.  However, another application that I got it for was for streaming iPhoto slideshows and iMovie stuff to the Apple TV with Airplay's screen s

  • Trying to do shop on behalf.

    Hi SRM Guru's         While iam trying to do shop on behalf of my manager iam not able to find my manager's name in that list. Please suggest what can i suppose to do if i have to find my manager name. please help me. Thanks & Regards kala

  • Editing multiple objects

    Pretty simple question, How to I edit multiple objects from their individual centre points? Cheers -Ford

  • Linking different buttons to different sections of a slideshow

    Hi. I have created a iDVD8 project with six buttons. When I select each of these buttons in turn in my finished DVD I would like them to link to different sections of the SAME slideshow. Can I do this? The DVD is a slideshow of photos for 2007. Butto

  • Time Zone CCM

    I have a Cisco Call Manager version 4.3, and set the Time Zone to GMT-04:00 Santiago and my phone display the GMT hours. For example I set the Time Zone to GMT-04:00 Caracas, La Paz, the phones show the correct hours, the problem is specific whit the