Please read this article created by @Erland Sommarskog about how parameter sniffing can play a role in that scenario. I am mentioning him here in case he would like to talk to you about other possible reasons and how to deal with them.
Discrepancy in Azure SQL Server Query Performance: Index Seek in SSMS vs Index Scan in Java Application
Hello,
I'm facing an issue with Azure SQL Server (PaaS) query performance and I'm hoping to get some insights from you all.
Problem Statement:
I have a SQL query that performs well (~6 ms) when executed directly in SQL Server Management Studio (SSMS), showing an "Index Seek" in the execution plan. However, when the same query is executed from my Java application (spring boot deployed over azure app service) using JDBC, the execution plan shows an "Index Scan" and the query takes significantly longer (~1 Sec) to execute.
What I've Tried:
- Ensured that statistics are up-to-date on the tables and indexes involved.
- Compared the execution context settings between SSMS and the Java application.
- Added SQL into Stored prod and then it works fine, does index seek.
- Removed plan id, cleared cache.
Question:
- What could be causing this discrepancy in query performance?
- Are there any debugging steps that I might have missed?
Any insights or suggestions would be greatly appreciated. Thank you!
2 answers
Sort by: Most helpful
-
-
Oury Ba-MSFT 19,101 Reputation points Microsoft Employee
2023-09-29T17:35:06.5166667+00:00 Vipin Sharma Thank you for reaching out.
I agree with @Alberto Morillo . It depends on how connector is sending the query to the server, it's an index scan rather than a seek. So, the connection object, in this case JDBC being used is structuring the query in a way where the where clause is not getting optimized to use index. App service as a platform doesn't control this.
Regards,
Oury