Thu Dec 09, 2021 12:13 am
Login Register Lost Password? Contact Us


PROJECT vs. ROW

Questions around writing code and queries

Thu Jul 07, 2011 10:34 pm Change Time Zone

The definitions for PROJECT and ROW are as follows:

"The PROJECT function processes through all records in the recordset performing the transform function on each record in turn."

"The ROW function creates a single data record and is valid for use in any expression where a single record is valid."

So PROJECT is used to transform recordsets and ROW is used to transform a single record, correct? Is there ever a condition when using either ROW or PROJECT is a viable option? If so, which is better?
champirs
 
Posts: 5
Joined: Fri May 13, 2011 8:10 pm

Fri Jul 08, 2011 12:36 am Change Time Zone

The simple answer is 'yes'. It is fairly each to convert a row into a dataset with a single record and to convert a dataset with a single record into a row. Therefore you nearly always have the option of one or the other.

In terms of 'which is better' - there is a simple rule of thumb for this (and most of ECL) - which is 'tell the truth'. If what you are trying to do is transform one dataset into another - use a project; if what you are trying to do is build a row - then use ROW.

Possibly the easiest test is: "which one requires least code" - that is typically the method where you are telling the most truth.

HTH

David
dabayliss
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 109
Joined: Fri Apr 29, 2011 1:35 pm

Fri Jul 08, 2011 6:12 am Change Time Zone

To reinforce David's comments, so long as what you have coded is not so complicated that the code generator cannot recognise it, it will transform what you wrote into the most efficient alternative prior to generation. Thus you are usually better off writing simple ECL that the code-generator (and your fellow ECL coders) can understand more easily, than trying to second-guess the compiler by substituting a more obscure construct that you think might go faster.

Because the ECL expressions that the code generator is trying to optimize are side-effect free, the range of optimizations and transformations that it can (and does) apply without changing the result is pretty large.

Richard
richardkchapman
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 110
Joined: Fri Jun 17, 2011 8:59 am

Tue Jul 12, 2011 7:26 pm Change Time Zone

It does help - thanks so much. I just wasn't sure if there would be a negative impact in either case. I agree with your 'tell the truth' logic. That also makes it much easier on maintenance!
champirs
 
Posts: 5
Joined: Fri May 13, 2011 8:10 pm

Tue Jul 12, 2011 7:28 pm Change Time Zone

I see what you mean, Richard. I am not used to a compiler being that intuitive. So that does make me feel better from the code side. I just want to be as efficient as possible - you and David have certainly helped in that direction.

Thanks again!

Becky
champirs
 
Posts: 5
Joined: Fri May 13, 2011 8:10 pm


Return to Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron