cancel
Showing results for 
Search instead for 
Did you mean: 

SAP HANA XS batch insert with SYSUUID

Former Member
0 Kudos

Ha folks!

I have come across strange behavior of hana xs engine while writing some batch inserts using prepared command that includes calling of "sysuuid"

So, for example I have some table like


create column table "IDS"( "ID" VARCHAR (36) not null,  "COL" INTEGER null)

Then I created xs javascript file that tries to populate this table in a batch way

I pass number of records to insert from the request parameter. Roughly code looks like:


var count =  parseInt ($.request.parameters.get("count"));

var conn = $.db.getConnection();

conn.prepareStatement('delete from "IDS"').execute();

  var pstmt = conn.prepareStatement('insert into "IDS"  (id, col) values (sysuuid, ?)');

  pstmt.setBatchSize(count);

  

  for (var i = 0; i < count; ++i){

  pstmt.setString(1, i.toString());

  pstmt.addBatch();

  }

  pstmt.executeBatch();

  pstmt.close();

  conn.commit();

  conn.close();

If I execute this xs file with e.g. count=10 I will get 10 rows created, each would have "col" column value in a range of 0..9, but all "id" values will be equal

If I change prepare statement to the following:


var pstmt = conn.prepareStatement('insert into "IDS"  (id, col) select  sysuuid, ? from dummy' );

.. all "id" values will get their unique values as expected. So, it felt like in a first scenario it computed sysuuid value once and then used for every row

I would be fine with this "select .. from dummy" workaround if not the fact that this insert statement is around 10 times slower than the analog with "values". Some may think that this is due to that calling "sysuud" for every row inserted slows execution in a second scenario, but its not the case. Even by replacing sysuuid with some scalar value shows worse performance when doing "select .. from dummy" vs "values ( .. )"

Has anyone faced similar issues and solved them somehow?

I find this batch processing functions very useful for bulk data insertion as it performs really fast - I could insert millions of rows in a few seconds. But this issue with sysuuid would require coming up with some workarounds which may kill benefit of using batches.

Thanks!

Artem

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hi Artem,

I am coming cross the same scenario and my workaround is to make uuid as another parameter and use self-defined js function to generate the uuid. Hope it can help you.

Regards,
Patrick