Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
SQL

SQL: Use Indexing for Query Performance

- 12.07.26 - ErcanOPAK

⚡ Indexing = Query Performance

Slow queries kill performance. Indexing speeds up data access. Find data fast, optimize queries.

📝 Index Types

# B-Tree Index (default)
CREATE INDEX idx_users_email ON users(email);

# Unique Index
CREATE UNIQUE INDEX idx_users_email ON users(email);

# Composite Index
CREATE INDEX idx_users_name_email ON users(name, email);

# Full-Text Index
CREATE FULLTEXT INDEX idx_articles_content ON articles(content);

# Index on Expression
CREATE INDEX idx_users_upper_name ON users(UPPER(name));

# Filtered Index
CREATE INDEX idx_users_active ON users(email)
WHERE status = 'active';

# Covering Index
CREATE INDEX idx_users_covering ON users(email)
INCLUDE (name, created_at);

🎯 Index Strategies

# When to Index
- WHERE clauses
- JOIN columns
- ORDER BY columns
- GROUP BY columns

# Find missing indexes
SELECT 
    migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) AS improvement_measure,
    'CREATE INDEX [missing_index_' + CONVERT(VARCHAR, mig.group_handle) + '_' + CONVERT(VARCHAR, digest.index_handle) + '_' + LEFT(PARSENAME(mid.statement, 1), 32) + '] ON ' + mid.statement + ' (' + ISNULL(mid.equality_columns, '') + CASE WHEN mid.equality_columns IS NOT NULL AND mid.inequality_columns IS NOT NULL THEN ',' ELSE '' END + ISNULL(mid.inequality_columns, '') + ')' + ISNULL(' INCLUDE (' + mid.included_columns + ')', '') AS create_index_statement
FROM sys.dm_db_missing_index_groups mig
INNER JOIN sys.dm_db_missing_index_group_stats migs ON migs.group_handle = mig.group_handle
INNER JOIN sys.dm_db_missing_index_details mid ON mig.index_handle = mid.index_handle
WHERE mid.database_id = DB_ID()
ORDER BY improvement_measure DESC;

# View query plan
EXPLAIN SELECT * FROM users WHERE email = 'test@example.com';

# Index maintenance
ALTER INDEX ALL ON users REBUILD;
ALTER INDEX idx_users_email ON users REORGANIZE;

✅ Index Tips

  • Index columns used in WHERE and JOIN
  • Avoid over-indexing (slows INSERT/UPDATE)
  • Use composite indexes for multiple columns
  • Monitor index usage
  • Rebuild indexes periodically

“Indexing speeds up queries. Find data fast, optimize performance. Essential for database performance.”

— DBA

Related posts:

SQL Execution Plan Reuse: Boost Query Performance with Plan Caching

SQL Execution Plan Reuse: Boost Query Performance with Plan Caching

SQL: Identifying and Preventing Deadlocks in High-Concurrency Systems

SQL: Identifying and Preventing Deadlocks in High-Concurrency Systems

SQL: Use CHAR Instead of VARCHAR for Fixed-Length Columns to Save Space

SQL: Use CHAR Instead of VARCHAR for Fixed-Length Columns to Save Space

Views: 6

Post navigation

.NET Core: Build Background Tasks with Worker Services
C#: Use ValueTuples for Multiple Return Values

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com