问题
I am thinking to create denormalized table for our BI purpose.
While creating business logic from several tables i noticed queries perform better when denormalized table is updated in batches(sproc with multiple business logic SQL's) with merge statement as below.
eg: sproc contains multiple SQL's like
- merge denormalized_data (select businesslogic1)
- merge denormalized_data (select businesslogic2)
etc
Is it better to include business logic in huge SQL or divide it so that each query handles less number of rows?
Is there any overhead if I use sproc?
回答1:
Speaking very generally. Snowflake is optimized to work in large batches. For example, I've had cases where it takes about as long to insert 1 record as 100,000 records. So inserting 1 record 100,000 times is a LOT slower.
There is certainly going to be some limit. A 1TB batch should be split up. And your mileage may vary depending on how/when/etc. you are updating the table. In general though, you'll find batches are more performant.
The only real overhead that I know of for procedures has to do with converting data types from SQL to Javascript and back again, and then how you have to manage the output. In most cases, this won't be significant.
来源:https://stackoverflow.com/questions/59147564/snowflake-sproc-vs-standalone-sql