You can simplify your code a bit by looping over the updatedRecordsQuery directly, instead of doing an index loop:
Then inside your loop, you don't need the loop index references at all, so "updatedRecordsQuery.firstname[a]" becomes "updatedRecordsQuery.firstname".
That probably won't address your performance issue though. Looping that many records is going to be resource intensive. Since you are already storing the new data in a temporary table on the database server, it seems like you could try to offload the process of updating your "CI" table to your database server as well. Maybe you can write a stored procedure that you can call from CF using <cfstoredproc> or <cfquery>. What DBMS are you using?
I would suggest to use select update instead of looping over query object and update each row one-by-one.
- Insert your CSV data into temp table.
- Use a select update SQL query to update the changed data instead of looping over a select query.
Table.col1 = other_table.col1,
Table.col2 = other_table.col2
Table.id = other_table.id
NOTE: You can put all your scripts in a Procedure.
Maybe this is a dumb question but how are you detecting updated rows in the temp table.
Is there a "update date" field that indicates a change or are you scanning/comparing multiple fields.
If the answer is the second option maybe you can add a date stamp to the application that creates the csv file and add a date variable to your temp table query WHERE statement.