Skip to Content
author's profile photo Former Member
Former Member

Run HANA Stored procedure in parallel

Dear all,

I have created a stored procedure in HANA which will select the parameter "Property" into an array, iterate over this array and call a second stored procedure ("pattern_Identification") with the parameter "Property" as input parameter. As I have around 20 different "Property" parameters the procedure "pattern_Identification" is called several times sequential and makes the whole process slowly. That's why I would like to parallelize the process.

Please let me know how I can use HANA capability to call this stored procedure parallelly ?



PROCEDURE "MY_SYSTEM"."My_Project.procedures::run_Pattern_Identification" ( 
  IN personID ALPHANUM(10)
  DECLARE property_Array VARCHAR(50) ARRAY;
  DECLARE a_Length INT;
  DECLARE a_Index INT;
  DECLARE property VARCHAR(50);

  property_Array := ARRAY_AGG(:property_Tab.PROPERTY);
  a_Length := CARDINALITY(:property_Array);

  FOR a_Index IN 2 .. a_Length DO
  property := :property_Array[:a_Index];
  CALL "test_Project.procedures::pattern_Identification"(:property);           -- Call could be parallelly

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Sep 18, 2015 at 09:31 AM

    Hi Matthias,

    You can follow below steps to run these procedures parallelize.

    1> Combine the data of Array into a string by storing Property names as comma separated. Use below codes

    DECLARE v_property VARCHAR(300);

    FOR a_index IN 1..a_Length DO

    IF a_index<a_Length THEN

    v_property:= :v_property||:property_array[:a_index]||','


    v_property:= :v_property||:property_array[:a_index]


    END FOR;

    2>Now change the input parameter of inner procedure as IN <paramter_name >VARCHAR(300)

    and call the procedure making v_property as input paremeter.

    CALL "test_Project.procedures::pattern_Identification"(:v_property);

    3>Inside this pattern_identification procedure split this string into the array and use the data of the array in the logic so procedures will run just like parallel process.

    Let me know in case any issue.



    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Matthias,

      I know I am a bit late in this discussion, but it stuck to the back of my mind.

      The main question is of course: why the procedure calls at all?

      Looking at what happens in the procedures I figured it's this:

      - find all different properties that had been collected so far

      - for each of the properties

      - find all days with discomfort PLUS the 5 days before that day

      - for every day

      - read the date and the value of the current property (if available on this date)

      - store the result in a table

      That's definitively doable in a single SQL statement:

      select row_number() over(partition by order by desc ) sequence_id
             , as "eventID"
             ,   day_before
             ,   prop."VALUE"
          (select dc."DATE",, add_days(dc."DATE", as day_before 
           from discomfort_t dc
                cross join (select  0 as off from dummy union all
                           select -1 as off from dummy union all
                           select -2 as off from dummy union all
                           select -3 as off from dummy union all
                           select -4 as off from dummy union all
                           select -5 as off from dummy) date_range) dates
          inner join 
                  (select "DATE",  property, "VALUE" from environmental_data) prop
           on dates.day_before = prop."DATE"
      order by asc,  "eventID" desc

      The dates "union"-sub-select generates the date offsets you are looking for.

      This gets joined with the dates of days of discomfort.

      We now have a list of dates of discomfort and the five days before that.

      This then gets joined with all the measures properties and values.

      Finally the row_number() produces the "sequence_id" starting new with every date of day of discomfort.

      I don't have any test data of reasonable size but I don't see why this shouldn't be quicker then the two procedure approach...



      So, now

  • Posted on Sep 18, 2015 at 09:09 AM

    Moved to proper space: SAP HANA Developer Center

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.