tags / Performance

Performance tips and tricks

How to Build a SQL Query

Need to retrieve data from a database?

A typical SQL query consists of these clauses:

  • SELECT to choose columns
  • FROM to specify the table
  • JOIN to combine related tables
  • WHERE to filter rows
  • GROUP BY to group results
  • HAVING to filter groups
  • ORDER BY to sort data
  • OFFSET / FETCH or LIMIT to paginate

Not every query needs every clause, but this is the structure you'll see in most SQL statements.

How to Build a SQL Query

Understanding what each clause does makes reading and writing SQL much easier.

How to Increase Throughput

Consider parallel execution.

Common approaches:

  • Use Task.WhenAll()
  • Process independent tasks concurrently
  • Increase consumer instances
  • Batch operations when possible
  • Remove unnecessary bottlenecks

Parallel processing allows multiple operations to run at the same time rather than waiting for each to finish.

For example:

  • 10 API calls executed sequentially may take 10 seconds
  • 10 API calls executed in parallel may take around 1 second

Of course, parallelism isn't free. Databases, external APIs, and infrastructure still have limits.

But if your workload is independent, parallel execution is often one of the simplest ways to increase throughput.

What was the biggest throughput improvement you've achieved?

How to Increase Throughput

How to Speed Up SQL Queries

Queries running slowly?

Consider adding an index.

How to Speed Up SQL Queries

Indexes help SQL Server:

  • Find data faster
  • Reduce table scans
  • Improve filtering performance
  • Improve sorting performance
  • Improve join performance

Not every column needs an index, but columns used in WHERE clauses often benefit from one.

What is your favorite indexing strategy?

How to Use SaveChangesAsync in .NET

Want asynchronous database writes in EF Core?

Use SaveChangesAsync() instead of SaveChanges().

How to Use SaveChangesAsync in .NET

Benefits:

  • Doesn't block the calling thread
  • Works better under load
  • Integrates with async/await
  • Recommended for ASP.NET Core applications
  • Available since EF Core was released

What other EF Core performance tips do you use?