B
Biff Gaut
Hello,
I am querying an Oracle database using the Microsoft Oracle Data
Provider for .NET and I am seeing significant performance penalties
when I us parameter based queries rather than pure text dynamic SQL.
Below is an actual query that demonstrates the problem - the first
query, which embeds the target value directly in the query executes in
abou1 1/10 sec. When I run the exact same query using a parameter I
get hung up for 25 seconds. Has anyone seen a problem like this or
have any idea what could be causing this delay? Is it endemic to
using the Microsoft provider as I have seen hinted at in other
messages? Being that we are close to deployment, I would really
prefer not to switch providers and have security concerns about
abandoning parameters.
//---------------------------------------
// Doing the query with Dynamic SQL is very quick
//---------------------------------------
string connectionString = "Data
Source=ValidateConnectionStringOmitted";
using (OracleConnection cn = new OracleConnection(connectionString))
{
cn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = cn;
cmd.CommandText =
@"SELECT
DISTINCT I.COL1,
I.COL2,
E.COL3,
E.COL1
FROM
TABLE1 I,
TABLE2 E
WHERE
I.COL1 = E.COL1 AND
I.COL2 LIKE 'AVALUE%'";
cmd.CommandType = System.Data.CommandType.Text;
OracleDataAdapter a = new OracleDataAdapter(cmd);
DataSet d = new DataSet();
// Timing on this call shows execution time of around 100 ms
a.Fill(d);
}
//---------------------------------------
// Using a parameter has a performance hit of 2 orders of magnitude!
//---------------------------------------
string connectionString = "Data
Source=ValidateConnectionStringOmitted";
using (OracleConnection cn = new OracleConnection(connectionString))
{
cn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = cn;
cmd.CommandText =
@"SELECT
DISTINCT I.COL1,
I.COL2,
E.COL3,
E.COL1
FROM
TABLE1 I,
TABLE2 E
WHERE
I.COL1 = E.COL1 AND
I.COL2 LIKE :LastName";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.Add(new OracleParameter("LastName",
OracleType.VarChar,
7,
ParameterDirection.Input,
false,
0,
0,
"",
DataRowVersion.Default,
"AVALUE%"));
OracleDataAdapter a = new OracleDataAdapter(cmd);
DataSet d = new DataSet();
// Timing on this call shows an execution time of over 25 seconds
a.Fill(d);
}
Thanks in advance for any advice.
Biff Gaut
Gaithersburg, MD
I am querying an Oracle database using the Microsoft Oracle Data
Provider for .NET and I am seeing significant performance penalties
when I us parameter based queries rather than pure text dynamic SQL.
Below is an actual query that demonstrates the problem - the first
query, which embeds the target value directly in the query executes in
abou1 1/10 sec. When I run the exact same query using a parameter I
get hung up for 25 seconds. Has anyone seen a problem like this or
have any idea what could be causing this delay? Is it endemic to
using the Microsoft provider as I have seen hinted at in other
messages? Being that we are close to deployment, I would really
prefer not to switch providers and have security concerns about
abandoning parameters.
//---------------------------------------
// Doing the query with Dynamic SQL is very quick
//---------------------------------------
string connectionString = "Data
Source=ValidateConnectionStringOmitted";
using (OracleConnection cn = new OracleConnection(connectionString))
{
cn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = cn;
cmd.CommandText =
@"SELECT
DISTINCT I.COL1,
I.COL2,
E.COL3,
E.COL1
FROM
TABLE1 I,
TABLE2 E
WHERE
I.COL1 = E.COL1 AND
I.COL2 LIKE 'AVALUE%'";
cmd.CommandType = System.Data.CommandType.Text;
OracleDataAdapter a = new OracleDataAdapter(cmd);
DataSet d = new DataSet();
// Timing on this call shows execution time of around 100 ms
a.Fill(d);
}
//---------------------------------------
// Using a parameter has a performance hit of 2 orders of magnitude!
//---------------------------------------
string connectionString = "Data
Source=ValidateConnectionStringOmitted";
using (OracleConnection cn = new OracleConnection(connectionString))
{
cn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = cn;
cmd.CommandText =
@"SELECT
DISTINCT I.COL1,
I.COL2,
E.COL3,
E.COL1
FROM
TABLE1 I,
TABLE2 E
WHERE
I.COL1 = E.COL1 AND
I.COL2 LIKE :LastName";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.Add(new OracleParameter("LastName",
OracleType.VarChar,
7,
ParameterDirection.Input,
false,
0,
0,
"",
DataRowVersion.Default,
"AVALUE%"));
OracleDataAdapter a = new OracleDataAdapter(cmd);
DataSet d = new DataSet();
// Timing on this call shows an execution time of over 25 seconds
a.Fill(d);
}
Thanks in advance for any advice.
Biff Gaut
Gaithersburg, MD