Posts

Showing posts with the label oracle

Bulk Inserts and the Performance Holy Grial (Part II)

Hi, Back to our topic ( see previous post ) about bulk inserts using PHP and Oracle OCI library, the first approach I'll explain today is as follows: Public method bulk_insert public function bulk_insert($common, $data) { try { $params = $this->prepareBulkInsertParams($common, $data); return $this->ociBulkInsert($params); } catch (Exception $e) { $this->logger->log(ERROR, $e->getMessage()); } } Neat, isn't it? At a first glance, a much clearer method is the result of a first refactor. Many of the code pieces have been extracted to a new method ( Extract method , Refactoring, K. Beck) alongside with new ones to give support to the PL/SQL batch insert syntax. Preparing the Parameters This method is just for extracting the incoming data and transform it into a more manageable array. private function prepareBulkInsertParams(array $common, array $data) : array { ext...

Bulk Inserts and the Performance Holy Grial (Part I)

Hello, I've been asked to improve a part of a model class which is causing some database issues. We use PHP and Oracle, so our legacy code is built using the OCI ( Oracle Client Interface) built-in library to take advantage as much as possible of the driver speed instead of using either the CodeIgniter abstracted database class or, simply, PDO ( PDO for Oracle ). Since we have to deal with bulk transactions under high load scenarios, database access optimization is a must. Massive rows have to be inserted prior to another batch of updates on them lately. Binding parameters in advance is a way of getting a performance improvement (read more on this topic here: https://blogs.oracle.com/sql/entry/improve_sql_query_performance_by ), in addition to avoid SQL injection attacks. So, here's is a snippet of what the bulk insert method looked like before any change: class TxnUser extends CI_Model { const OPEN = 1; const CLOSED = 0; [...] // Legacy meth...