I reduced an endpoint response time by 75% without changing a single line of infrastructure. I just changed how the query reached the database. The scenario: a report with 5 JOINs, SUM and COUNT aggregations, city and date filters, running against 1 million records. Spring Data JPQL with DTO projection: 1,240ms at p95. Starting point. Native SQL with nativeQuery = true: 780ms. 37% faster just by writing raw SQL and removing the ORM translation overhead. Materialized View mapped as a read-only entity: 310ms. The endpoint became a simple SELECT with filters. The database had already done the heavy lifting before the request arrived. The lesson was straightforward: the ORM is not the villain, but it has a cost that shows up when the query gets heavy. Knowing when to move away from JPQL and when to go beyond Native SQL makes a real difference in production. Which of these approaches are you using today for reports with many JOINs? #Java #SpringBoot #Backend #SoftwareEngineering #DatabasePerformance
Guilherme Narciso’s Post
More Relevant Posts
-
🚀 Why Scalar Functions Can Hurt Your SQL Performance! While working on backend systems and writing SQL queries, I discovered a common mistake that can silently slow down your application… 💡 Using Scalar Functions inside queries. At first, they seem very convenient — wrapping logic into a reusable function sounds like a clean solution. But here’s the problem 👇 ❌ Scalar Functions are executed row by row ❌ They prevent SQL Server from optimizing the query properly ❌ They can significantly slow down performance on large datasets 📌 Example: SELECT name, dbo.GetDiscount(price) FROM products; This looks clean… but behind the scenes, the function is executed for EACH row 😬 ✅ Better Approaches: ✔️ Use JOINs or inline logic instead ✔️ Prefer Inline Table-Valued Functions (iTVF) ✔️ Handle logic in the application layer when appropriate 🔥 Key Takeaway: "Clean code is not always fast code — always think about performance!" Have you ever faced performance issues بسبب Scalar Functions؟ 👇 #SQLServer #Backend #Java #SpringBoot #Performance #SoftwareEngineering #Database #CleanCode
To view or add a comment, sign in
-
SlothDB is a super fast embedded SQL database. 😁 You point SQL at a file. Parquet, CSV, JSON, Avro, Arrow, SQLite, Excel. No server, no import step, no extension to install before you can read a Parquet file. Same embedded model as SQLite and DuckDB, different defaults. A few things we cared about while building it: It is one binary. Drop slothdb.exe somewhere, run it. It runs in the browser. The WASM build is 1.3 MB and fits Workers' 1 MB script cap in the edge variant. It is fast enough to be worth the swap for analytical work. On a 5-query warm batch over 10M rows, SlothDB finishes in 138 ms. DuckDB 1.1.5 finishes the same batch on the same hardware in 540 ms. It is also early. v0.1.8 shipped today. The Python wheel had a packaging bug last week that I only caught because a stranger filed an issue. So if you hit a rough edge, file one. We read every one. Try it in 10 seconds at https://slothdb.org or pip install slothdb. Our Github repo- https://lnkd.in/gxCSmACA #SQL #DataEngineering #DuckDB #OpenSource #OLAP
To view or add a comment, sign in
-
-
🚀 Day 18/30 of my SQL Challenge 📌 Problem Statement: Monthly Transactions I. The task was to generate a monthly report for each country including: -Total transactions -Approved transactions -Total transaction amount -Approved transaction amount 💡 Approach: -Used DATE_FORMAT() to extract month from the transaction date -Applied GROUP BY on month and country -Used conditional aggregation: SUM(CASE WHEN ...) to count only approved transactions Calculated both counts and amounts in a single query 🧠 Key Learnings: -Clear understanding of GROUP BY and conditional aggregation pattern -Difference between SUM and COUNT in conditional cases -How to solve multiple requirements efficiently in one query -Importance of breaking down the problem before jumping into coding #Day18 #SQL #LeetCode #CodingJourney #SDE #ProblemSolving #MYSQL
To view or add a comment, sign in
-
-
🚨 SELECT * is silently killing your SQL queries. I've seen a 40ms query turn into a 9-second nightmare - all because of one hidden TEXT column. And the culprit? A lazy SELECT * in production. Here's what most developers don't realize: → Every unused column travels across the network on every query → LOB columns (TEXT, BLOB) silently explode your RAM usage → Databases can't optimize what they don't know you need → Schema changes break your app - often without a single error thrown In a benchmark of 10,000 rows with 22 columns: SELECT * consumed 6× more memory than explicit column lists. The fix is simple. The discipline is the hard part. Name your columns. Every. Single. Time. I put together a 7-slide breakdown covering: ✅ Why SELECT * hurts performance ✅ Real benchmark numbers ✅ The breaking changes it causes ✅ The exact fix with code examples ✅ 3 production SQL rules to live by Swipe through the doc and save it for your next code review. What's the worst SELECT * story from your production database? Drop it in the comments - I'd love to hear it. 👇 #SQL #DataAnalysis #QueryOptimization #Backend #DatabasePerformance #Programming #TechTips
To view or add a comment, sign in
-
I just published a new article in my Spring Boot learning series One common confusion in JPA is choosing between JPQL and Native SQL. So I broke it down with real examples . Topics covered : - When to use JPQL / HQL - When Native SQL is necessary - Trade-offs between portability and performance - Real Spring Boot examples Read the full article here : https://lnkd.in/d6akwNwd
To view or add a comment, sign in
-
LINQ vs SQL — Which is Faster? Short answer: 👉 It depends. --- 💡 LINQ Advantages: • Readable • Maintainable • Type-safe --- 💡 SQL Advantages: • Full control • Better for complex queries • Optimized execution --- ❌ Common Mistake: Using LINQ blindly for everything. --- ✅ Smart Approach: • Use LINQ for simple queries • Use raw SQL for complex scenarios • Analyze generated SQL --- ⚠️ Important: LINQ is translated into SQL. Bad LINQ = Bad SQL --- 💡 Real Insight: Performance issues are not about LINQ vs SQL. They are about how queries are written. --- Do you inspect your generated SQL queries? #dotnet #linq #sql #performance #softwareengineering
To view or add a comment, sign in
-
-
💡 While working on converting XML-based procedures to JSON, I came across an interesting behavior that many developers overlook 👇 👉 SQL Server is NOT fully case-sensitive by default But… 👉 JSON parsing inside SQL Server IS case-sensitive 🚨A real issue that i faced on today. -- SQL OPENJSON(@json, '$.Achievement') // JSON { "achievement": [...] } 👉 Result: No data returned (no error!) Reason? Achievement ≠ achievement Because -- JSON is case-sensitive JSON_VALUE(@json, '$.Achievement ') ❌ NULL JSON_VALUE(@json, '$.achievement') ✅ Works #SQLServer #JSON #BackendDevelopment #Database #Learning #Debugging #TechTips
To view or add a comment, sign in
-
📊 𝐒𝐭𝐨𝐫𝐞𝐝 𝐏𝐫𝐨𝐜𝐞𝐝𝐮𝐫𝐞𝐬, 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬 & 𝐩𝐚𝐜𝐤𝐚𝐠𝐞𝐬 𝐢𝐧 𝐏𝐋/𝐒𝐐𝐋 𝐒𝐭𝐨𝐫𝐞𝐝 𝐏𝐫𝐨𝐜𝐞𝐝𝐮𝐫𝐞𝐬 ➡️ are named PL/SQL blocks that perform a specific task. They help in: ✔ Reusability of code ✔ Better performance (compiled once, reused many times) ✔ Reduced network traffic 👉 Think of them as reusable “actions” you can execute whenever needed. 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬 ➡️ are similar to procedures but with one key difference: 👉 They must return a value Used mainly for: ✔ Calculations ✔ Data transformations ✔ Returning single values in SQL queries ⚡ Functions can be directly used inside SQL statements, unlike procedures. 𝐩𝐚𝐜𝐤𝐚𝐠𝐞𝐬 ➡️ are like containers that group related procedures, functions, variables, and cursors together. They consist of: 📌 Specification – Declares what is accessible 📌 Body – Defines how it works Benefits: ✔ Modular programming ✔ Improved performance (loaded once in memory) ✔ Better security & encapsulation #PLSQL #OracleDB #DatabaseProgramming #SQL #StoredProcedures #Functions #Packages #Coding #Learning #TechSkills
To view or add a comment, sign in
-
Are you quietly choking your database with Spring Data JPA? Abstractions are beneficial, but relying on them without understanding what Hibernate is doing under the hood can lead to issues in high-throughput distributed systems. If you are using findAll() to load full entities just to read two columns, or executing COUNT() queries for infinite scrolls, you are missing out on significant performance improvements. I just published a comprehensive guide on Medium that breaks down 5 proven strategies to optimize your JPA queries. Link to the full deep dive is in the comments. What is your go-to strategy for addressing the N+1 problem? Let me know below. #JavaDeveloper #SpringBoot #Hibernate #DatabaseOptimization #LetsCodeWithKK
To view or add a comment, sign in
-
📒 SQL Performance Tuning — Notes (Backend Devs Should Know) 🧠 What is SQL Performance? How fast your query returns results + How efficiently it uses resources (CPU, Memory, I/O) ⚠️ Common Mistakes: • Using SELECT * • Missing indexes • Writing complex joins without filtering • Ignoring execution plans • Fetching unnecessary data ⚙️ Core Concepts: 👉 Indexing • Speeds up data retrieval • Works like a “table of contents” • Over-indexing can slow down writes 👉 Query Optimization • Filter early (WHERE clause) • Avoid nested subqueries (use joins wisely) • Use proper joins (INNER vs LEFT) 👉 Execution Plan • Shows how SQL actually runs your query • Helps find bottlenecks • Always analyze for slow queries 👉 Normalization vs Denormalization • Normalization → avoids redundancy • Denormalization → improves read performance 🚀 Pro Tips: • Use indexes on frequently searched columns • Avoid functions on indexed columns • Use LIMIT / TOP when needed • Cache frequently used data • Monitor slow queries regularly 💡 Reality Check: Fast code ≠ Fast application 👉 Database performance is the real bottleneck in most systems DotNet #CSharp #SQL #SQLServer #ASPNet #BackendDevelopment #DatabaseDesign
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Congrats!