Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: xathrasHi Guys,
I have been troubleshooting some slowness on a JDBC query that uses SQL bindings and wanted to see if anyone else has come across this issue or suggestions.
I have a query, lets say to look at an order table, to get a list of order numbers, and i pass in a order number as a JDBC binding, the purpose is to exclude any that exist already from being added. It runs a sql like the following:
select MASTER_ORDER_ID
from [DB].[dbo].[BRE]
where MASTER_ORDER_ID = ?
On the SQL Server, it looks like its taking the JDBC binding input as a nvarchar rather than a varchar.
Lets say I have 5000 orders to check, its taking 12+ minutes to get the output. After running the SQL and running the SQL profile in SQL Server, I am seeing it doing the following execution plan:
Select (Cost 0%) -> Parallelism (Cost %) -> Filter (Cost 100%) -> Compute Scaler (Cost 0%) -> Index Scan (Cost 0%)
If i run manually on the SQL server It executes quickly. And the execution plan is:
Select (Cost 0%) -> Hash Match (Right Semi Join) (Cost 60%) -> Constant Scan (Cost 0%) -> Index Seek (Cost 40%)
Is there anyway to force the jdbc binding input i am setting as a varchar, rather than nvarchar. It seems like the converting is causing the slowness.
Wayne