BI Quest [A blog on Informatica]

Share what you learn

Understanding Treat Source Rows property and Target “Insert, Update…” properties

Posted by Ankur Nigam on August 17, 2011

Informatica has plethora of options to perform IUD (Insert, Update, Delete) operations on tables. One of the most common method is using the Update strategy, while the underdog is using Treat Source Rows set to {Insert; Update; Delete} and not data driven. I will be focusing on latter in this topic.

In simple terms when you set the Treat Source Rows property it indicates Informatica that the row has to be tagged as Insert or Update or Delete. This property coupled with target level property of allowing Insert, Update, Delete works out wonders even in absence of Update Strategy. This also leads to a clear-cut mapping design. I am not opposing the use of Update Strategy but in some situations this leads to a slight openness in the mapping wherein I don’t have to peek into the reason of action the Strategy is performing e.g. IIF(ISNULL(PK)=1,DD_INSERT,DD_UPDATE).

Lets buckle up our belts and go on a ride to understand the use of these properties.

Assume a scenario where I have following Table Structure in Stage

Keeping things simple the target table would be something like this

As you can see the target has UserID as a surrogate key which I will populate through a sequence. Also note that Username is unique.

Now I have a scenario where I have to update the existing records and insert the new ones as supplied in the staging table.

Before beginning with writing code, lets first understand TSA and target properties is more detail. Treat Source Rows accepts 4 types of settings:

  1. Insert :- When I set this option Informatica will mark all rows read from source as Insert. Means that the rows will only be inserted.
  2. Update :- When I set this option Informatica will mark all rows read from source as Update. It means that rows when arrive target they have to be updated in it.
  3. Delete :- The rows will be marked as “to be deleted” from target once having been read from Source.
  4. Data Driven :- This indicates Informatica that we are using an update strategy to indicate what has to be done with rows. So no marking will be done when rows are read from source. Infact what has to be done with rows arriving to target will be decided immediately before any IUD operation on target

However setting TSA alone will not let you modify rows in the target. Each target in itself should be able to accept or I should say allow IUD operations. So when you have set TSA property you have to also set the target level property also that whether the rows can be inserted, updated or deleted from the target. This can be done in following ways:-

Insert and delete are self-explanatory however update has been categorized into 3 sections. Please note that setting any of them will allow update on your tables:-

  1. Update as Update :- This is simple property which says that if the row arrives target, it has to be updated in target. So if you check the logs Informatica will generate an Update template something like “UPDATE INFA_TARGET_RECORDS SET EMAIL = ? WHERE USERNAME = ?”
  2. Update as Insert :- This means that when row arrives target and it is a row which has to be updated, then the update behaviour should be to insert this row in target. In this case Informatica will not generate any update template for the target instead the incoming row will be inserted using the template “INSERT INTO INFA_TARGET_RECORDS(USERID,USERNAME,EMAIL)  VALUES ( ?, ?, ?)”
  3. Update else Insert :- Means that the incoming row flagged as update should be either updated or inserted. In a nutshell it means that if any key column is present in the incoming row which also exists in target then Informatica will intelligently update that row in target. In case if the incoming key column is not present in the target the row will be inserted.

PS :- The last two properties require you to set the Insert property of target also because if this is not checked then Update as Insert & Update else Insert will not work and session will fail stating that the target does not allows Insert. Why? Well its simple because these update clauses have insert hidden in them.

Ok enough of theories? Fine … let’s get our hand dirty. Coming back to our scenario, we have the rows read from source and want them to be either inserted or updated in target depending upon the status of rows i.e. whether they are present in the target or not. My mapping looks something like this:

Here I have used a lookup table to fetch user ID for a username incoming from stage. In the router following has been set:-

The output from router is sent to respective instances of the target (INFA_TARGET_RECORDS) in case if user exists or not. INFA_TARGET_RECORDS_NEW in case of new records and INFA_TARGET_RECORDS_UPD in case of existing records.

Once this is in place I have to set the Treat Source Rows property as Update for this session. Also to enable Informatica to insert in the table I will have to :-

  1. Set the Insert & Update as Insert properties of the instance INFA_TARGET_RECORDS_NEW.
  2. Set Update as Update property for INFA_TARGET_RECORDS_UPD instance in the session.

What actually happened is that I have treated all rows from source to be flagged as update. Secondly I have modified the behaviour of the Update and set it as Update as Insert. Due to this property update has allowed me actually to insert the rows in target. When the session runs it will update the rows in target and insert the new rows in target (actually update as insert).

Try it out and let me know if it works for you. I am not attaching any run demo because its better if you do it and understand even more clearly what is happening behind the scenes.

17 Responses to “Understanding Treat Source Rows property and Target “Insert, Update…” properties”

  1. blue said

    I have used update strategy transformation with DD_DELETE.
    In Session, Treat Source Rows As is specified as ‘Data Driven’.
    For Target Level Session Property, only ‘Delete’ is checked and every other operation(Insert, Update etc. ) is unchecked.
    Monitor is showing records reaching till target, but they not getting affected (They are not getting deleted). I cant figure out why is it so. Any idea?

    • Ankur Nigam said

      Extremely sorry for late reply, I have been quite busy these days. Now back :)…Ok Can you give me some more details? It could be that you are not defining key columns which are stopping informatica to issue delete statement

  2. Suraj said

    Very well Explained……… Thanks a lot.

  3. Manu said

    Thanks a lot for posting this! Much appreciated, cheers!

  4. Chaitali said

    Hi , Thanks for the detailed explanation. Could you also throw some light on the pros and cons (performance concerns) of using “Treat Source Rows As” and Target Load Options of IUD vs keeping these setting as default and have the mapping do the work anyways because you have coded the mapping to do inserts in the designer?

    • Ankur Nigam said

      The only advantage I can think of using Treat Source Rows property is that it keeps mapping fairly simple. However using Update Strategy has its own advantage such as you can define a criteria for individual rows. Additionally you said “vs keeping these setting as default and have the mapping do the work “, which I can not understand what you actually mean.

  5. man said

    simply superb…grt!!!!

  6. kamlesh said

    very ……….good……………thanks…………….

  7. Shruti said

    nicely explained

  8. Santosh said

    superb explanation…..got a clear picture of two properties.

  9. sudher said

    well explained

  10. Kapil Sharma said

    Nice Explanation Sir………;)

  11. Jeeva said

    Hi Expert,

    Could you plz explain the below concept?

    Update Strategy transformation

    ” It is desired to run a session where every row that is processed by the session updates the target table based on the primary key value. Assume that the target table definition has a primary key, and all other session and mapping properties are left to their defaults. Select the statement below that is true”.

    I dont understand especially this line” all other session and mapping properties are left to their defaults “.Please throw some light on this..

    Choose Answer
    (A)
    The only action that is necessary is to set the Treat Source Rows As session property to Update.
    (B)
    At least one Update Strategy transformation must be present in the mapping, and the update expression condition must be written to be true for all rows that are desired to update the target table.
    (C)
    At least one Update Strategy transformation must be present in the mapping, and the update expression condition must be written to be true for all rows that are desired to update the target table, and the Treat Source Rows As session property must be set to Update.
    (D)
    At least one Update Strategy transformation must be present in the mapping, and the update expression condition must be written to be true for all rows that are desired to update the target table, and the Treat Source Rows As session property must be set to Data Driven.

  12. Sue Vogel said

    Have you seen performance decrease with using “treat source rows as update”? I have a workflow that runs in seconds with “treat source rows as insert”. When I change it to “treat source rows as update” it takes 2 minutes to run. The really odd thing is it seems to be getting hung up building the cache for a lookup before it even starts the load session. I need to update so I can’t leave it as “insert”. Other than the performance issue the “update” works as expected.

    • Ankur Nigam said

      When you set the source rows as insert you are only inserting I guess?

      Insert operations are always faster than updation. Is the lookup used for updating the data directly or indirectly?

      • Sue Vogel said

        I think I was mistaken about the lookup cache causing the problem. I think it was the next step after that. It is probably just that the updates are taking longer than the inserts.

Leave a comment