HANA SQLScript Dream Team

Is there an equivalent to Sleep(1000) in HANA SQLScript?

I don’t see anything in the HANA SQLScript reference, so I wonder if there can be a creative workaround that will not bind the processor 100%.

+5
source share
1 answer

HANA does not support anything like this. There are two approaches that I can think of if you absolutely MUST have this

Waiting waiting

As already suggested on SCN , you can create a procedure that gets stuck in a while loop until a certain time threshold is reached, Mr. Amid Das suggested the following:

 CREATE PROCEDURE PLEASE_SLEEP ( IN SLEEPING_TIME INTEGER, OUT WOKE_UP_AT TIME ) LANGUAGE SQLSCRIPT READS SQL DATA AS V_TIME TIME; V_TIME_TO_WAKE TIME; BEGIN V_TIME := CURRENT_TIME; V_TIME_TO_WAKE < ADD_SECONDS ( TO_TIME( V_TIME ), SLEEPING_TIME ); WHILE V_TIME != V_TIME_TO_WAKE DO V_TIME := CURRENT_TIME ; END WHILE; WOKE_UP_AT := V_TIME_TO_WAKE ; END 

I'm not sure how much CPU usage will be, but it is definitely not the best.

Using table lock timeouts

This idea is a little crazy and complicated, but it can just work without sacrificing too much processor power.

The only SQL command that can wait is LOCK TABLE . This command will be disabled after a certain time if a table lock cannot be obtained. This timeout can be set using SET TRANSACTION LOCK WAIT TIMEOUT [number of milliseconds] .

Now we need a table that can be locked by the procedure, as well as the other transaction, which keeps this table locked. This is the hard part. What might work is to use the XS Engine to schedule a continuous XS Job that will keep the specified table locked for as long as possible. Alternatively, you can write a Python script that will lock the table.

This idea is very experimental, and I have not tried it myself. But I believe that it should work if everything is configured correctly.

+5
source

Source: https://habr.com/ru/post/1209284/


All Articles