Sequence of tables in from clause and sequence of "where clause" conditions

Is Sequence of tables in "From Clause" and sequence of "where clause" conditions matters in 10g for performance?
Edited by: user6763079 on Jun 1, 2011 3:33 AM

user6763079 wrote:
Is Sequence of tables in "From Clause" and sequence of "where clause" conditions matters in 10g for performance?In general it does not matter.
It could matter if the Rule Based Optimizer (RBO) is used. However this RBO is only used if enforced by a hint or if no table statistics are collected. Starting from 10g the table statistics are automatically selected by a regular database job. So in general the CBO would be used.
The CBO will consider different access paths. If the number of tables is low enough, then all possible combinations are considered and the order does not make any difference.
Edited by: Sven W. on Jun 1, 2011 4:00 PM

Similar Messages

  • ANSI SQL Syntax - What belongs to join-clause and what to where-clause

    Hello,
    we currently have a discussion about the ANSI SQL Syntax where we do not agree what belongs to the join clause and what belongs to the where clause in an ANSI Sytnax SQL Query.
    Lets say there is a query like this:
    +SELECT *+
    FROM employees emp, departments dept
    WHERE emp.dept_country = dept.dept_country
    AND emp.dept_name = dept.dept_name
    AND dept.dept_type = 'HQ'
    AND emp.emp_lastname = 'Smith'
    Primary key of the departments table is on the columns dept_country, dept_name and dept_type. We have a Oracle database 10g.
    Now I have rewritten the query to Ansi Syntax:
    +SELECT *+
    FROM employees emp
    JOIN departments dept
    ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name
    WHERE dept.dept_type = 'HQ'
    AND emp.emp_lastname = 'Smith'
    Another developer says that this is not completely correct, every filter on a column that belongs to the primary-key of the joined table has to be in the join clause, like this:
    +SELECT *+
    FROM employees emp
    JOIN departments dept
    +ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name AND dept.dept_type = 'HQ'
    WHERE emp.emp_lastname = 'Smith'
    Can somebody tell me which on is correct?
    Is there any definition for that? I couldn't find it in the Oracle Database definition.
    I just found out the names of the ANSI documents here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_standard_sql001.htm#i11939
    I had a look at the ANSI webstore but there you have to buy the PDF files. In my case thats exaggerated because both of the Queries work and i am just interessted if there is one correct way.
    Thank you in advance
    Marco

    Hi,
    As i guideline i would say, answer the question: should the result of the join be filtered or should only filtered rows be joined from a particular table?
    This is helpful in the case of outer joins also, for inner joins it doesnt matters as said already be former posters, where there may be hughe semantical differences depending of where the predicates are placed.
    From performance view, if we talk about oracle, take a look a the execution plans. You will see that there is (probably) no difference in case of inner joins. Even in case of outer joins the optimizer pushes the predicate as a filter towards the table if it semantically possible.
    Regards

  • Update table based on a select with a where clause

    I am trying to update a table only for records where i have a status of changed.
    Using the following code the update changes all the records putting in blank data if it is outwith the where clause.
    ideas?
    -- Update changed records
    UPDATE IP_SURVEY_ACTIVITY_REG_NO old
    SET (
    old.SLPN,
    old.SURVEY_DATE,
    old.SEQUENTIAL_REF_NUMBER,
    old.TOTAL_NUM_OF_SAMPLES,
    old.TOTAL_NUM_OF_ASSOC_SAMPLES,
    old.AIR_TESTS,
    old.REMARKS,
    old.SURVEY_DETAILS,
    old.FURTHER_SURVEY_DETAILS,
    old.GENERAL_COMMENTS) =
    (SELECT
    new.SLPN,
    new.SURVEY_DATE,
    new.SEQUENTIAL_REF_NUMBER,
    new.TOTAL_NUM_OF_SAMPLES,
    new.TOTAL_NUM_OF_ASSOC_SAMPLES,
    new.AIR_TESTS,
    new.REMARKS,
    new.SURVEY_DETAILS,
    new.FURTHER_SURVEY_DETAILS,
    new.GENERAL_COMMENTS
    FROM IP_SURVEY_ACTIVITY_REG_NO_INT new
    WHERE new.load_id = v_load_id
    AND new.status = 'CHANGED'
    AND new.sarn = old.sarn);
    cheers bjorn

    The EXISTS claue just needs to be added to your original query as a predicate on the ip_survey_activity_reg_no table. somethign like:
    UPDATE ip_survey_activity_reg_no old
    SET (old.slpn, old.survey_date, old.sequential_ref_number,
         old.total_num_of_samples, old.total_num_of_assoc_samples,
         old.air_tests, old.remarks, old.survey_details,
         old.further_survey_details, old.general_comments) =
                         (SELECT new.slpn, new.survey_date,
                                 new.sequential_ref_number,
                                 new.total_num_of_samples,
                                 new.total_num_of_assoc_samples, new.air_tests,
                                 new.remarks, new.survey_details,
                                 new.further_survey_details,new.general_comments
                          FROM ip_survey_activity_reg_no_int new
                          WHERE new.load_id = v_load_id and
                                new.status = 'CHANGED' and
                                new.sarn = old.sarn)
    WHERE EXISTS (SELECT 1 FROM ip_survey_activity_reg_no_int new
                  WHERE new.load_id = v_load_id and
                        new.status = 'CHANGED' and
                        new.sarn = old.sarn)An updateable join view is similar, except you just join the two tables. Assuming that sarn is the primary key of ip_survey_activity_reg_no_int, or is at least declared as unique in that table, then the update of the join would look something like:
    UPDATE (SELECT old.slpn oslpn, old.survey_date osurvey_date,
                   old.sequential_ref_number osequential_ref_number,
                   old.total_num_of_samples ototal_num_of_samples,
                   old.total_num_of_assoc_samples ototal_num_of_assoc_samples,
                   old.air_tests oair_tests, old.remarks oremarks,
                   old.survey_details osurvey_details,
                   old.further_survey_details ofurther_survey_details,
                   old.general_comments ogeneral_comments,
                   new.slpn nslpn, new.survey_date nsurvey_date,
                   new.sequential_ref_number nsequential_ref_number,
                   new.total_num_of_samples ntotal_num_of_samples,
                   new.total_num_of_assoc_samples ntotal_num_of_assoc_samples,
                   new.air_tests nair_tests, new.remarks nremarks,
                   new.survey_details nsurvey_details,
                   new.further_survey_details nfurther_survey_details,
                   new.general_comments ngeneral_comments
            FROM ip_survey_activity_reg_no old, ip_survey_activity_reg_no_int new
            WHERE new.sarn = old.sarn and
                  new.status = 'CHANGED' and
                  new.load_id = v_load_id)
    SET oslpn = nslpn,
        osurvey_date = nsurvey_date,
        osequential_ref_number = nsequential_ref_number,
        ototal_num_of_samples = ntotal_num_of_samples,
        ototal_num_of_assoc_samples = ntotal_num_of_assoc_samples,
        oair_tests = nair_tests,
        oremarks = nremarks,
        osurvey_details = nsurvey_details,
        ofurther_survey_details = nfurther_survey_details,
        ogeneral_comments = ngeneral_commentsHTH
    John
    Message was edited by:
    John Spencer
    Honest, Eric wasn't there when I posted :-)

  • How to select value from database view with * in wher clause

    Hi ,
      I ahve a database view with some fields.
    Now my requirement is to serach a single row on the basis of process type.
    Process type can have values like ZBA,ZBC,ZBD,ZBE or similarly anything starting with ZB.
    Now i know that starting two letters will be ZB , but dont knwo the last letter.
    So how should i use select query for the same?
    Should i use like operator for the same?
    regards
    PG

    hi,
    u can use character '%'.sample code like this
    SELECT reltype
                 instid_a
                 catid_a
                 instid_b
                 FROM /dbm/ord_docflow
                 INTO TABLE it_link
                 FOR ALL ENTRIES IN it_pnwtyh
                 WHERE  instid_a  =  it_pnwtyh-instid_a AND
                 instid_b  LIKE 'QMSM%'  AND
                 typeid_a  = 'BUS2400'  AND
                 typeid_b  = 'BUS2400' AND
                 catid_a   = 'BO' AND
                 catid_b   = 'BO' AND
                 reltype   = 'VONA'.
    this is similar to using* while we fetch values from table.in the above code only i no QMSM rest values not sure,so used QMSM%

  • The process time between INNER JOIN and join in WHERE clause

    as u know, there are 2 kind of join
    SELECT *
    FROM tableA
    INNER JOIN tableB
    ON tableA.ID= tableB.ID
    WHERE ....
    and
    SELECT *
    FROM tableA, tableA
    WHERE tableA.ID = tableB.ID
    AND ....
    I find the first one is faster in MS SQL Server.
    But i test them in oracle and i find that it is the same. Is it correct?

    Who knows why SQL Server shows different timings. Perhaps it's just cos it's not good at knowing that the two things are the same.
    The only difference in timing as far as Oracle is concerned is the time it takes to parse the syntax of the query, which will be nanoseconds. The execution time of two equivalent queries will not differ based on the factor of the syntax used.

  • Partition Pruning on Interval Range Partitioned Table not happening when SYSDATE used in Where Clause

    We have tables that are interval range partitioned on a DATE column, with a partition for each day - all very standard and straight out of Oracle doc.
    A 3rd party application queries the tables to find number of rows based on date range that is on the column used for the partition key.
    This application uses date range specified relative to current date - i.e. for last two days would be "..startdate > SYSDATE -2 " - but partition pruning does not take place and the explain plan shows that every partition is included.
    By presenting the query using the date in a variable partition pruning does table place, and query obviously performs much better.
    DB is 11.2.0.3 on RHEL6, and default parameters set - i.e. nothing changed that would influence optimizer behavior to something unusual.
    I can't work out why this would be so. It very easy to reproduce with simple test case below.
    I'd be very interested to hear any thoughts on why it is this way and whether anything can be done to permit the partition pruning to work with a query including SYSDATE as it would be difficult to get the application code changed.
    Furthermore to make a case to change the code I would need an explanation of why querying using SYSDATE is not good practice, and I don't know of any such information.
    1) Create simple partitioned table
    CREATETABLE part_test
       (id                      NUMBER NOT NULL,
        starttime               DATE NOT NULL,
        CONSTRAINT pk_part_test PRIMARY KEY (id))
    PARTITION BY RANGE (starttime) INTERVAL (NUMTODSINTERVAL(1,'day')) (PARTITION p0 VALUES LESS THAN (TO_DATE('01-01-2013','DD-MM-YYYY')));
    2) Populate table 1million rows spread between 10 partitions
    BEGIN
        FOR i IN 1..1000000
        LOOP
            INSERT INTO part_test (id, starttime) VALUES (i, SYSDATE - DBMS_RANDOM.value(low => 1, high => 10));
        END LOOP;
    END;
    EXEC dbms_stats.gather_table_stats('SUPER_CONF','PART_TEST');
    3) Query the Table for data from last 2 days using SYSDATE in clause
    EXPLAIN PLAN FOR
    SELECT  count(*)
    FROM    part_test
    WHERE   starttime >= SYSDATE - 2;
    | Id  | Operation                 | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |           |     1 |     8 |  7895  (1)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE           |           |     1 |     8 |            |          |       |       |
    |   2 |   PARTITION RANGE ITERATOR|           |   111K|   867K|  7895   (1)| 00:00:01 |   KEY |1048575|
    |*  3 |    TABLE ACCESS FULL      | PART_TEST |   111K|   867K|  7895   (1)| 00:00:01 |   KEY |1048575|
    Predicate Information (identified by operation id):
       3 - filter("STARTTIME">=SYSDATE@!-2)
    4) Now do the same query but with SYSDATE - 2 presented as a literal value.
    This query returns the same answer but very different cost.
    EXPLAIN PLAN FOR
    SELECT count(*)
    FROM part_test
    WHERE starttime >= (to_date('23122013:0950','DDMMYYYY:HH24MI'))-2;
    | Id  | Operation                 | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |           |     1 |     8 |   131  (0)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE           |           |     1 |     8 |            |          |       |       |
    |   2 |   PARTITION RANGE ITERATOR|           |   111K|   867K|   131   (0)| 00:00:01 |   356 |1048575|
    |*  3 |    TABLE ACCESS FULL      | PART_TEST |   111K|   867K|   131   (0)| 00:00:01 |   356 |1048575|
    Predicate Information (identified by operation id):
       3 - filter("STARTTIME">=TO_DATE(' 2013-12-21 09:50:00', 'syyyy-mm-dd hh24:mi:ss'))
    thanks in anticipation
    Jim

    As Jonathan has already pointed out there are situations where the CBO knows that partition pruning will occur but is unable to identify those partitions at parse time. The CBO will then use a dynamic pruning which means determine the partitions to eliminate dynamically at run time. This is why you see the KEY information instead of a known partition number. This is to occur mainly when you compare a function to your partition key i.e. where partition_key = function. And SYSDATE is a function. For the other bizarre PSTOP number (1048575) see this blog
    http://hourim.wordpress.com/2013/11/08/interval-partitioning-and-pstop-in-execution-plan/
    Best regards
    Mohamed Houri

  • Bad query plan for self-referencing CTE view query and variable in WHERE clause. Is there way out or this is SQL Server defect?

    Please help. Thank you for your time and expertise.
    Prerequisites: sql query needs to be a view. Real view is more than recursion. It computes location path,  is used in JOINs and returns this path.
    Problem: no matter what I tried, sql server does not produce 'index seek' when using variable but does with literal.
    See full reproduction code below.
    I expect that query SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = @lcID will seek UNIQUE index but it does not.
    I tried these:
    1. Changing UX and/or PK to be CLUSTERED.
    2. query OPTION(RECOMPILE)
    3. FORCESEEK on view
    4. SQL Server 2012/2014
    5. Wrap it into function and CROSS APPLY. On large outer number of rows this just dies, no solution
    but to no avail. This smells like a bug in SQL Server. I am seeking your confirmation.
    I am thinking it is a bug as variable value is high-cardinality, 1, and query is against unique key. This must produce single seek, depending if clustered or nonclustred index is unique
    Thanks
    Vladimir
    use tempdb
    BEGIN TRAN
    -- setup definition
    CREATE TABLE dbo.LocationHierarchy(
    lcID int NOT NULL ,
    lcHID hierarchyid NOT NULL,
    lcCode nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    lcHIDParent AS lcHID.GetAncestor(1) PERSISTED,
    CONSTRAINT PK_LocationHierarchy_lcID PRIMARY KEY NONCLUSTERED (lcID ASC),
    CONSTRAINT UX_LocationHierarchy_pltID_lcHID UNIQUE CLUSTERED (lcHID ASC)
    -- add some data
    INSERT INTO dbo.LocationHierarchy
    VALUES
    (1, '/', 'A')
    ,(2, '/1/', 'B')
    ,(3, '/1/1/', 'C')
    ,(4, '/1/1/1/', 'D')
    --DROP VIEW dbo.vwLocationCodes
    GO
    CREATE VIEW dbo.vwLocationCodes
    AS
    WITH ru AS
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.lcHID
    ,CAST('/' + lh.lcCode + '/' as varchar(8000)) as LocationPath
    -- to support recursion
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    UNION ALL
    SELECT
    ru.lcID
    ,ru.lcCode
    ,ru.lcHID
    ,CAST('/' + lh.lcCode + ru.LocationPath as varchar(8000)) as LocationPath
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    JOIN ru ON ru.lcHIDParent = lh.lcHID
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.LocationPath
    ,lh.lcHID
    FROM ru lh
    WHERE lh.lcHIDParent IS NULL
    GO
    -- get data via view
    SELECT
    CONCAT(SPACE(l.lcHID.GetLevel() * 4), lcCode) as LocationIndented
    FROM dbo.vwLocationCodes l
    ORDER BY lcHID
    GO
    SET SHOWPLAN_XML ON
    GO
    DECLARE @lcID int = 2
    -- I believe this produces bad plan and is defect in SQL Server optimizer.
    -- variable value cardinality is 1 and SQL Server should know that. Optiomal plan is to do index seek with key lookup.
    -- This does not happen.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = @lcID -- bad plan
    -- this is a plan I expect.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = 2 -- good plan
    -- I reviewed these but I need a view here, can't be SP
    -- http://sqlblogcasts.com/blogs/tonyrogerson/archive/2008/05/17/non-recursive-common-table-expressions-performance-sucks-1-cte-self-join-cte-sub-query-inline-expansion.aspx
    -- http://social.msdn.microsoft.com/Forums/sqlserver/en-US/22d2d580-0ff8-4a9b-b0d0-e6a8345062df/issue-with-select-using-a-recursive-cte-and-parameterizing-the-query?forum=transactsql
    GO
    SET SHOWPLAN_XML OFF
    GO
    ROLLBACK
    Vladimir Moldovanenko

    Here is more... note that I am creating table Items and these can be in Locations.
    I am trying LEFT JOIN and OUTER APLLY to 'bend' query into NESTED LOOP and SEEK. There has to be nested loop, 2 rows against 4. But SQL Server fails to generate optimal plan with SEEK. Even RECOMPILE does not help
    use tempdb
    BEGIN TRAN
    -- setup definition
    CREATE TABLE dbo.LocationHierarchy(
    lcID int NOT NULL ,
    lcHID hierarchyid NOT NULL,
    lcCode nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    lcHIDParent AS lcHID.GetAncestor(1) PERSISTED,
    CONSTRAINT PK_LocationHierarchy_lcID PRIMARY KEY NONCLUSTERED (lcID ASC),
    CONSTRAINT UX_LocationHierarchy_pltID_lcHID UNIQUE CLUSTERED (lcHID ASC)
    -- add some data
    INSERT INTO dbo.LocationHierarchy
    VALUES
    (1, '/', 'A')
    ,(2, '/1/', 'B')
    ,(3, '/1/1/', 'C')
    ,(4, '/1/1/1/', 'D')
    --DROP VIEW dbo.vwLocationCodes
    GO
    --DECLARE @Count int = 10;
    --WITH L0 AS (SELECT N FROM (VALUES(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) N (N))-- 10 rows
    --,L1 AS (SELECT n1.N FROM L0 n1 CROSS JOIN L0 n2) -- 100 rows
    --,L2 AS (SELECT n1.N FROM L1 n1 CROSS JOIN L1 n2) -- 10,000 rows
    --,L3 AS (SELECT n1.N FROM L2 n1 CROSS JOIN L2 n2) -- 100,000,000 rows
    --,x AS
    -- SELECT TOP (ISNULL(@Count, 0))
    -- ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) as Number
    -- FROM L3 n1
    --SELECT Number as itmID, NTILE(4)OVER(ORDER BY Number) as lcID
    --INTO dbo.Items
    --FROM x
    ----ORDER BY n1.N
    --ALTER TABLE dbo.Items ALTER COLUMN itmID INT NOT NULL
    --ALTER TABLE dbo.Items ADD CONSTRAINT PK PRIMARY KEY CLUSTERED (itmID)
    CREATE TABLE dbo.Items (itmID int NOT NULL PRIMARY KEY, lcID int NOT NULL)
    INSERT INTO dbo.items
    VALUES(1, 1)
    ,(2, 3)
    GO
    CREATE VIEW dbo.vwLocationCodes
    AS
    WITH ru AS
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.lcHID
    ,CAST('/' + lh.lcCode + '/' as varchar(8000)) as LocationPath
    -- to support recursion
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    UNION ALL
    SELECT
    ru.lcID
    ,ru.lcCode
    ,ru.lcHID
    ,CAST('/' + lh.lcCode + ru.LocationPath as varchar(8000)) as LocationPath
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    JOIN ru ON ru.lcHIDParent = lh.lcHID
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.LocationPath
    ,lh.lcHID
    FROM ru lh
    WHERE lh.lcHIDParent IS NULL
    GO
    -- get data via view
    SELECT
    CONCAT(SPACE(l.lcHID.GetLevel() * 4), lcCode) as LocationIndented
    FROM dbo.vwLocationCodes l
    ORDER BY lcHID
    GO
    --SET SHOWPLAN_XML ON
    GO
    DECLARE @lcID int = 2
    -- I believe this produces bad plan and is defect in SQL Server optimizer.
    -- variable value cardinality is 1 and SQL Server should know that. Optiomal plan is to do index seek with key lookup.
    -- This does not happen.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = @lcID-- OPTION(RECOMPILE) -- bad plan
    -- this is a plan I expect.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = 2 -- good plan
    SELECT *
    FROM dbo.Items itm
    LEFT JOIN dbo.vwLocationCodes l ON l.lcID = itm.lcID
    OPTION(RECOMPILE)
    SELECT *
    FROM dbo.Items itm
    OUTER APPLY
    SELECT *
    FROM dbo.vwLocationCodes l
    WHERE l.lcID = itm.lcID
    ) l
    -- I reviewed these but I need a view here, can't be SP
    -- http://sqlblogcasts.com/blogs/tonyrogerson/archive/2008/05/17/non-recursive-common-table-expressions-performance-sucks-1-cte-self-join-cte-sub-query-inline-expansion.aspx
    -- http://social.msdn.microsoft.com/Forums/sqlserver/en-US/22d2d580-0ff8-4a9b-b0d0-e6a8345062df/issue-with-select-using-a-recursive-cte-and-parameterizing-the-query?forum=transactsql
    GO
    --SET SHOWPLAN_XML OFF
    GO
    ROLLBACK
    Vladimir Moldovanenko

  • How to union results from 3 different dimensions in where clause with or - Mdx query

    Hi 
    I have a MDX Query and i need to pass the variable values to it by dynamically.
    Each time it will get any one attribute from three dimensions.
    Select 
    {} ON Columns,
    {} ON Rows 
    From
    Cube
    Where
    [Dimension1].[Attribut].&[Value]
    or
    [Dimension2].[Attribut2].&[Value]
    or
    [Dimension3].[Attribut3].&[Value]
    So It is working for two different values by using union and cross join.
    Can you please provide the solution ..
    Thanks in advance

    Hi Philip
    Thanks for replying me.
    I tried on that way, In my mdx query i am using one slice attribute (i.e [Customer].[Gender].allmembers) in rows so getting error "The  Hierarchy already appears in Axis1".
    SELECT
    {[Measures].[Internet Sales Amount] } ON 0,
    NON EMPTY
    {[Customer].[Gender].allmembers } ON 1 -- Used
    FROM
    [Adventure Works]
    WHERE
    [Customer].[Gender].&[M]
    ,[Product].[Size Range].[(All)]
    ,[Customer].[Country].[All Customers]
    [Customer].[Gender].[All Customers]
    ,[Product].[Size Range].&[XL]
    ,[Customer].[Country].[All Customers]
    [Customer].[Gender].[All Customers]
    ,[Product].[Size Range].[(All)]
    ,[Customer].[Country].&[Australia]
    Can you provide alternate ways to get resolved.
    Thanks in advance

  • DB Adapter wizard – WHERE clause on parent and child tables not working.

    I have two tables, SECURITY and SECURITY_POSITIONS, where SECURITY has a 1:M relationship with SECURITY_POSITIONS. I used the DB-adapter wizard to create the relationship and the following WHERE clause expression which is looking at both the parent and the child tables;
    The expression builder looks like this:
    AND
    |--- 1. partitionKey EQUAL p_SearchKey
    |--- 2. securityType EQUAL “DBT”
    |--- 3. securityPositionsCollection.dealReference EQUAL “NA”
    The primary key on SECURITY = PARTITION_KEY and SECURITY_REFERENCE
    The foreign key from SECURITY_POSITIONS to SECURITY = PARTITION_KEY and SECURITY_REFERENCE
    securityType is on SECURITY table (master)
    securityPositionsCollection.dealReference is on SECURITY_POSITIONS table (child)
    The invoke on the database adapter is selecting a row in securityPositionsCollection for each child row, rather than just those with dealReference = “NA”!
    I turned on DEBUG logging in the BPEL console and I can see that there are 2 SELECT queries run (guess this is how Toplink does it!), where the 1st query appears to select the parent rows and the 2nd query selects the child rows.
    However the 2nd query is not working because it is failing to select only those child rows where dealReference = “NA”. Also, don’t know why the 2nd SELECT query needs to specify the child SECURITY_POSITIONS table twice in the FROM clause, because that seems to be causing the problem.
    1st query executed is as follows;
    SELECT DISTINCT t0.PARTITION_KEY, t0.SECURITY_REFERENCE, t0.SECURITY_TYPE
    FROM CENTRAL.SECURITY t0, CENTRAL.SECURITY_POSITIONS t1
    WHERE ((((t0.PARTITION_KEY = ?) AND (t0.SECURITY_TYPE = ?)) AND (t1.DEAL_REFERENCE = ?)) AND ((t1.SECURITY_REFERENCE = t0.SECURITY_REFERENCE) AND (t1.PARTIT
    ION_KEY = t0.PARTITION_KEY)))
    bind => [200706200000, DBT, NA]
    2nd query executed is as follows, where child table appears twice! ;
    SELECT DISTINCT t0.DEAL_REFERENCE, t0.PARTITION_KEY, t0.SECURITY_REFERENCE
    FROM CENTRAL.SECURITY_POSITIONS t0,
    CENTRAL.SECURITY_POSITIONS t2,
    CENTRAL.SECURITY t1
    WHERE ((((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND (t0.PARTITION_KEY = t1.PARTITION_KEY)) AND
    (((t1.PARTITION_KEY = ?) AND (t1.SECURITY_TYPE = ?)) AND
    (t2.DEAL_REFERENCE = ?))) AND
    ((t2.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND
    (t2.PARTITION_KEY = t1.PARTITION_KEY)))
    bind => [200706200000, DBT, NA]
    Anyone experienced the same problem e.g. why is toplink making the query more complicated that it needs to be, because the query only needs to reference the SECURITY_POSITIONS table once, as follows;
    SELECT DISTINCT t0.DEAL_REFERENCE, t0.PARTITION_KEY, t0.SECURITY_REFERENCE
    FROM CENTRAL.SECURITY_POSITIONS t0,
    CENTRAL.SECURITY t1
    WHERE ((((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND (t0.PARTITION_KEY = t1.PARTITION_KEY)) AND
    (((t1.PARTITION_KEY = '200706200000') AND (t1.SECURITY_TYPE = 'DBT')) AND
    (t0.DEAL_REFERENCE = 'NA'))) AND
    ((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND
    (t0.PARTITION_KEY = t1.PARTITION_KEY)))

    Hello,
    It looks like you have configured your 1:M relationship to use batch reading. This causes the query to bring in the Security_Position table's objects to use the same selection criteria as was used on the initial query, with a join statement. This is more efficient in most cases as it ensures only the Security_positions needed for the Security objects to be fully built are read, in a single query.
    The selection criteria added is only used to filter out the Security objects. All referenced Security_Positions must be read in for the returned Security objects so that the data matches what is in the database. If you do not want the Security_Positions, you might try using indirection on the mapping which will delay the second query until you need the Security_Positions. Or, if you want only the Security_Positions with dealReference EQUAL “NA", you could do a query specifically to filter on them.
    Best Regards,
    Chris

  • Using where clause in Fetch Row from table

    Hello,
    I call Page2 from Page1, I pass PK1 to Page2.
    In the section Fetch Row from Table2, I write a Where clause ( FK2 = : PK1). I have data in Table2 with FK = PK1, but I cant view the data in Page2.
    Where is the error?
    Thanks for help.

    please recreate the problem in apex.oracle.com
    please create a developer account so that you don't give your email to all the spam-bots.
    MK

  • Empty WHERE Clause with AND condition after

    I have a question concerning a SQL query that I am using for a report. I have converted an old report to Crystal Reports 2008 and the resulting SQL query no longer works.
    After the conversion all the inner joins that were previously used in the report were moved to the FROM clause.
    My resulting WHERE clause is as follows:
    WHERE   AND
    "TABLE"."TABLEKEY" IS NOT NULL
    I get this error message:
    ORA-00936 Missing expression
    As you can see there WHERE clause has nothing before the AND condition because all the inner joins have moved to the FROM clause in the new version of Crystal Reports. I am fine with these inner joins moving but how do I take care of this empty condition.
    Any help is appreciated.

    Hi Joshua
    Please go through the following SAP note which deals with similar type of issue.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313335333533393334%7D.do
    Thanks

  • Dynamic query in where clause while looping in an internal table.

    Hi,
    Had a small question : How can i make a dynamic query for the WHERE clause while looping at an internal table.
    i want to implement a dynamic where clause query for the below example.
    it_cfx_col is an internal table and wa_cfx_col is a work area for it_cfx_col
      DATA :
      i_cfx_col TYPE TABLE OF cfx_col,
      wa_cfx_col LIKE LINE OF i_cfx_col.
    DATA : count TYPE i VALUE 0.
    DATA : l_where_clause TYPE string,
             l_where_clause2 TYPE string,
             l_name type string.
    l_name = 'NANDANOM'.
    l_scenario = 'collaboration'.
    LOOP AT it_cfx_col INTO wa_cfx_col
    WHERE CREATED_BY = l_name
    AND SCENARIO = l_scenario.
    count = count + 1.
    some business logic implemented using the work area wa_cfx_col
    endloop.
    Now i want to write a dynamic query for the where clause.
    DATA : count TYPE i VALUE 0.
      DATA : l_where_clause TYPE string,
             l_where_clause2 TYPE string,
             l_name type string.
    l_name = 'NANDANOM'.
    l_scenario = 'collaboration'.
      l_where_clause = 'CREATED_BY = l_name'.
      l_where_clause2 = 'AND SCENARIO = l_scenario'.
    if l_scenario is not initial.
      CONCATENATE  l_where_clause l_where_clause2
      INTO l_where_clause SEPARATED BY space.
    endif.
    LOOP AT i_cfx_col INTO wa_cfx_col
    WHERE (l_where_clause).
    count = count + 1.
    some business logic implemented using the work area wa_cfx_col
    endloop.
    when i compile this i get an error message as { Statement concluding with "...(l_where_clause)" ended unexpectedly}
    Even i changed the initilization of the variable  l_where_clause2 to [ l_where_clause2 = 'AND SCENARIO = l_scenario.'. ]
    added the end of line demarkation ".", but still i got the same error message.
    Is it a limtation in ABAP that i cannot write a dynamic query for the where clause while looping at an internal table?
    Regards,
    om

    Hi savita,
    there in no such 1 limitaion in abap for dynamic query .. i think the  error meassge is only beacuse of your synatx delcartaion.
    >> LOOP AT i_cfx_col INTO wa_cfx_col
       WHERE (l_where_clause).
       count = count + 1.
    some business logic implemented using the work     area    wa_cfx_col
       endloop.
    afted delclarataion also , in the where statement you should specify both the field name and value bname
       LOOP AT i_cfx_col INTO wa_cfx_col
       WHERE l_where_clause = 'CREATED_BY = l_name' .
       count = count + 1.
    hope it helps.
    regads
    priya.

  • Where clause in BMM (logical table Source) is not working

    Hello Folks ,
    I felt I ask here before I ask Siebel(oops Oracle!) support, by which I could save significant time NOT restart box multiple times , change log level , upload RPD , making multiple screen shots etc.. etc..
    Here is an example the scenario
    I have a custom field in the activity called the Activity source with two digit abbreviation
    TX – Text message
    LT – Letter
    EM – Email so forth
    The LOV table W_LOV_D has the type as CUST_SRC_ACT
    Whoever implemented analytics they did an alias table for W_LOV_D and did a physical join between W_ACTICITY_F to W_LOV_D through field VAL
    W_ACTICITY_F.X_ACT_SRC--> W_LOV_D.VAL and they did not do a where clause in BMM to retrieve only W_LOV_D.TYPE =’CUST_SRC_ACT’
    So in fact the query pulls TX for CUST_SRC_ACT as well as TX for State abbreviation
    I went ahead and added the where clause filter
    "Siebel Data Warehouse".Catalog.dbo."Dim_W_LOV_D_Acty_Src".TYPE = 'CUST_SRC_ACT'
    I saved the repository and started the server (I was doing offline) spooled the SQL and the results are the same. Looks like the filter is not being applied.
    I did reload the server meta data etc..
    Would anyone knows what is going on with the filter (or what I am doing wrong)?
    Thanks in advance,
    AP

    hi Ap,
    Pull only Dim_W_LOV_D_Acty_Src column into answers and check whether u r able to see CUST_SRC_ACT or not .Of course, you need to check sql query too
    Thanks,
    Saichand.v

  • Where Clause in Table Lookups for Data Load

    Hello,
    In Shared Components I created in Data Load Table. In this Data Load Table I added a Table Lookup. On the page to edit the Table Lookup, there is a field called Where Clause. I tried to add a Where Clause to my Table Lookup in this field but it seems that it has no effect on the Data Load process.
    Does someone know how to use this Where Clause field?
    Thanks,
    Seb

    Hi,
    I'm having the same problem with the where clause being ignored in the table lookup, is this a bug and if so is there a work around?
    Thanks in advance

  • WHERE clause comparing count and RowNumber

    Hello, I have just one more question with an error I'm running into. I'm wanting to use a WHERE or HAVING (tried both) to filter the returned data to be between a calculated RowNumber. I tried setting the filter on the tablix or using variables but neither
    one worked.I had some help getting the RowNumbers to work now I'm hoping to use that RowNumber to filter the data to only show the data in the middle 80* of what is returned. So what I'm trying to do is use count to find total number of rows. Then filter out
    the both 10% and top 90& using that count and then filtered on the RowNumbers.
    I tried using different syntax of WHERE and HAVING and I tried putting those clauses under the first WHERE clause or by itself outside of the second select (shown in the example now below). Nothing I've tried works. Is what I'm trying to do possible or is
    there another way I could do this if not?
    Thanks for the help, much appreciated!
    SELECT *,ROW_NUMBER() OVER (ORDER BY TTR) AS RowNumber FROM (
    SELECT
    FilteredIncidentResolution.incidentid,
    FilteredIncident.createdon,
    FilteredIncidentResolution.actualend,
    FilteredIncident.statecodename,
    FilteredIncident.casetypecodename,
    FilteredIncidentResolution.timespent,
    DATEDIFF(minute, FilteredIncident.createdon, FilteredIncidentResolution.actualend) as TTR
    FROM FilteredIncident INNER JOIN
    FilteredIncidentResolution ON FilteredIncident.incidentid = FilteredIncidentResolution.incidentid
    WHERE (FilteredIncident.statecodename = N'Resolved') AND (FilteredIncident.casetypecodename = N'Support') AND (FilteredIncidentResolution.actualend >= @start) AND
    (FilteredIncidentResolution.actualend <= @end)
    ) X
    WHERE RowNumber >= count(FilteredIncidentResolution.incidentid)*.1 AND RowNumber <= count(FilteredIncidentResolution.incidentid)*.9
    ORDER BY TTR

    You're making the same mistake as before. Calculated column can not be used in the WHERE clause. I think you're actually looking for the NTILE() function, but I will just fix your query:
    select * FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY TTR) AS RowNumber FROM (
    SELECT
    FilteredIncidentResolution.incidentid,
    FilteredIncident.createdon,
    FilteredIncidentResolution.actualend,
    FilteredIncident.statecodename,
    FilteredIncident.casetypecodename,
    FilteredIncidentResolution.timespent,
    DATEDIFF(minute, FilteredIncident.createdon, FilteredIncidentResolution.actualend) as TTR,
    COUNT(FilteredIncidentResolution.incidentid)
    OVER() as TotalIncidents
    FROM FilteredIncident INNER JOIN
    FilteredIncidentResolution ON FilteredIncident.incidentid = FilteredIncidentResolution.incidentid
    WHERE (FilteredIncident.statecodename = N'Resolved') AND (FilteredIncident.casetypecodename = N'Support') AND (FilteredIncidentResolution.actualend >= @start) AND
    (FilteredIncidentResolution.actualend <= @end)
    ) X
    ) Y
    WHERE RowNumber >= TotalIncidents*.1 AND RowNumber <= TotalIncidents*.9 -- we're excluding top 10 and bottom 10
    ORDER BY TTR
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

Maybe you are looking for

  • ITunes on Windows will not update any iOS-device

    I have three iOS-devices. An iPod Touch 3rd gen (ver 3.1.3), and iPhone 3GS (4.2.1) and iPad. It's been a really long time that I remember that iTunes offered to update any of them. iTunes itself has been regularly updating and is now 10.5.1.42. The

  • Web application deployment failure when Mozilla Rhino 15R2 included in war file

    Hi Guys I'm currently attempting to deploy a web application under weblogic 6.1. The application makes use of Mozilla Rhino15R2, packaged in the file js.jar. With js.jar contained in the WEB-INF\lib directory in the war file, the application fails to

  • Best Backup Solution for WAN

    What is the best -according to you- failover WAN solution for hub-and-spoke design network, the central office and all the other sites (10 total) will be within 50 miles, has anyone been faced with same decision making issue? Primary circuits will be

  • Custom TAB in txn WCOCO using Screen Enhancement(BADI Implementation)

    Hi, My requirement is to add a custom  tab with some fields in the Header in transaction WCOCO. I implemented the enhancement spot WCB_CC_VIEW_SPOT and the BAdi WCB_HEADER_DATA_TAB_I_BADI and am able to create the custom tab. All the details for the

  • DMS Content server restriction

    Hi All, In the past we have tried to restrict user access to DMS data (on content server) using DOC type/status restriction. Now we are trying to explore the possibilities of restricting users from accessing export control data from a specific conten