Client-side processing

There are certain set operations that cannot be translated into SQL completely, for example a project statement with a math function or a user-defined function:

    & <- [$:sex, &:age]: f <- {
      in.{
        out :=
          sex == "male" ?
            (age <= 65 ?
              5.5 + (age - 20) * 0.2365 :
              5.5 + (65 - 20) * 0.2365 * (120.0 - age) / (120.0 - 65.0)
            )
          : // sex == "female"
            (age <= 65 ?
              6.5 + (age - 20) * 0.2365 :
              6.5 + (65 - 20) * 0.2365 * (120.0 - age) / (120.0 - 65.0)
            )
          ;
      };
   };

   {[#:id, &:npv]}: npv := project [.id, f(.sex, .age)*.pension] participants;
       

In the above example, the function f is called in a project expression. Currently, Rax cannot translate such expressions to SQL. In this case, Rax uses client-side processing: it fetches the rows of the participants set from the underlying database, executes the projection on every row and stores the result back in the database, in the npv table. Obviously, pulling all data from a database table to process it locally is slower than letting the SQL database do the computations. Such project expressions will therefore execute slower than project expressions without user-defined functions. In the future releases, Rax will be able to translate most user-defined functions into SQL, though.