-
Notifications
You must be signed in to change notification settings - Fork 0
Performance Tips
This guide provides recommendations for improving the performance of applications built with the Generic SQL API Framework.
Good SQL design and proper database optimization can significantly improve response times and reduce server load.
Always use parameters instead of concatenating SQL strings.
✅ Recommended
SELECT *
FROM CustomerTable
WHERE CustomerID = :CustomerID;❌ Avoid
SELECT *
FROM CustomerTable
WHERE CustomerID = '" + id + "';Retrieve only the columns your application requires.
✅ Recommended
SELECT
CustomerID,
CustomerName,
City
FROM CustomerTable;❌ Avoid
SELECT *
FROM CustomerTable;Returning unnecessary columns increases network traffic and memory usage.
Indexes improve query performance for frequently searched columns.
Example:
CREATE INDEX IX_Customer_City
ON CustomerTable (City);Common candidates for indexing:
- Primary Keys
- Foreign Keys
- Frequently searched columns
- Frequently sorted columns
Reduce the number of rows returned whenever possible.
Example:
SELECT
CustomerID,
CustomerName
FROM CustomerTable
WHERE Status = 'Active';Avoid retrieving the entire table when only a subset is required.
For large datasets, always use pagination.
Example:
SELECT *
FROM CustomerTable
ORDER BY CustomerID
OFFSET :Offset ROWS
FETCH NEXT :Limit ROWS ONLY;Benefits:
- Faster response times
- Lower memory usage
- Improved user experience
Join only the tables you need.
Example:
SELECT
c.CustomerName,
o.OrderNumber
FROM CustomerTable c
INNER JOIN OrderTable o
ON c.CustomerID = o.CustomerID;Avoid joining unnecessary tables.
Instead of retrieving all rows and calculating totals in your application, let SQL Server do the work.
Example:
SELECT
COUNT(*) AS TotalCustomers,
SUM(NetAmount) AS TotalSales
FROM InvoiceTable;Each SQL file should perform one specific task.
Good examples:
customers.sql
customer_details.sql
daily_sales.sql
monthly_sales.sql
Avoid creating one SQL file that performs multiple unrelated operations.
Test queries using SQL Server Management Studio before deploying them.
Review:
- Execution Time
- Execution Plan
- Index Usage
- Scan vs Seek Operations
If your application displays only 20 records, avoid requesting thousands of rows.
Use:
- Pagination
- Filters
- Search conditions
Frequently used reference data can be cached by the application instead of querying the database repeatedly.
Examples:
- Countries
- States
- Product Categories
- Tax Rates
Note: Caching support is planned for a future version of the framework.
A well-structured query directory improves maintainability.
Example:
queries/
customers/
orders/
reports/
inventory/
dashboard/
Before deploying a query, verify:
- Only required columns are selected.
- Appropriate indexes exist.
- Pagination is implemented where needed.
- Parameters are used.
- Unnecessary joins are removed.
- SQL has been tested in SQL Server Management Studio.
- Execution time is acceptable.
- Write clear and efficient SQL.
- Keep queries simple and maintainable.
- Test performance with realistic datasets.
- Monitor database performance regularly.
- Review execution plans for complex queries.
Continue with:
- Security Best Practices
- Framework Architecture
- Contributing
- Frequently Asked Questions