Which is Faster for Millions of Records? Procedure or Insert Statement with Multiple Values – MySQL

MySQLmysql-5.6stored-procedures

I have written a perl script that reads row from a tab separated txt file, do some processing on it, and inserts into the MySQL table.

Currently, I am making an insert query with 10,000 records (from the script) and finally execute the statement.
insert into tablename values (1, 'kamal'), (2, 'nayan'), ......, (10000, 'kumar');

Another approach that came in my mind is stored procedure. Can anyone tell me how can I utilise stored procedure to make my queries faster? Right now, I have tested stored procedure to insert one row at a time, but that would need 10000 procedure calls, while insert statement is asking for just one call.

Any help would be appreciated.
Engine: InnoDB
Version: 5.5.45

Best Answer

Stored Procedure is better, why? Read this: http://www.sqlbook.com/SQL-Server/Why-use-Stored-Procedures-41.aspx

When a query runs, it calculates the most efficient method of processing the query and stores it in something called the execution plan. Depending on the query, a good deal of the time taken to execute a query is actually spent on calculating the execution plan.

When inline SQL statements are executed the execution plan must be generated each time the query runs. When a stored procedure is called its execution plan is stored in memory and the next time the stored procedure is called the execution plan is retrieved from memory without needing to be recalculated. This increases the speed of execution and improves database performance.