Snowflake stored procedure parallel execution - stored-procedures

I want to execute a single instance of Snowflake stored procedure by using Snowflake code only. Trying not to use tasks as it has external dependencies.
Just by code. Throwing all stored procedure instances in parallel.
For example SP_INSERT_WORDS(VARCHAR) is a stored procedure and I want to call multiple instances of the same stored procedure.
SP_INSERT_WORDS('A');
SP_INSERT_WORDS('B');
SP_INSERT_WORDS('C');
. . .
SP_INSERT_WORDS('Z');

You can try the below options
Use the RESULTS option in SnowSQL.
!set results=False;
This option avoids the wait on the previous calls and asynchronously execute queries
Task execution may be viable, however it is unidirectional
Parallel calls from the application
Link on restrictions for Stored Procedures
https://docs.snowflake.com/en/sql-reference/stored-procedures-usage.html#restrictions-on-stored-procedures

Related

Is there a way to parallelerise the execution of stored procedures in snowflake

We have a master stored procedure that loops through a table and for each row calls a stored procedure based on data from that table. There is likely to be a lot of rows and so we are worried about the the master stored procedure timing out due to the time it would take to loop through all of the rows.
The stored procedures called do not have a dependency on each other so we would like to speed up the process by executing the stored procedures without waiting for the previous one to finish. Is there a way to achieve this in snowflake?
Javascript stored procedures are single-threaded so there is no way to get them to run parts of their code in parallel.
You might be able to improve performance by changing your design, for example by running instances of the SP via tasks as you can get tasks to run in parallel
We have a master stored procedure that loops through a table and for each row calls a stored procedure based on data from that table.
Having one stored procedure call others will be single threaded. You can do this instead:
Create a task for each of your child stored procedures. Set its schedule to 1 minute; specify no overlapping execution, and do not enable it.
Have your main stored procedure read from the table that drives it.
Instead of having your main stored procedure call other stored procedures, have it alter their tasks to resume them.
The first thing each child stored procedure should do is to run a SQL statement to alter their task disabling it.
This will allow asynchronous, parallel execution. The main stored procedure just needs to figure out what other stored procedures do or don't need to run and what their call parameters should be. It kicks off their execution by enabling the schedule for their task and moves on to the next code statement. A minute later, the child stored procedure starts and disables its schedule so when it completes it won't run again until the main stored procedure alters its task back to enabled.
Your task create statements for the child stored procedures should be something like this:
create or replace task MY_SP_TASK
warehouse = 'MY_WAREHOUSE'
schedule = '1 MINUTE '
allow_overlapping_execution = false
as
call MY_SP('PARAM1', 'PARAM2')
If you need the main stored procedure to change the parameters in the call, you can have the main stored procedure run the "create or replace task" and change them. You'll then want to enable the task:
alter task MY_SP_TASK resume;
If you don't need to change the child's call parameters, you can just run the alter statement to resume it and that's all. Then on the child stored procedure among the first things the code should do is disable its own taskL
alter task MY_SP_TASK suspend;

Oracle stored procedure sight

I'm curious about a nested procedures sight. I have a procedure, Proc1 whichs accepts a C# modelled UDT which is defined at schema level.
Proc2 - insert: (called from inside Proc1) identifies records that are in the UDT but not in a table and creates new records.
Proc3 - update: (called from inside Proc1)
Would this proc be able to see (have sight) of the newly created records from Proc2? IE, is there a "commit" when proc2 finishes?
Proc4 - delete (call from inside Proc1) deletes all properly identified records.
There are no implicit commits when a procedure finishes. But since all procedures in the same call stack are part of the same transaction, they will inherently be part of the same transaction scope (I ignore the possibility that you have defined one of your procedures to use an autonomous transaction and I assume you aren't explicitly ending a transaction by issuing an explicit commit or rollback). So each procedure will see the uncommitted results of all the code run earlier in the same session.

Avoiding hard coding Schema in DB2/400 Stored Procedure

I'm creating Stored Procedures to replace Legacy app programs for an IBM i. I'm calling the stored procedure from a Java Web App. I'm using the jt400 JDBC driver
My JDBC URL is jdbc:as400://myhost/;libraries=*LIBL,MYLIB;prompt=false
The stored procedures can call stored procedures
The initial stored procedure call completes normally if it does not make further stored procedure calls
If the stored procedure makes a call to other stored procedures it fails with
com.ibm.as400.access.AS400JDBCSQLSyntaxErrorException: [SQL0204] MY_SP in MYLIB type *N not found.
If I hard code a schema in the stored procedure call statement, the call completes normally.
I want to have the called stored procedures use the same schema as the caller
You need to SET PATH = "MYLIB"
When I am using SQuirreL to call a stored procedure, I need to use the SET PATH statement to get it to find the stored procedure. I don't know if that is because my library list is bad or what, but the current schema is not used to find an unqualified stored procedure.
I actually had this same problem, the stored procedure uses your job description library list. You need to edit that you can use TAATOOL CHGLBLJOBD. I am not in front of an iSeries at the moment but I believe the command was either EDTJOBDLIB or EDTJOBDLIBL WRKJOBDLIBL. It is some variation of that.

derby procedure that does not modify

I'm trying to create a trigger on derby which simply calls a procedure. The stored procedure does not change anything and gets no parameters. It simply check that the time is within an interval (for example between 08:00 and 16:00). On creation of trigger i receive the following error:
"42Z9D: Procedures that modify SQL data are not allowed in BEFORE triggers."
But the procedure makes no changes.
When defining a procedure one should specify if the procedure modifies data or not. If it executes any sql or not. As mentioned in the link provided above by Bryan I should use one the options:
{ NO SQL | MODIFIES SQL DATA | CONTAINS SQL | READS SQL DATA }
If you dont use this options the default value will be assumed that is CONTAINS SQL.

Value Displays when Running Stored Procedure in SSMS but not in SSRS

I have a stored procedure that uses table variables to create a query and runs perfectly when executing in SQL Server Management Studio. However, the column referring to this table variable does not display when running the stored procedure in Query Designer.
I have used this method on many other reports without issue, but cannot figure out why the value will display in SSMS and not in SSRS.
After a fresh nights sleep, I realized it was how a parameter was being passed to the Sub Stored Procedures. The main stored procedure had a where clause that contained a "LIKE #Parameter" but the Sub Stored Procedure contained an "= #Parameter", so when a "%" was passed into the parameter the main Stored Procedure returned results, but nothing was displayed from the Sub Stored Procedure.
Simply just a case of making my job harder on myself...

Resources