views:

99

answers:

3

Does anybody have any suggestions on how to improve the following statements:

insert into ProductInfo with (rowlock) (orderid, productname)
      select 66673, FileInfoId
        from ProductInfo with (nolock) where 
          ProductId = 66671 and
          IsEligableForCopy = 1 and 
          ProductFileInfoId >= 2768395941 and 
          ProductFileInfoId < 2768405941
A: 

The Query looks fine. It should be running perfectly. Is there anything specific that you want to achieve.?

1s2a3n4j5e6e7v
+1  A: 

It sounds like it is timing out because it fails to obtain a lock. What DBMS are you using? And have you tried it without requesting a lock? The example you present appears to be a one-time insert, but I assume this is just an example, as opposed to something you would run in production.

MJB
I am using SQL 2005, maybe I should be removing the rowlock and nolock?
RPS
I would think that the locks should be unnecessary.
MJB
Ok, I will try with removing the rowlock and nolock and see if it improves.Thanks!
RPS
@RPS I don't understand why you asked this question then failed to respond when asked about existing indexes and number of records. (Both highly relevant to the performance of your query)
Martin Smith
@Martin Sorry I missed that post,It will return 10000 rows at a time, and I don't have an index on ProductFileInfoId... Maybe that will help!
RPS
Also, I know there is never updates happening on the ProductFileInfo table so that is the reason for NOLOCK.. Only inserts.
RPS
@RPS - What is the clustered index on the table?
Martin Smith
@RPS If it is the SELECT that is taking a long time then a composite index on ProductId, IsEligableForCopy, ProductFileInfoId might help with included column FileInfoId
Martin Smith
ProductId is the clustered index on the table.
RPS
@RPS and will your insert end up putting it at the end (e.g. are you always inserting the `Max(ProductId) + 1`?
Martin Smith
@RPS In any event you're probably best off optimising the performance of the `SELECT` part first by providing appropriate indexes.
Martin Smith
+1  A: 

Improve or add indicies on ProductInfo...maybe it won't timeout

Ed B