I’m inserting many rows in a table having the following schema:
TABLE "SPACE"."WORKTABLE"
( "ID" NUMBER,
"AUTHOR" VARCHAR2(20 BYTE),
"INSERTION_DATE" DATE,
"XML_DOCUMENT" "SYS"."XMLTYPE"
)
The insertion is being done using ADO.NET (OracleXmlType).
The first inserted row takes more than two minutes to finish; but after this insertion is done, all the following take much less time than the first one.
- Why is this so?
- Is this only related to the XML parsing being done when inserting the XML? Why (if yes) it happens only at the first insertion?
- Can this time be reduced?
(please, if possible, document your answers)
UPDATE:
The code being executed is a simple insertion for at most 10 rows having an XML of 5500 character length. Also, I’ve already taken away the time taken to the connection to be opened as a cause of the lag.
string sql = "INSERT INTO WORKTABLE VALUES ( " + rowID + ",'JBALVIN',1,'01-JAN-12',:xmldocument)";
using (OracleCommand comm = new OracleCommand(sql, con))
{
comm.Parameters.Add(":xmldocument", OracleDbType.XmlType);
OracleXmlType xmlType = new OracleXmlType(con, entidadXML);
comm.Parameters[0].Value = xmlType;
comm.ExecuteNonQuery();
}
UPDATE:
We have noticed that the line causing the delay is OracleXmlType xmlType = new OracleXmlType(con, entidadXML);. Could it be fixed by stopping Oracle to check XML validity? If so… how can it be done? by a direct command using the connection?
Hmmm… after some guessing and googling, I found that if the URLs with the schema used on the XML are deleted (attributes
xmlns:xsiandxsi:noNamespaceSchemaLocation), the insertion is done in the order of milliseconds. Sadly, this behavior is not documented at Oracle OracleXmlType documentation.