DIfferent perfromance of same query on two database

We have our DEV database of 11.2.0.2 on Redhat 5.2, and our production database is a two node RAC of the same version on same ype of servers. Recently, we noticed that when run the same query on the two server, the DEV is 300 to 1000 times faster than on production, while the exec plan cost of DEV is one third of that of PRD. The query is SELECT PERSON_X_IDTY.PERSON_ID AS Facet_ID,1.0 AS Facet_Rank
FROM (IDTY INNER JOIN PERSON_X_IDTY ON ((IDTY.IDTY_ID = PERSON_X_IDTY.IDTY_ID)))
WHERE (((IDTY.IDTY_NAME_FIRST IS NOT NULL AND LOWER(IDTY.IDTY_NAME_FIRST) = LOWER('DAVID'))
AND (IDTY.IDTY_NAME_LAST IS NOT NULL AND LOWER(IDTY.IDTY_NAME_LAST) = LOWER('MILLER'))
AND (IDTY.IDTY_BIRTH_DATE IS NOT NULL
AND (IDTY.IDTY_BIRTH_DATE BETWEEN TO_DATE('1981-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')
AND TO_DATE('2000-12-31 23:59:59','YYYY-MM-DD HH24:MI:SS')))
AND (IDTY.IDTY_GENDER IS NOT NULL AND IDTY.IDTY_GENDER = 'M'))) AND ROWNUM<= 300 I know the query looks stupid, but that is generated and we are not to change it.
The exec plan show indexes are used for both table, but cost on PRD are heavier for index RANGE SCAN or BY INDEX ROWID. The index used for table IDTY is a functional index on IDTY.IDTY_NAME_LAST. I rebuild the indexes used but there is no improvement.
What parameters or configuration of database I need to check to find the reason for this case?
Thanks.

Thank you for all your replies. I did found some difference in init parameters and I restarted Oracle on PRD with a parameter file that is most copied from DEV and make the two as the same as possible. Not solve the problem. After noted that both tables involved are set to PARALLEL 4, I did SQL> alter table IDTY parallel 1;
SQL> alter table PERSON_X_IDTY patallel 1; The query plan got worse, but the query returned in a time comparable with DEV. THen I re-set parallelism back to 4 SQL> alter table IDTY parallel 4;
SQL> alter table PERSON_X_IDTY patallel 4; Query performance remained being good.
Now I have a work around, but hope can got an explaination? The parameters related to parallellism areNAME1                           VALUE_PRD                   VALUE_DEV                  
fast_start_parallel_rollback    LOW                         LOW                        
parallel_adaptive_multi_user    TRUE                        TRUE                       
parallel_automatic_tuning       FALSE                       FALSE                      
parallel_degree_limit           CPU                         CPU                        
parallel_degree_policy          MANUAL                      MANUAL                     
parallel_execution_message_size 16384                       16384                      
parallel_force_local            FALSE                       FALSE                      
parallel_io_cap_enabled         FALSE                       FALSE                      
parallel_max_servers            160                         160                        
parallel_min_percent            0                           0                          
parallel_min_servers            0                           0                          
parallel_min_time_threshold     AUTO                        AUTO                       
parallel_server                 TRUE                        FALSE                      
parallel_server_instances       2                           1                          
parallel_servers_target         64                          64                         
parallel_threads_per_cpu        2                           2                          
recovery_parallelism            0                           0    

Similar Messages

  • Select query on two Database views

    Hi all,
    Can i fetch the data by writing a select query on two DATABASE VIEWS
    Because i am able to fetch data by writing a selct query on ONE DATABASE VIEW and ON TRANSPARANT TABLE
    but i am not able to fetch data by writing a query on TWO DATABASE VIEWS
    Query which i am able to fetch data is
    select * from CSKS where OBJNR = COVJ-OBJNR
    Query which i am NOT able to fetch data is
    Select * from COAS where OBJNR = COVJ-OBJNR
    Here
    COVJ is a DATABASE VIEW
    CSKS is a Transparant Table
    COAS is a DATABASE VIEW
    Thanks in advance
    Regards
    Ajay

    Hi
    I tried with code and I am able to fetch data from view COAS
    DATA:it_coas TYPE STANDARD TABLE OF coas.
    SELECT * FROM coas INTO TABLE it_coas.
    IF sy-subrc IS INITIAL.
      WRITE:/ 'Sucess'.
    ENDIF.
    I think in your case COAS view does not have a value for COVJ-OBJNR.
    Regards
    Srilaxmi

  • One query on two databases acts differently.

    Hi - this is a doozy. I'd Ask Tom but I think he's busy...
    Database-A = PRODUCTION
    Database-B = TEST
    Both databases run 9.2.0.8, the parameter files in use are the same (so all optimizer settings etc are equal). The table spaces were created equally.
    One difference is that 'A' uses an overloaded SAN and 'B' is on a different one with plenty of bandwidth - though the problem sounds to me like a database optimizer issue, anyway...
    'B' schema was created from export/import of 'A'.
    The schemas have both been analyzed the same way (and both do each night).
    The problem is here that on 'B' the query uses the PK index on one of the tables whereas on 'A' the same query does not use the PK index.
    Note: There are slightly fewer rows in 'B' as 'A' is prod and getting updated.
    Already ruled out:
    optimizer_index_cost_adj: this is set to 100 on both databases and dropping it to 50, 10, 5 and 1 on 'A' does not make the optimizer favour the index.
    Stored outlines may not be an option for this query as we cannot alter the application code and the query changes....
    Any ideas where should I look next?
    Ta!

    Thanks to both the above comments.
    I did think about the data clustering but I kept
    coming back to why the optimizer on 'A' said "I want
    a full table scan" and 'B' says, "oh hey, there's an
    index, I'll use that".This has nothing to do with clustering data.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_1069.htm#i1578369 - look for 'Clustering Factor'
    Also see Note:39836.1
    IN a nutshell - it tells the system how bad an index could be when considering the organization of the table. A table (not index) reorg could easily change the clustering factor, give the same index for the same table with exactly the same data (but different row order) a completely different value.

  • How to create logical directories with same name on two databases

    Hi,
    OS: Windows
    Oracle Version : 10g
    I have to databases in one oracle home. I have created some logical directories in one database. When I am trying to create logical directories with same name in another database, it is overwriting the first database directory paths with the second one
    Can't we create directories with same name but different path in two databases on one machine?
    Pls suggest me on this
    Regards,
    Vijay

    I am trying to create logical directory using CREATE
    DIRECTORY statement. I am very much aware that the
    create directory statement doesn't create directory
    on OS. But we can attach the physical directory on OS
    to logical directory in oracle
    My requirement is to create logical directories in
    oracle mapping the OS directories. Both the
    databases, wil have same logical directory names but
    different OS directory mappingsIf I understand you correctly, you can do this:
    On DB 1
    CREATE OR REPLACE DIRECTORY same_dir_name as 'C:\myoracle\mydir1';
    On DB 2
    CREATE OR REPLACE DIRECTORY same_dir_name as 'D:\myoracle\mydir2';
    What stops you from doing that ?
    Note: If what you have is one database but different connections, then you are connecting to one database. The above second statement will drop and replace with the first one

  • Web template with different sections from same query

    Hi all.
    we have a query that display some characteristics for a single employ; we want to create a web template that display, in different analisys items (referred to same data provider), parts of query result.
    The query has only characteristics and no indexes.
    To explain better:
    Query result:
    Employ      1000
    B.U.           AAA
    City            Rome
    Level           A
    Web template:
    +------------------+                    +-----------------------+
    !    Employ 1000   !                    !    City    Rome       !
    +------------------+                    !    Level   A          !
                                            +-----------------------+      
            +--------------------+
            !  B.U.      AAA     !
            +--------------------+
    We should be able to write a web template like this using 3 different query but the question is: can we use the same query ? DATA_ROW_FROM / DATA_ROW_TO parameters don't work because only limits data rows but we have 1 only row!
    Thanks to all.
    Valter Casse
    AMS-BW
    SSC

    Have you considered creating and using query views?

  • Running the same query against numerous databases

    My organization has 20+ clients. Each client has a separate database in the same MSSQL server*. For these purposes, the databases are structurally identical. I've been tasked to gather information from tables in all of these databases. I can use the same query on multiple clients - my issue is switching between databases.
    The naive solution would be for me to declare 20+ DataSource instances, and have some mapping from client name to DataSource. I think that's going to be a real mess and my inclination is to avoid it.
    Another possibility would be dynamically generating the PreparedStatement based on the client, something like
    "SELECT foo, bar " + "FROM " + client.getDatabaseName() + ".dbo.my_table";
    My understanding, though, is that it's a bad practice to have dynamically generated prepared statement calls and not possible to parameterize the 'from' clause.
    Another thing I've been digging around at is using a transaction and an SQL Server call to alter what database calls from that transaction go to. I thought that could be done, but I'm not finding anything which suggests it's possible.
    I guess I've identified my problem, but I'm thrashing on how to solve it. I'm still newish to non-trivial database interactions, so I'd appreciate any input. If I posted this in the wrong place, please feel free to yell at me and move it.
    Thanks in advance,
    Eric
    * Not my fault. I'm new.

    I'm collection usage and storage metrics. "Client X has 200 records, Client Y has 250. Client X has 15 active users, Client Y has 12."
    The data is being read from the client databases and stored into a separate metrics database.
    I anticipate it will be mostly select count() calls.
    I can. For the maintenance reasons I mentioned above, I'd rather not have to maintain all those datasources if I don't have to.
    No, the invocations will be sequential.
    for (each metric type) {
        for (each client) {
            gather information;
            add to batch
        update batch in metrics database
    }I guess I was hoping there was a Sekrit SQL way to swap what database inside a server instance the connection was pointing to. I'm guessing that's not going to happen, and I'm left with N datasources for N clients or generated preparedStatements which swap out the database name in the FROM portion.
    The data is being written to a table in a single, separate metrics database.
    I'm trying not to, honest.
    Edited by: 919852 on Mar 12, 2012 8:38 AM

  • Different output of same query in SQL Server and Oracle

    I have two tables table1 and table2
    --table1 has two columns c1 int and c2 varchar. there are not constraints added in it. it has data as given below
    c1     c2
    6     d
    5     j
    102     g
    4     g
    103     f
    3     h
    501     j
    1     g
    601     n
    2     m
    --table2 has only one column c1 int. there are not constraints added in it. it has data as given below
    c1
    6
    1
    4
    3
    2
    now when i run below given query in sql server and oracle it gives me different result
    select *
    from table1
         inner join (SELECT ROW_NUMBER() OVER (order by c1 ASC) AS c1 from table2) table2 on table2.c1=table1.c1
    sql server output
    c1     c2     c1
    1     g     1
    2     m     2
    3     h     3
    4     g     4
    5     j     5
    oracle output
    C1 C2 C1
    5 j 5
    4 g 4
    3 h 3
    1 g 1
    2 m 2
    If you notice the first column in both output. It is sorted in sql server and not in oracle.
    Why it is behaving differently in oracle? Is there any way I can solve this in oracle?
    Thanks,
    Jigs

    It is NOT behaving "differently" in Oracle; you just haven't specified an order that you expect your results to be in, so you're going to get output in whatever order the database fancies displaying it (ie. no guarenteed order). This is an artifact of how the database chooses to put together the data, and different databases (or even datasets within the same database) can and most likely will behave differently.
    Even SQL Server won't guarentee to always get your data in an ordered fashion if you exclude the order by clause, even if you think it has always output the data in an ordered fashion.
    Your solution is to add an order by clause, in BOTH databases, to force the order of the output data.

  • Different results for same query on different servers

    1. database being converted from 7.3.4 to 9.2
    2. query is executed on both servers
    3. different results!
    The tables and data are the same, and indexes are setup on new server. EXPLAIN PLAN was run on both but with (predictably) widely different results.
    I know, not much detail here, but has anyone ever ran into anything like this?
    Thanks,
    Pat

    Folks,
    Here is the relevant information for this problem. The attributes have been changed for confidentiality. If you need any other information let me know.
    Thanks,
    Pat
    Query:
    SELECT
    one,two,three,four,a.five,six,seven,
    a.eight,a.nine,
    to_char(ten,'99999.99'),to_char(eleven,'99999.99'),
    to_char(twelve,'99999.99'),to_char(thirteen,'99999.99'),
    fourteen,fifteen,sixteen,seventeen,eighteen,
    nineteen,twenty,twentyone
    FROM
    table1 a,
    table2 b
    WHERE
    a.five = b.five
    AND one = 'X'
    AND six = ' '
    AND three != 12345
    AND three IN
    (SELECT DISTINCT
    three
    FROM table3
    WHERE
    one = 'X'
    AND twentytwo = 'XYZ'
    AND twentythree != 0
    AND twentyfour != 0
    AND twentyfive = 'Y'
    AND (a.five IN
    (SELECT DISTINCT
    five
    FROM table1
    WHERE
    one = 'X'
    AND three IN (12345)
    Table1:
    one          varchar2(1)     not null     PK
    two          varchar2(20)     not null     PK
    three          number(5)     not null     PK
    four          number(2)     not null     PK
    five          number(6)     not null     PK
    six          varchar2(4)     not null     PK
    seven          number(4)     not null
    eight          varchar2(8)     not null
    nine          date          not null
    ten          number(7,2)
    eleven     number(7,2)
    twelve     number(7,2)
    thirteen     number(7,2)
    Table2:
    five          number(6)     not null     PK
    fourteen     varchar2(5)     not null
    fifteen     varchar2(5)     not null
    sixteen     varchar2(2)     not null
    seventeen     varchar2(35)     not null
    eighteen     varchar2(4)     not null
    nineteen     varchar2(2)
    twenty     varchar2(1)
    twentyone     number(6)
    Table3:
    one          varchar2(1)     not null     PK
    twentytwo     varchar2(12)     not null     PK
    two          varchar2(20)     not null     PK
    three          number(5)     not null     PK
    four          number(2)     not null     PK
    twentysix     number(2)     not null     PK
    twentyfive     varchar2(1)     not null
    nine          date          not null
    twentythree     number(13,8)     not null
    twentyfour     number(12,8)     not null
    twentyseven     varchar2(1)     not null
    eight          varchar2(8)     not null
    Explain - Oracle9i (default, with CBO):
    SELECT STATEMENT
    RECURSIVE EXECUTION SYS_LE_3_0
    RECURSIVE EXECUTION SYS_LE_3_1
    TEMP TABLE TRANSFORMATION
    HASH JOIN
    HASH JOIN
    HASH JOIN
    TABLE ACCESS FULL SYS_TEMP_0FD9D6603_AB874A
    TABLE ACCESS BY INDEX ROWID TABLE1
    BITMAP CONVERSION TO ROWIDS
    BITMAP AND
    BITMAP MERGE
    BITMAP KEY ITERATION
    TABLE ACCESS FULL SYS_TEMP_0FD9D6603_AB874A
    BITMAP CONVERSION FROM ROWIDS
    INDEX RANGE SCAN TABLE1INDEX03
    BITMAP MERGE
    BITMAP KEY ITERATION
    TABLE ACCESS FULL SYS_TEMP_0FD9D6602_AB874A
    BITMAP CONVERSION FROM ROWIDS
    INDEX RANGE SCAN TABLE1INDEX04
    TABLE ACCESS FULL SYS_TEMP_0FD9D6602_AB874A
    TABLE ACCESS FULL TABLE2
    Query results - Oracle9i (with CBO):
    X|A | 1| 0| 22| | 1|08-MAR-02|XYZ | | 24.00| | |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|B | 2| 1| 22| | 7|04-DEC-01|XYZ | | 3.25| 8.00| |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|C | 3| 1| 22| | 1|14-AUG-02|XYZ | | 10.35| | |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|D | 4| 1| 22| | 6|11-JUL-02|XYZ | | .00| 13.90| |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|E | 5| 5| 23| | 1|22-FEB-01|XYZ | | 211.80| | |ABCDE|EFGHI|AB|HIJKLMN |DEF | | | |
    X|E | 5| 5| 23| | 1|22-FEB-01|XYZ | | 211.80| | |ABCDE|EFGHI|AB|HIJKLMN |DEF | | | |
    X|E | 5| 5| 23| | 1|22-FEB-01|XYZ | | 211.80| | |ABCDE|EFGHI|AB|HIJKLMN |DEF | | | |
    X|E | 5| 5| 23| | 1|22-FEB-01|XYZ | | 211.80| | |ABCDE|EFGHI|AB|HIJKLMN |DEF | | | |
    X|E | 5| 5| 23| | 1|22-FEB-01|XYZ | | 211.80| | |ABCDE|EFGHI|AB|HIJKLMN |DEF | | | |
    (approximately 4550 rows returned)
    Explain - Oracle9i (ALTER SESSION SET OPTIMIZER_METHOD=RULE;):
    SELECT STATEMENT
    MERGE JOIN
    SORT JOIN
    NESTED LOOPS
    NESTED LOOPS
    VIEW VW_NSO_1
    SORT UNIQUE
    TABLE ACCESS BY INDEX ROWID TABLE3
    INDEX RANGE SCAN TABLE3INDEXPK
    TABLE ACCESS BY INDEX ROWID TABLE1
    INDEX RANGE SCAN TABLE1INDEX03
    TABLE ACCESS BY INDEX ROWID TABLE2
    INDEX UNIQUE SCAN TABLE2INDEXPK
    SORT JOIN
    VIEW VW_NSO_2
    SORT UNIQUE
    TABLE ACCESS BY INDEX ROWID TABLE1
    INDEX RANGE SCAN TABLE1INDEX03
    Explain - Oracle 7.3.4:
    SELECT STATEMENT
    MERGE JOIN
    SORT JOIN
    NESTED LOOPS
    NESTED LOOPS
    VIEW
    SORT UNIQUE
    TABLE ACCESS BY ROWID TABLE3
    INDEX RANGE SCAN TABLE3INDEX03
    TABLE ACCESS BY ROWID TABLE1
    INDEX RANGE SCAN TABLE1INDEX03
    TABLE ACCESS BY ROWID TABLE2
    INDEX UNIQUE SCAN TABLE2INDEXPK
    SORT JOIN
    VIEW
    SORT UNIQUE
    TABLE ACCESS BY ROWID TABLE1
    INDEX RANGE SCAN TABLE1INDEX03
    Query results - Oracle 7.3.4:
    X|A | 1| 0| 22| | 1|08-MAR-02|XYZ | | 24.00| | |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|B | 2| 1| 22| | 7|04-DEC-01|XYZ | | 3.25| 8.00| |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|C | 3| 1| 22| | 1|14-AUG-02|XYZ | | 10.35| | |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|D | 4| 1| 22| | 6|11-JUL-02|XYZ | | .00| 13.90| |ABCDE|FGHIJ|AB|ABCDEFG |ABC | | | |
    X|E | 5| 5| 23| | 1|22-FEB-01|XYZ | | 211.80| | |ABCDE|EFGHI|AB|HIJKLMN |DEF | | | |
    (approximately 1150 rows returned)
    Indexes (used):
    TABLE1INDEX03     (three)
    TABLE1INDEX04     (five)
    TABLE2INDEXPK     (five)
    TABLE3INDEXPK     (one,twentytwo,two,three,four,twentysix)
    Discussion:
    Notice the repeating result for X,E,5,5,23,.... in the Oracle9i retrieval using CBO.
    The execution of this query returned approximately four times the number of rows as
    Oracle 7.3.4 using RBO. This is a function of how many "fours" there are in table3
    that have matching "threes and fours" in table1. If you put a DISTINCT clause at the
    very front of the query (SELECT DISTINCT one,two,three ....) then the result is
    accurate and the same as Oracle 7.3.4. In one execution of this query, 27,000 rows
    are expected to be returned, but the server returned over 1 million rows!
    When RBO was used on Oracle9i, the results were identical to the ones on Oracle 7.3.4.

  • Explain plan for same query in three databases

    Hi,
    We have three databases dev, uat and test, all have same init parameters and almost same data. We are running a query which runs long on dev and on uat and test it runs very fast, the explain plan on uat and test shows a cost of around 4000 but on dev the cost is 20000. Statistics were collected on three instances 2 days ago and the objects are also same.
    My question is what else should I look for this optimizer behaviour? the database version is 10.2.0.3.
    Please help.
    Thanks
    Clin

    user627471 wrote:
    Hi,
    We have three databases dev, uat and test, all have same init parameters and almost same data. We are running a query which runs long on dev and on uat and test it runs very fast, the explain plan on uat and test shows a cost of around 4000 but on dev the cost is 20000. Statistics were collected on three instances 2 days ago and the objects are also same.
    My question is what else should I look for this optimizer behaviour? the database version is 10.2.0.3.
    Please help.
    Thanks
    Clinpost both EXPLAIN PLAN here

  • Different query plans for same query on same DB

    Hi,
    HP-Ux
    Oracle Database 10.2.0.4
    We are experiencing a strange issue. One of our night batch process is taking invariably more time to execute. The process does not consume time at 1 particular query. Everyday we find a new query taking more time than previous execution.
    Now, when we see the explain plan while the query is executing, we see NESTED LOOP SEMI (with improper index being used). At the same time if we take the query and see the explain plan seperately, we get HASH JOIN SEMI (with proper index being used). Also, if we execute this query with the values as in procedure, it finishes within mili seconds (as it should).
    The tables and indexes are analyzed everyday before the process starts.
    Can anybody explain, why the same query shows two different plans at the same time ?
    Thanks a lot in advance :)

    Aalap Sharma wrote:
    HP-Ux
    Oracle Database 10.2.0.4
    We are experiencing a strange issue. One of our night batch process is taking invariably more time to execute. The process does not consume time at 1 particular query. Everyday we find a new query taking more time than previous execution.
    Now, when we see the explain plan while the query is executing, we see NESTED LOOP SEMI (with improper index being used). At the same time if we take the query and see the explain plan seperately, we get HASH JOIN SEMI (with proper index being used). Also, if we execute this query with the values as in procedure, it finishes within mili seconds (as it should).
    The tables and indexes are analyzed everyday before the process starts.
    Can anybody explain, why the same query shows two different plans at the same time ?As already mentioned, you might hit typical issues in 10.2: The column workload based SIZE AUTO statistics gathering feature and/or bind variable peeking.
    How do you analyze the tables and indexes before the process starts? Can you share the exact call with parameters?
    Some ideas:
    1. If your process is "new", then the column workload monitoring of the database might recognize the column usage pattern and generate histograms on some of your columns. It might take a while until the workload has been established so that all columns got histograms according to the workload (It needs a certain number of usages/executions before the workload is registered as relevant). Until then you might get different execution plans each time the statistics are refreshed due to new histograms being added.
    2. If the default 10g statistics gathering job is active, it might gather different statistics during the night than your individual job that runs prior to the processing. This could be one possible explanation why you get different plans on the next day.
    3. "Bind Variable Peeking" is possibly another issue you might run into. How do you test the query so that you get a different, well performing plan? Does your original statement use bind variables? Do you use literals to reproduce? Note that using EXPLAIN PLAN on statements involving bind variables can lie, since it doesn't perform bind variable peeking by default.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Trigger in a join table between two database

    Hi an Happy new year
    I have two database, one is dedicated to security and the second for my multitenancy application
    In this two databases one have tables USER, USER_JOIN_USER_ROLE and USER_ROLE
    the second, USER (where fields are differents), USER_JOIN_USER_ROLE and USER_ROLE
    the two join table must be the same and USER_ROLE are the same in the two databases.
    I plan to use a trigger to replicate from the  application database to the security one, I already use triggers to Replicate USER and set the differents fields.
    I'm new in triggers using.
    My user replication trigger seems like that
    CREATE TRIGGER [dbo].[USER_REPLICATION]
    ON [dbo].[DM_USER]
    AFTER INSERT
    AS
    BEGIN
    DECLARE @EmployeeId int = (SELECT FKEmployee FROM inserted)
    DECLARE @Login nvarchar(50) = (SELECT LoginUser FROM Inserted)
    DECLARE @Password nvarchar(50) = (SELECT PasswordUser FROM Inserted)
    DECLARE @Tenant int = (SELECT IdCompany FROM TEST_MULTI.dbo.DM_COMPANY WHERE IsTenant = ''Y'')
    DECLARE @CompanyId int = (SELECT ExtIdCompany FROM TEST_MULTI.dbo.DM_COMPANY WHERE IsTenant = ''Y'')
    DECLARE @LegalEntityId int = (SELECT FKLegalEntity FROM TEST_MULTI.dbo.DM_EMPLOYEE WHERE IdEmployee = @EmployeeId)
    DECLARE @LastName nvarchar(255) = (SELECT LastNameEmployee FROM TEST_MULTI.dbo.DM_EMPLOYEE WHERE IdEmployee = @EmployeeId)
    DECLARE @FirstName nvarchar(255) = (SELECT FirstNameEmployee FROM TEST_MULTI.dbo.DM_EMPLOYEE WHERE IdEmployee = @EmployeeId)
    DECLARE @EMail nvarchar(255) = (SELECT EMail FROM inserted)
    SET NOCOUNT ON;
    INSERT INTO DM_SECURITY_MASTER.dbo.DM_USER(LoginUser, PasswordUser, FKCompany, TenantId, LegalEntityId, LastName, FirstName, Email)
    VALUES (@Login, @Password, @CompanyId, @Tenant, @LegalEntityId, @LastName, @FirstName, @EMail)
    UPDATE [TEST_MULTI].[dbo].[DM_USER] SET ExtIdUser = (SELECT IdUser FROM [DM_SECURITY_MASTER].[dbo].[DM_USER]
    WHERE LoginUser = @Login
    AND PasswordUser = @Password
    AND FKCompany = @CompanyId
    AND TenantId = @Tenant
    AND LegalEntityId = @LegalEntityId
    AND LastName = @LastName
    AND FirstName = @FirstName
    AND EMail = @EMail)
    WHERE IdUser = (SELECT IdUser FROM Inserted)
    END
    but I cannot figure how to use a trigger to update a collection and not find anything on it, any help welcome
    I use Windows Identity Foundation in my code and update or insert can set multiple rows

    Hello and thanks for help.
    The trigger i give as example already works fine but Fanny Liu is for sure better than mine and I will try it. Users insertions are not multiple, only one user can be inserted at the same time
    My question was most on using triggers to update a collection via a Join table between my user and users roles
    I wrote it Yesterday for INSERT
    USE [TEST_MULTI]
    GO
    /****** Object: Trigger [dbo].[USER_ROLE_INSERT_REPLICATION] Script Date: 01/03/2014 10:56:36 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:
    -- Create date: 2014/02/01
    -- Description: Replication INSERT on MASTER DATABASE
    -- =============================================
    ALTER TRIGGER [dbo].[USER_ROLE_INSERT_REPLICATION]
    ON [TEST_MULTI].[dbo].[DM_USER_JOIN_USER_ROLE]
    AFTER INSERT
    AS
    DECLARE InsertCursor CURSOR FOR (SELECT FKUser, FKUserRole FROM inserted)
    DECLARE @UserId int, @UserRoleId int
    OPEN InsertCursor
    FETCH NEXT FROM InsertCursor INTO @UserId, @UserRoleId
    WHILE @@FETCH_STATUS = 0
    BEGIN
    DECLARE @UserMasterId int = (SELECT ExtIdUser FROM TEST_MULTI.dbo.DM_USER WHERE IdUser = @UserId)
    IF NOT EXISTS(SELECT * FROM DM_SECURITY_MASTER.dbo.DM_USER_JOIN_USER_ROLE WHERE FKUser = @UserMasterId
    AND FKUserRole = @UserRoleId)
    INSERT INTO DM_SECURITY_MASTER.dbo.DM_USER_JOIN_USER_ROLE (FKUser, FKUserRole) VALUES (@UserMasterId, @UserRoleId)
    FETCH NEXT FROM InsertCursor INTO @UserId, @UserRoleId
    END
    CLOSE InsertCursor;
    DEALLOCATE InsertCursor;
    And for DELETE
    USE [TEST_MULTI]
    GO
    /****** Object: Trigger [dbo].[USER_ROLE_DELETE_REPLICATION] Script Date: 01/03/2014 10:57:58 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:
    -- Create date: 2014/02/01
    -- Description: Replicate DELETE on MASTER DATABASE
    -- =============================================
    ALTER TRIGGER [dbo].[USER_ROLE_DELETE_REPLICATION]
    ON [TEST_MULTI].[dbo].[DM_USER_JOIN_USER_ROLE]
    AFTER DELETE
    AS
    DECLARE DeleteCursor CURSOR FOR (SELECT FKUser, FKUserRole FROM deleted)
    DECLARE @UserId int, @UserRoleId int
    OPEN DeleteCursor
    FETCH NEXT FROM DeleteCursor INTO @UserId, @UserRoleId
    WHILE @@FETCH_STATUS = 0
    BEGIN
    DECLARE @UserMasterId int = (SELECT ExtIdUser FROM TEST_MULTI.dbo.DM_USER WHERE IdUser = @UserId)
    DELETE FROM DM_SECURITY_MASTER.dbo.DM_USER_JOIN_USER_ROLE WHERE FKUser = @UserMasterId AND FKUserRole = @UserRoleId
    FETCH NEXT FROM DeleteCursor INTO @UserId, @UserRoleId
    END
    CLOSE DeleteCursor;
    DEALLOCATE DeleteCursor;
    It works fine
    Thanks for help, I will mark it as answered

  • Same query at same time, but different execution plans from two schemas

    Hi!
    We just had some performance problems in our production system and I would like to ask for some advice from you.
    We had a select-query that was run from USER1 on SCHEMA1, and it ran a table scan on a huge table.
    Using session browser in TOAD I copied the Sql-statement, logged on SCHEMA1 and ran the same query. I got a different execution plan where I avoided the table scan.
    So my question is:
    How is it possible that the same query get different execution plans when running in two different schemas at the same time.
    Some more information:
    The user USER1 runs "alter session set current_schema=SCHEMA1;" when it logs on. Besides that it doesn't do anything so session parameter values are the same for USER1 and SCHEMA1.
    SCHEMA1 is the schema owning the tables.
    ALL_ROWS is used for both USER1 and SCHEMA1
    Our database:
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    PL/SQL Release 9.2.0.8.0 - Production
    CORE     9.2.0.8.0     Production
    TNS for Linux: Version 9.2.0.8.0 - Production
    NLSRTL Version 9.2.0.8.0 - Production
    Anybody has some suggestions to why I experience different execution plan for the same query, run at the same time, but from different users?

    Thanks for clarification of the schema structure.
    What happens if instead of setting the current session schema to SCHEMA1, if you simply add the schema name to alle tables, views and other objects inside your select statement?
    As in select * from schema1.dual;I know that this is not what you want eventually, but it might help to find any misleading objects.
    Furthermore it is not clear what you meant with: "avoided a table scan".
    Did you avoid a full table scan (FTS) or was the table completely removed from the execution plan?
    Can you post both plans?
    Edited by: Sven W. on Mar 30, 2010 5:27 PM

  • One target table is loading from two different source but same columns but one source is in a database and other is in a flat file.

    Hope you all are doing good.
    I have a business issue to be implemented in ODI 11G. Here it is. I am trying to load a target table from two sources having same coulmn names. But one source is in file format and other is in Oracle Database.
    This is what i think i will create two mappings in the same interface using Union between the sources. But i am not sure how the interface would connect to different logical architecture to connect to two different sources.
    Thanks,
    SM

    You are on the right track, this can all be done in a single interface. Do the following
    1) Pull your file data model into the source designer and and your target table model to the target pane.
    2) Map all the relevant columns
    3) In the source designer create a new dataset and choose the UNION join type (this will create a separate tab in the source designer pane)
    4) Select the new dataset tab in the source designer pane and pull your source oracle table data model into the source designer. Map all the relevant columns to the target
    5) Make sure that your staging location is defined on a relational technology i.e. in this case the target would be an ideal candidate as that is where ODI will stage the data from both file and oracle source and perform the UNION before loading to the target
    If you want to look at some pretty screenshots showing the steps above take a look at http://odiexperts.com/11g-oracle-data-integrator-part-611g-union-minus-intersect/

  • Same query takes different time to fetch result from Database

    Hi all,
    I am having a scenario in which a query is taking different time keeping other environmental variables constant.
    When that query runs for 1 user it takes just 2 minutes to fetch result and the DB connection becomes inactive after fetching the result.
    But if I run the same query after some time in similar environment it takes 25 minutes. sometimes 40 minutes to execute and give the result to the app server from the same database.
    I am not able to understand this behavior from DB. Can anybody try to explain this behavior?
    The details of the DB are,
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    OS Details:
    Windows 2008 server Enterprise Edition.
    I tried analyzing that query in oracle, it recommended there are lots of hard parsing in that query.
    Regards,

    user10915512 wrote:
    Hi all,
    I am having a scenario in which a query is taking different time keeping other environmental variables constant.
    When that query runs for 1 user it takes just 2 minutes to fetch result and the DB connection becomes inactive after fetching the result.
    But if I run the same query after some time in similar environmentBut not exactly the same environment. So what is different that it is only "similar"?
    it takes 25 minutes. sometimes 40 minutes to execute and give the result to the app server from the same database.
    I am not able to understand this behavior from DB. Can anybody try to explain this behavior?Run a statspack on the 'well behaved' query and on the 'not well behaved' query. Compare and contrast the results.
    >
    The details of the DB are,
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    OS Details:
    Windows 2008 server Enterprise Edition. To paraphrase Forest Gump, "My momma always said Windows was like a box of chocolates ...."
    >
    >
    I tried analyzing that query in oracle, it recommended there are lots of hard parsing in that query.
    Regards,

  • Two database with the same sid but different ORACLE_HOME on one host

    two database with the same sid but different
    ORACLE_HOME on one host,and if configure them with
    two differnt lisnter staticaclly,this abosultely work
    because in the lisnter.ora we must provice
    ORACLE_HOME variable,with this ORACLE_HOME the client
    can differentiate which database to connect,but if
    use dynamically register feature,how can the client
    tell which database to connect?

    Also note that this type of configurtion may not be supported.
    Just because a given configuration works in certain given conditions does not mean that it would be supported.
    If this setup is for a configuration that has any value, please also Contact Oracle Support to get their inputs on what you are trying to accomplish.

Maybe you are looking for

  • Definitive Word On ID3 Tags, Library Files & Which Data Is Stored Where...

    I have spent a few hours just now (and have read the discussions a lot previously) on various iTunes issues, namely ones pertaining to organization and storage of data & info. I still have quite a few questions I would like the definitive answers for

  • Re: Local vs Remote Folder

    > However, when I try to use W: as the root folder > in DW, I get an error that the "selected folder does not contain the > current > sires' home page. The site map cannot be built".... That's not an error - it's an alert. And it only means that you

  • Need help for  the message flow in sap xi system?

    Hello All, My requirement is some wat different............in the existing production system the message flow is 3500 per hour......... now we want to develop new scenario and the message flow will be 8500 message per hour. Client is not giving me th

  • Env 3 not compatible?

    Hello, I have an env 3, and with my mac, it doesn't show up on the desktop when I connect it. I started using I sync, and it found my phone via bluetooth, but now says "Isync cannot sync with this device." Why? Is there a different way to do this? Pl

  • Using variables in IP

    Hi, I would like to use some variables adminstrated by a user in IP. For example, we want the central user to select the fiscal year for the Integrated application. The only solution we found is to create a specific table where the user enters a fisc