Author |
Message
|
seeknee |
Posted: Sun Apr 01, 2012 8:56 pm Post subject: SET or CREATE FIELD |
|
|
 Apprentice
Joined: 08 Aug 2002 Posts: 41 Location: Melbourne, Australia
|
Hi All
This might be a silly question but ... here goes
Which is better from a performance perspective
SET OutputRoot.XMLNSC.Field = 'Hello';
OR
CREATE FIELD OutputRoot.XMLNSC.Field VALUE 'Hello';
Both end up with the same result but which has better performance?
Many Thanks _________________ IBM Certified Specialist MQSeries
IBM Certified Specialist WebSphere MQ Integrator
IBM Certified Solution Designer WebSphere Business Integration Message Broker V5
"Good judgement comes from experience, and experience comes from poor judgement" |
|
Back to top |
|
 |
Esa |
Posted: Sun Apr 01, 2012 10:38 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
I think there is no difference in performance, but CREATE statement gives you more control.
SET OutputRoot... is as bad for perfromance as CREATE FIELD OutputRoot...
Much more important what you write after SET of CREATE FIELD.
You get well-performing code by following this simple rule of thumb: never use OutputRoot or InputRoot with any other statement than DECLARE. |
|
Back to top |
|
 |
seeknee |
Posted: Sun Apr 01, 2012 10:44 pm Post subject: |
|
|
 Apprentice
Joined: 08 Aug 2002 Posts: 41 Location: Melbourne, Australia
|
Perfect that is what I was after.
Would never use OutputRoot in the statements but just wanted to illustrate the SET or CREATE
Cheers _________________ IBM Certified Specialist MQSeries
IBM Certified Specialist WebSphere MQ Integrator
IBM Certified Solution Designer WebSphere Business Integration Message Broker V5
"Good judgement comes from experience, and experience comes from poor judgement" |
|
Back to top |
|
 |
Esa |
Posted: Sun Apr 01, 2012 10:55 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
seeknee wrote: |
Would never use OutputRoot in the statements |
I would. You know, you can always break a rule if you know why it's there  |
|
Back to top |
|
 |
mgk |
Posted: Mon Apr 02, 2012 1:15 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Just for completeness I thought I would add in a little more detail here.
CREATE FIELD when used like this:
Code: |
CREATE FIELD OutputRoot.XMLNSC.Top.Field VALUE 'Hello'; |
Will always be creating a new Field element as the lastchild of Top.
Whereas when used like this:
Code: |
SET OutputRoot.XMLNSC.Top.Field = 'Hello'; |
SET may be creating a new Field element as the lastchild of Top if there is no Field element that already exists, but if a Field element does exist it will actually just change the value of the first existing element called Field. To be able to obey these rules, SET must search all the children of Top to see if there is an element called Field in existance. And this is where a small performance difference can occur. If there are many children of Top, and none are called Field then this will take more time than simply always creating a new element as the lastchild, but this difference is very small. However, in the case where you are creating a new part of the tree from scratch, (for example no elements exist under Top) then CREATE and SET should perform the same.
Please don't assume that you should use this information to justify always using CREATE and never using SET - you shouldn't, I just wanted to explain one of the differences between the two.
I hope this helps...
Kind Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Last edited by mgk on Mon Apr 02, 2012 5:10 am; edited 1 time in total |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2012 4:18 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mgk wrote: |
I just wanted to explain one of the difference between the two. |
I for one thank you for this interesting little nugget.
 _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
rekarm01 |
Posted: Wed Apr 04, 2012 1:42 am Post subject: Re: SET or CREATE FIELD |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
mgk wrote: |
Code: |
CREATE FIELD OutputRoot.XMLNSC.Top.Field VALUE 'Hello'; |
Will always be creating a new Field element as the lastchild of Top. |
Please double-check that. A CREATE statement with one of these clauses [PREVIOUSSIBLING, NEXTSIBLING, FIRSTCHILD, or LASTCHILD] always creates a new field, but a CREATE statement with a FIELD clause does not necessarily create any fields; it ensures only that the given fields exist. So CREATE FIELD and SET should perform similarly.
One other thing ... if the SET or CREATE statement does implicitly create a new field, it's not always the last child. (The documentation doesn't actually specify where it should go):
Code: |
CALL CopyMessageHeaders();
SET OutputRoot.XMLNSC.Data.A[1] = 'a1';
SET OutputRoot.XMLNSC.Data.B[1] = 'b1';
SET OutputRoot.XMLNSC.Data.C[1] = 'c1';
SET OutputRoot.XMLNSC.Data.A[2] = 'a2';
SET OutputRoot.XMLNSC.Data.B[2] = 'b2';
SET OutputRoot.XMLNSC.Data.C[2] = 'c2';
SET OutputRoot.XMLNSC.Data.A[3] = 'a3';
SET OutputRoot.XMLNSC.Data.B[3] = 'b3';
SET OutputRoot.XMLNSC.Data.C[3] = 'c3'; |
Code: |
CALL CopyMessageHeaders();
CREATE FIELD OutputRoot.XMLNSC.Data.A[1] VALUE 'a1';
CREATE FIELD OutputRoot.XMLNSC.Data.B[1] VALUE 'b1';
CREATE FIELD OutputRoot.XMLNSC.Data.C[1] VALUE 'c1';
CREATE FIELD OutputRoot.XMLNSC.Data.A[2] VALUE 'a2';
CREATE FIELD OutputRoot.XMLNSC.Data.B[2] VALUE 'b2';
CREATE FIELD OutputRoot.XMLNSC.Data.C[2] VALUE 'c2';
CREATE FIELD OutputRoot.XMLNSC.Data.A[3] VALUE 'a3';
CREATE FIELD OutputRoot.XMLNSC.Data.B[3] VALUE 'b3';
CREATE FIELD OutputRoot.XMLNSC.Data.C[3] VALUE 'c3'; |
Both of these create XMLNSC as the LASTCHILD of OutputRoot, but do not create each of the A B C elements as the LASTCHILD of Data; if they did, then the expected order should be A B C A B C A B C, but the actual order turns out to be A A A B B B C C C.
Why is that? |
|
Back to top |
|
 |
mqsiuser |
Posted: Wed Apr 04, 2012 2:40 am Post subject: Re: SET or CREATE FIELD |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Thanks for letting us know.
rekarm01 wrote: |
Why is that? |
This might be because you (as a developer of this) will try to give/hand the most expressiveness through (to the interface-developer): If you want to create last/prev/next/first-children you'd use LAST/PREV/NEXT/FIRST CHILD... and on the "unqualified" statement you can come up with something cool (and still also useful). _________________ Just use REFERENCEs |
|
Back to top |
|
 |
mgk |
Posted: Wed Apr 04, 2012 3:37 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
How does that saying go, "post in haste, repent at leisure" Sorry for the confusion.
You're right, I was thinking of CREATE LASTCHILD... rather than CREATE FIELD. As you say, CREATE FIELD does work just like SET in that it makes sure the element exists, whereas CREATE LASTCHILD etc always creates a new element.
Quote: |
expected order should be A B C A B C A B C, but the actual order turns out to be A A A B B B C C C.
Why is that? |
SET and CREATE FIELD statements will try to navigate to the requested element and if found will change its value. If not found (and the index is not out of range), they create a new element "after the last found element" If the element does not exist at all, then the position will be at the end (lastchild).
Kind Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
|