Skip to content

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

Tag: database

SQL

SQL: Writing Readable Queries with Common Table Expressions (CTE)

- 01.03.26 - ErcanOPAK comment on SQL: Writing Readable Queries with Common Table Expressions (CTE)

Stop nesting subqueries. It makes SQL unreadable. Use WITH. WITH MonthlySales AS ( SELECT Month, SUM(Amount) as Total FROM Sales GROUP BY Month ) SELECT * FROM MonthlySales WHERE Total > 10000; It reads like a story from top to bottom, making it much easier for your team to maintain.

Read More
Wordpress

WordPress: Finding the Plugin That’s Slowing You Down

- 01.03.26 - ErcanOPAK comment on WordPress: Finding the Plugin That’s Slowing You Down

Is your admin dashboard crawling? You don’t need a new host; you need the Query Monitor plugin. What it exposes: Database queries triggered by each plugin. Slow API calls to external services. PHP errors and warnings hidden in the background. Once installed, look at the top bar. It will turn red if a query takes […]

Read More
SQL

SQL: Identifying and Resolving Deadlocks in High-Concurrency DBs

- 01.03.26 - ErcanOPAK comment on SQL: Identifying and Resolving Deadlocks in High-Concurrency DBs

A Deadlock occurs when Task A waits for Task B, and Task B waits for Task A. The DB kills one to save the other. Prevention Strategy Implementation Access Order Always update Table A then B, never mix. Snapshot Isolation READ_COMMITTED_SNAPSHOT ON. Use DBCC TRACEON (1222, -1) to capture detailed deadlock graphs in the error […]

Read More
Wordpress

WordPress: Fixing the ‘Slow wp_options’ Query with Custom Indexing

- 01.03.26 - ErcanOPAK comment on WordPress: Fixing the ‘Slow wp_options’ Query with Custom Indexing

In massive sites, the wp_options table becomes a bottleneck because autoload columns aren’t always indexed efficiently. The Fix: Running this SQL command can shave milliseconds off every single page load by helping MySQL find autoloaded options faster: CREATE INDEX autoloadindex ON wp_options (autoload, option_name); This is a low-level optimization that even ‘Premium’ caching plugins often […]

Read More
SQL

SQL: Querying NoSQL Data Inside Relational SQL Server

- 01.03.26 - ErcanOPAK comment on SQL: Querying NoSQL Data Inside Relational SQL Server

Storing JSON in a NVARCHAR(MAX) column? You can query it just like a table using JSON_VALUE and OPENJSON. SELECT Name, JSON_VALUE(LogData, ‘$.IP’) as LoginIP FROM Logs WHERE JSON_VALUE(LogData, ‘$.Status’) = ‘Failed’; This provides the flexibility of NoSQL with the strict ACID compliance of SQL Server. Best of both worlds.

Read More
SQL

SQL: Calculating Running Totals with the OVER() Clause

- 28.02.26 - ErcanOPAK comment on SQL: Calculating Running Totals with the OVER() Clause

Before Window Functions, calculating a running total required a complex self-join. Now, it’s a one-liner. SELECT OrderDate, Amount, SUM(Amount) OVER (ORDER BY OrderDate) as RunningTotal FROM Sales; Why? It’s significantly faster because the database only scans the table once (O(N) vs O(N^2)).

Read More
SQL

SQL: Making Complex Queries Readable with Common Table Expressions (CTE)

- 28.02.26 - ErcanOPAK comment on SQL: Making Complex Queries Readable with Common Table Expressions (CTE)

Subqueries are hard to read and debug. CTEs allow you to create ‘Virtual Results’ that you can reference easily. WITH HighValueSales AS ( SELECT * FROM Sales WHERE Amount > 1000 ) SELECT p.ProductName, hvs.Amount FROM HighValueSales hvs JOIN Products p ON hvs.ProductId = p.Id;

Read More
C#

C# LINQ: The Performance Traps That Cost Us 90% Speed (And How to Fix Them)

- 23.02.26 | 23.02.26 - ErcanOPAK comment on C# LINQ: The Performance Traps That Cost Us 90% Speed (And How to Fix Them)

🐌 The LINQ That Killed Performance Beautifully expressive LINQ. Slow as molasses. Your elegant code processes 1000 items in 8 seconds. Production is on fire. The 3 Deadly LINQ Mistakes πŸ’£ Mistake #1: Multiple Enumeration ❌ SLOW (database hit 3 times!) var query = dbContext.Users.Where(u => u.IsActive); var count = query.Count(); // DB hit #1 […]

Read More
SQL

SQL: Use UNION ALL Instead of UNION When Duplicates Don’t Matter

- 22.02.26 | 22.02.26 - ErcanOPAK comment on SQL: Use UNION ALL Instead of UNION When Duplicates Don’t Matter

UNION removes duplicates (expensive operation). UNION ALL keeps them (fast). UNION (Slow): SELECT Name FROM ActiveUsers UNION SELECT Name FROM InactiveUsers; — Removes duplicates: Sorts, scans, filters — Slow on large datasets! UNION ALL (Fast): SELECT Name FROM ActiveUsers UNION ALL SELECT Name FROM InactiveUsers; — Keeps duplicates: No sorting or filtering — Much faster! […]

Read More
AI

AI Prompt: Optimize SQL Queries with Execution Plan Analysis

- 22.02.26 - ErcanOPAK comment on AI Prompt: Optimize SQL Queries with Execution Plan Analysis

Slow query but don’t know why? AI analyzes execution plans and suggests optimizations. The Prompt: Optimize this SQL query: [Paste SQL query] Execution plan shows: [Paste execution plan or describe bottleneck] Database: [PostgreSQL/MySQL/SQL Server] Table row counts: [Approximate sizes] Provide: 1. Identified performance issues 2. Optimized query with explanation 3. Index recommendations 4. Query rewrite […]

Read More
SQL

SQL Server: Querying JSON Columns Like a Pro

- 21.02.26 - ErcanOPAK comment on SQL Server: Querying JSON Columns Like a Pro

Modern SQL Server can handle NoSQL-style JSON data. Stop serializing/deserializing in C#; do it in SQL! SELECT JSON_VALUE(LogData, ‘$.Browser’) as Browser FROM WebLogs WHERE JSON_VALUE(LogData, ‘$.Status’) = ‘Error’

Read More
Wordpress

WordPress: Manage Your Entire Site from the Terminal with WP-CLI

- 21.02.26 - ErcanOPAK comment on WordPress: Manage Your Entire Site from the Terminal with WP-CLI

Why use a slow GUI when you can update 50 plugins in 2 seconds? # Update everything at once wp core update && wp plugin update –all # Regenerate all thumbnails wp media regenerate –yes ⚠️ Warning: Always take a snapshot with wp db export before running bulk commands!

Read More
SQL

SQL: Use CTEs (Common Table Expressions) for Readable Queries

- 21.02.26 - ErcanOPAK comment on SQL: Use CTEs (Common Table Expressions) for Readable Queries

Stop using complex subqueries. CTEs make your SQL look like clean code. WITH MonthlySales AS ( SELECT ProductId, SUM(Amount) as Total FROM Sales GROUP BY ProductId ) SELECT * FROM MonthlySales WHERE Total > 1000;

Read More
Asp.Net Core

.NET Core: Use Dapper for Lightweight ORM Alternative to Entity Framework

- 16.02.26 - ErcanOPAK comment on .NET Core: Use Dapper for Lightweight ORM Alternative to Entity Framework

Entity Framework too heavy for simple queries? Dapper is micro-ORM with near-raw SQL performance. Install: dotnet add package Dapper Basic Usage: using Dapper; using System.Data.SqlClient; var connection = new SqlConnection(connectionString); // Query (returns list) var users = connection.Query( “SELECT * FROM Users WHERE Age > @MinAge”, new { MinAge = 18 } ).ToList(); // Single […]

Read More
AI

AI Prompt: Generate Database Schema from Description

- 16.02.26 - ErcanOPAK comment on AI Prompt: Generate Database Schema from Description

Designing database schema takes hours. AI creates normalized schema with relationships instantly. The Prompt: Design database schema for: [Describe your application] Requirements: 1. Normalized (3NF minimum) 2. Include primary keys, foreign keys 3. Add indexes for common queries 4. Specify data types (be specific) 5. Add constraints (NOT NULL, UNIQUE, etc.) 6. Show relationships (1:1, […]

Read More
SQL

SQL: Use COALESCE to Replace NULL Values Inline

- 13.02.26 - ErcanOPAK comment on SQL: Use COALESCE to Replace NULL Values Inline

Don’t use CASE WHEN for simple NULL checks. COALESCE is cleaner. Verbose Way: SELECT CASE WHEN Name IS NULL THEN ‘Unknown’ ELSE Name END AS Name FROM Users; Clean Way: SELECT COALESCE(Name, ‘Unknown’) AS Name FROM Users; Multiple Fallbacks: SELECT COALESCE(MobilePhone, WorkPhone, HomePhone, ‘No phone’) AS Phone FROM Users; Returns first non-NULL value.

Read More
Docker

Docker Compose: Launch Full Stack Apps with One Command (Node + Redis + Postgres)

- 05.02.26 - ErcanOPAK comment on Docker Compose: Launch Full Stack Apps with One Command (Node + Redis + Postgres)

Manually starting 5 different services for development? Docker Compose defines and runs multi-container apps. # docker-compose.yml version: ‘3.8’ services: # Node.js API api: build: ./api ports: – “3000:3000” environment: – NODE_ENV=development – REDIS_URL=redis://redis:6379 – DATABASE_URL=postgresql://user:pass@db:5432/mydb volumes: – ./api:/app – /app/node_modules depends_on: – redis – db command: npm run dev # React Frontend frontend: build: ./frontend […]

Read More
SQL

SQL Server Indexing Secret: How Covered Indexes Can Make Queries 100x Faster

- 05.02.26 - ErcanOPAK comment on SQL Server Indexing Secret: How Covered Indexes Can Make Queries 100x Faster

Your SQL queries running slow even with indexes? Discover how covered indexes eliminate key lookups and dramatically improve performance. The Problem: Non-Covered Index — Table structure CREATE TABLE Orders ( Id INT PRIMARY KEY, CustomerId INT, OrderDate DATETIME, TotalAmount DECIMAL(10,2), Status VARCHAR(50), ShippingAddress NVARCHAR(500), — 20 more columns… ); — Common query SELECT CustomerId, OrderDate, […]

Read More
C#

C# LINQ Performance Secret: How ToQueryString() Can Reduce Database Calls by 90%

- 05.02.26 - ErcanOPAK comment on C# LINQ Performance Secret: How ToQueryString() Can Reduce Database Calls by 90%

Are your Entity Framework queries making too many database trips? Discover how IQueryable.ToString() reveals the actual SQL and helps you batch queries efficiently. The Hidden Debugging Gem: // Instead of this naive approach (multiple queries) var users = db.Users.Where(u => u.IsActive).ToList(); var orders = db.Orders.Where(o => o.UserId == userId).ToList(); var products = db.Products.Where(p => p.CategoryId […]

Read More
Wordpress

Why Your Site Is Slow Even With Caching Enabled

- 25.01.26 - ErcanOPAK comment on Why Your Site Is Slow Even With Caching Enabled

Autoloaded options are silently killing performance. SELECT option_name FROM wp_options WHERE autoload = ‘yes’; Why this mattersToo many autoloaded rows = memory bloat on every request.

Read More
SQL

SQL Queries Slow After Adding Index

- 05.01.26 - ErcanOPAK comment on SQL Queries Slow After Adding Index

Counterintuitive but real. WhyOptimizer chooses suboptimal plan. FixUpdate statistics after index changes.

Read More
SQL

SQL Deadlocks Appear Under Load

- 03.01.26 - ErcanOPAK comment on SQL Deadlocks Appear Under Load

Works fine in testing. WhyDifferent execution order under concurrency. FixStandardize access order across queries.

Read More
SQL

SQL Queries Suddenly Ignore Indexes

- 03.01.26 - ErcanOPAK comment on SQL Queries Suddenly Ignore Indexes

Indexes exist, scans happen. WhyImplicit type conversions. Fix WHERE UserId = @UserId — matching types  

Read More
SQL

Parameter Sniffing Kills Performance

- 03.01.26 - ErcanOPAK comment on Parameter Sniffing Kills Performance

Random slow queries. WhyExecution plans cached incorrectly. Fix OPTION (RECOMPILE)  

Read More
SQL

SQL Query Slows Down as Data Grows

- 03.01.26 - ErcanOPAK comment on SQL Query Slows Down as Data Grows

Same query, worse performance. WhyMissing covering indexes. Fix CREATE INDEX IX_User_Email ON Users (Email) INCLUDE (Name, CreatedAt);  

Read More
AI

AI Prompt β€” SQL Performance Autopsy

- 03.01.26 - ErcanOPAK comment on AI Prompt β€” SQL Performance Autopsy

Prompt You are a senior DBA. Analyze this SQL query. Identify: – Missing indexes – Parameter sniffing – Hidden scans Rewrite it with explanation. Query: <PASTE QUERY>  

Read More
SQL

SQL Queries Randomly Slow Down

- 02.01.26 | 03.01.26 - ErcanOPAK comment on SQL Queries Randomly Slow Down

Same query, different speed. WhyParameter sniffing. Fix Use OPTION (RECOMPILE) selectively. 🐌 Same Query, Different Speed Nothing changed. Except the parameters. If a query sometimes runs in 10 ms and sometimes in 10 seconds,you’re probably not looking at a missing index. You’re looking at parameter sniffing. 🚨 The Core Problem SQL Server creates an execution […]

Read More
AI

AI Prompt β€” SQL Performance Autopsy

- 02.01.26 - ErcanOPAK comment on AI Prompt β€” SQL Performance Autopsy

Prompt Act as a senior DBA. Analyze this SQL query. Identify: – Index issues – Hidden scans – Cardinality problems Suggest a rewritten query. Query: <PASTE QUERY>  

Read More
SQL

SQL Queries Slow Down After Data Grows

- 01.01.26 - ErcanOPAK comment on SQL Queries Slow Down After Data Grows

Same query, worse performance. Why it happensMissing covering indexes. FixInclude frequently selected columns.

Read More
Wordpress

WordPress β€” wp_options Autoload Kills TTFB

- 30.12.25 - ErcanOPAK comment on WordPress β€” wp_options Autoload Kills TTFB

Autoloaded options load on every request. βœ… Fix Set unused options to autoload = no.

Read More
Page 1 of 2
1 2 Next Β»

Posts navigation

Older posts
March 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« Feb    

Most Viewed Posts

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

Recent Posts

  • C#: Saving Memory with yield return (Lazy Streams)
  • C#: Why Records are Better Than Classes for Data DTOs
  • C#: Creating Strings Without Memory Pressure with String.Create
  • SQL: Protecting Sensitive Data with Dynamic Data Masking
  • SQL: Writing Readable Queries with Common Table Expressions (CTE)
  • .NET Core: Handling Errors Gracefully with Middleware
  • .NET Core: Mastering Service Lifetimes (A Visual Guide)
  • Git: Surgical Stashing – Don’t Save Everything!
  • Git: Writing Commits That Your Future Self Won’t Hate
  • Ajax: Improving Perceived Speed with Skeleton Screens

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (938)
  • How to add default value for Entity Framework migrations for DateTime and Bool (837)
  • Get the First and Last Word from a String or Sentence in SQL (828)
  • How to select distinct rows in a datatable in C# (801)
  • How to make theater mode the default for Youtube (738)

Recent Posts

  • C#: Saving Memory with yield return (Lazy Streams)
  • C#: Why Records are Better Than Classes for Data DTOs
  • C#: Creating Strings Without Memory Pressure with String.Create
  • SQL: Protecting Sensitive Data with Dynamic Data Masking
  • SQL: Writing Readable Queries with Common Table Expressions (CTE)

Social

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