On this page
dotConnect for Snowflake communicates with the Snowflake cloud service over HTTPS. Snowflake uses virtual warehouses to execute queries that require compute resources, consuming credits while the warehouses are running.
This topic describes how to improve application performance by reducing the number of requests, minimizing data transfer, and optimizing warehouse usage.
Reuse Connections
Opening a new connection requires authentication and session creation. Connection pooling eliminates this overhead by reusing existing sessions.
Keep connection pooling enabled (the default), open connections only when needed, and close them as soon as you're finished using them to return them to the pool.
- To keep sessions available for initial application requests, specify the Min Pool Size connection string parameter.
- To apply session settings each time a connection opens, use the Initialization Command connection string parameter instead of executing ALTER SESSION after each call to Open.
- Use identical connection strings for connections that can share a pool. The provider maintains a separate pool for each distinct connection string.
For more information, see Sessions and Connection Pooling.
Reduce the Number of Requests
Each SQL statement requires a separate request to Snowflake, introducing network latency even for simple operations. To reduce the number of requests, use set-based operations instead of processing individual rows:
- Insert multiple rows using a single INSERT statement with multiple rows in the VALUES clause, or use INSERT ... SELECT to copy rows from another table. The VALUES clause doesn't accept functions such as PARSE_JSON: to insert several rows with semi-structured values, use INSERT ... SELECT with UNION ALL, for example, INSERT INTO EVENTS (ID, PAYLOAD) SELECT 1, PARSE_JSON('{"a": 1}') UNION ALL SELECT 2, PARSE_JSON('[1, 2]'). For more information, see Working with Semi-Structured Data.
- Update or delete multiple rows using an UPDATE or DELETE statement with a WHERE clause, or use MERGE to combine data modification operations.
- Use set-based statements for large-scale data modifications and bulk loaders for large data inserts. Batch updates aren't supported: the Update method of a data adapter executes a separate statement for each modified row, and Entity Framework Core executes a separate statement for each added, modified, or deleted entity.
Load Large Amounts of Data
For efficient bulk data loading, use the loader classes instead of executing individual INSERT statements. The loaders upload data files to a Snowflake stage and load each batch using a single COPY INTO statement. This approach reduces the number of requests and improves data loading performance.
For more information, see Bulk Data Loading.
Retrieve Only the Data You Need
Reduce the amount of data Snowflake processes and transfers to your application:
- Select only the required columns instead of using SELECT *. Snowflake uses columnar storage, so selecting fewer columns can reduce the amount of data scanned and transferred.
- Filter and aggregate data on the server rather than in the application. Use LIMIT to restrict the number of rows returned.
- Close the data reader as soon as you've retrieved the required rows. Snowflake returns large result sets in chunks, and the provider downloads additional chunks as you read the rows.
- Take advantage of Snowflake's persisted query results. Snowflake caches query results for 24 hours and can reuse them without warehouse compute resources when the same query meets the requirements for result reuse.
Manage Warehouse Usage
Snowflake executes queries that require compute resources using the warehouse specified in the Warehouse connection string parameter or the user's default warehouse.
Snowflake bills warehouse usage per second, with a minimum of 60 seconds each time a warehouse starts. To balance query performance and compute costs, consider the following:
- Configure the AUTO_SUSPEND and AUTO_RESUME warehouse properties based on your application's query frequency. When automatic resumption is enabled, the first query after suspension must wait for the warehouse to resume. Increasing the auto-suspend interval can reduce this delay but increases credit consumption during periods of inactivity.
- Choose a warehouse size that matches your workload. Larger warehouses can improve the performance of complex queries but consume more credits per second. Simple queries might not benefit from additional compute resources.
- Use separate warehouses for different workloads, such as reporting and data loading. Specify the appropriate warehouse in each connection string.
Monitor Query Performance
Use the following tools to monitor SQL execution and identify performance issues:
- Use dbMonitor to monitor SQL statements executed by the application and their execution times.
- In Snowsight, go to Monitoring > Query History to review query execution times, warehouses, and query profiles.
To identify queries executed by a specific application, set the QUERY_TAG session parameter using the Initialization Command connection string parameter. The tag is stored in the query history, so you can find the queries of the application by it.