database - MySQL INSERT shorthand vs longhand performance -


what difference between:

insert `table_name` set `col1` = 'val1', `col2` = 'val2', `col3` = 'val3' 

and

insert `table_name` (`col1`,`col2`,`col3`) values('val1','val2','val3') 

is there performance benefit of using shorthand? prefer longhand myself, logically, performance reasons, should using shorthand every time? benchmark testing telling me option #2 above bit faster margin of 3%, why?

public function benchmarkinsert() {      $int_value = 1;     $varchar_value = 'stuff';     $serialized_value = json_encode(array('serialized stuff'));      $this->db->query("truncate table `query_benchmark`");      $start = microtime(true);             ( $i = 0; $i < 10000; $i++ ) {                   $this->db->query("insert `query_benchmark` (`col1`,`col2`,`col3`) values($int_value,'$varchar_value','$serialized_value')");     }             $elapsed = microtime(true) - $start;      echo 'shorthand: '.$elapsed.'<br/>';      $this->db->query("truncate table `query_benchmark`");             $start = microtime(true);             ( $i = 0; $i < 10000; $i++ ) {          $this->db->query("insert `query_benchmark` set `col1` = $int_value, `col2` = '$varchar_value', `col3` = '$serialized_value'");      }             $elapsed = microtime(true) - $start;      echo 'longhand: '.$elapsed.'<br/>';  } 

there shouldn't difference in 2 queries. should transformed same execution plan database.

the 3% difference being caused unrelated factor (caching, database load, etc)

you can validate viewing execution plan explain

https://dev.mysql.com/doc/refman/5.6/en/explain.html


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -