Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
639 views
in Technique[技术] by (71.8m points)

stored procedures - Are Javascript for loops faster than while loops when dealing with DB transactions?

I know that the discussion of whether while loops and for loops are faster is very popular, but I haven't seen any with this particular question.

I am currently developing stored procedures in Snowflake. These SPs use Javascript to handle the logic. I have the need to create some loops to run several (potentially thousands) SQL queries so I was wondering which could be the best approach for performance and safety.

I am worried about using while loops because it seems to me that it would be slower if the condition to evaluate was dependent on the result of a transaction, because the JS thread would need to stop to wait for the Snowflake query to return data in order to evaluate it again, whereas a normal for loop would just increment/decrement the counter and evaluate from inside the JS thread without needing to wait for a new set of results.

Which also leads me to a new questions: If this is true, would it mean that a while loop is safer since the for loop has the chance of becoming losing sync (in regards to the results obtained from Snowflake)?

I am not saying that this is the way things happen, rather, I'm just trying to confirm if this is actually how it goes or if I'm wrong. As I said I could not find many related resources to this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...