I have a simple NO-OP CLR Trigger being fired on a six field table with schema:
datetime (PK)
char (PK)
int (PK, FK)
varchar(1)
tinyint
real
which should be a total of 19 bytes / row inserted.
The FK in the above points to a table with schema:
int (PK)
nchar(10)
ncahr(10)
nchar(10)
nchar(10)
I am performing batch inserts using a prepared statement every 1000 rows. I am getting for 150K rows inserted an execution time of about 11s. This corresponds to a throughput of ~.24MB/s (150,000*19B / 11s). Why so slow? I am not even talking to the disk?
I know that my client side code doing the sending is much faster. If I comment out the:
executeBatch()
method in the client I get upwards of 5MB/s. What else is going on with the JDBC/ODBC connection and processing in SQL Server to make things so slow?
Is this really the throughput one can expect from SQL Server and an JDBC/ODBC connection in this case?
---EDIT---
The actual CLR code is very simple, literally an empty method:
public class Triggers
{
[SqlTrigger(Name = "InsertHook", Target = ConfigConstants.TABLE_NAME, Event = "INSTEAD OF INSERT")]
public static void InsertHook()
{
//empty
}
}
No-op in T-SQL Stored Procedure Total Measured Time was:3475297036ns or 3.475297036sec INSERT COUNT:150000 0.783276657MB/s 43165.47 Rows/s
INSERTING NORMAL into SQL Server Total Measured Time was:4884190118ns or 4.884190118sec INSERT COUNT:150000 MB Sent:2.7179718017578125 0.556MB/s 30712.53 Rows/s
Sadly, I do not have control over the schemas I am working with here. I guess I am still shocked that even with one FK constraint that this is the best SQL Server can do?
In summary, if I had to rank the performance. It would be:
1) T-SQL NO-OP Instead of Trigger (Fastest) - 0.78MB/s
2) Inserting Normal - 0.56MB/s
3) CLR NO-OP Stored Procedure Instead of Trigger - .24MB/s