Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL INSERT performance omitting field names?

Does anyone knows if removing the field names from an INSERT query results in some performance improvements?

I mean is this:

INSERT INTO table1 VALUES (value1, value2, ...)

faster for DB to be accomplished rather than doing this:

INSERT INTO table1 (field1, field2, ...) VALUES (value1, value2, ...)

?

I know it might be probably a meaningless performance difference, but just to know.

I'm usually using MySQL and PostgreSQL as DBs.

like image 430
Marco Demaio Avatar asked Mar 24 '10 18:03

Marco Demaio


1 Answers

No, actually the contrary! At least for Microsoft SQL Server - you didn't specify what database you're talking about.....

If you don't specify the fields, either in a SELECT or an INSERT, then SQL Server's query processor must first go inspect the system catalogs to find out what fields are indeed available.

So I would always recommend to explicitly list the fields you want - on SELECTs as much as on INSERTs.

like image 180
marc_s Avatar answered Oct 14 '22 11:10

marc_s