Is there a way to have PB execute Embedded SQL or Datawindow queries in a parametrized form? (Apart from rebuilding the entire application to use Stored Procedures)
Scenario
We have a (embedded or DW) SQL query like this:
SELECT col1, col2
FROM tbl
WHERE col3 = :para_1
AND col4 = :para_2
At runtime, PB will parse this text, substitute :para_1 and :para_2 with the values of those parameters and send the entire String to the DB.
The problem with this approach is, that (at least for MS SQL Server), unless Forced Parametrisation is enabled, this results in a new query for every combination of parameters which all have to be analyzed and optimized by the database.
Suggestion
If there was an option to have PB send the statement using sp_executesql, the DBMS would have to compile far fewer different statements.
EXECUTE sp_executesql
N'SELECT col1, col2
FROM tbl
WHERE col3 = @para_1
AND col4 = @para_2',
N' @para_1 int, @para_2 int',
@para_1 =
@para_2 =
Obviously, there could be other problems with parameter sniffing with this solution, but there's also many scenarios where this could lead to a massive performance increase.
In our example, we have many queries where query compilation takes more time than the actual query execution, let alone the massive amount of memory wasted in the query cache.
That's exactly what I was looking for. Thanks a lot!
Regards,
Markus
Additional performance related properties for the SNC driver:
"Transaction" tab page
BindSPInput=1 -- or your DIsableBind=0 has no impact on stored procedure calls
Block
StaticBind=1 (turned on by default)
Lock
"System" tab page
SPCache
PacketSize
Anyways, have a look at online help's Connecting to Your Database > Working with Native Database Interfaces > Using Microsoft SQL Server and Connecting to Your Database > Using Embedded SQL > Using Embedded SQL with Microsoft SQL Server. There may be a few goodies relevant to your setup. EX: How to handle spatial data types or the HierarchyID data type.
Enjoy, /Michael
Recalculate statistics.
Create appropriate indexes in the table.
Create a stored procedure with internal variables, so the optimizer will take an average and not the values of the first execution.
Put the query in cache of the database.
By performing these actions the parse of the query will be imperceptible.