summaryrefslogtreecommitdiff
path: root/adodb-loadbalancer.inc.php
diff options
context:
space:
mode:
authormike.benoit <mikeb@timetrex.com>2015-08-12 07:52:46 -0700
committerDamien Regad <dregad@mantisbt.org>2020-01-25 01:04:34 +0100
commit6d517da6bd4e2c53eb2f99d5937fb1ea46dbb882 (patch)
tree301e5f9196a6cee0f6324a4678ff072e5b272e83 /adodb-loadbalancer.inc.php
parentb354b84034151aee3a80c9c22806b7bace2dddd0 (diff)
downloadadodb-6d517da6bd4e2c53eb2f99d5937fb1ea46dbb882.tar.gz
adodb-6d517da6bd4e2c53eb2f99d5937fb1ea46dbb882.tar.bz2
adodb-6d517da6bd4e2c53eb2f99d5937fb1ea46dbb882.zip
Improve query routing to master when its non-readonly
Diffstat (limited to 'adodb-loadbalancer.inc.php')
-rw-r--r--adodb-loadbalancer.inc.php20
1 files changed, 18 insertions, 2 deletions
diff --git a/adodb-loadbalancer.inc.php b/adodb-loadbalancer.inc.php
index f52b9074..fc7597ed 100644
--- a/adodb-loadbalancer.inc.php
+++ b/adodb-loadbalancer.inc.php
@@ -300,12 +300,24 @@ class ADOdbLoadBalancer {
return FALSE;
}
+ public function isReadOnlyQuery( $sql ) {
+ if ( stripos( $sql, 'SELECT') === 0 && stripos( $sql, 'FOR UPDATE') === FALSE && stripos( $sql, ' INTO ') === FALSE && stripos( $sql, 'LOCK IN') === FALSE ) {
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
//Use this instead of __call() as it significantly reduces the overhead of call_user_func_array().
public function Execute( $sql, $inputarr = FALSE ) {
$type = 'master';
$pin_connection = NULL;
- if ( stripos( $sql, 'SELECT') === 0 ) {
+ //SELECT queries that can write and therefore must be run on MASTER.
+ //SELECT ... FOR UPDATE;
+ //SELECT ... INTO ...
+ //SELECT .. LOCK IN ... (MYSQL)
+ if ( $this->isReadOnlyQuery( $sql ) == TRUE ) {
$type = 'slave';
} elseif ( stripos( $sql, 'SET') === 0 ) {
//SET SQL statements should likely use setSessionVariable() instead,
@@ -329,12 +341,16 @@ class ADOdbLoadBalancer {
$method = strtolower($method);
switch ( $method ) {
//case 'execute': //This is the direct overloaded function above instead.
- case 'selectlimit':
case 'getone':
case 'getrow':
case 'getall':
case 'getcol':
case 'getassoc':
+ case 'selectlimit':
+ if ( $this->isReadOnlyQuery( $args[0] ) == TRUE ) {
+ $type = 'slave';
+ }
+ break;
case 'cachegetone':
case 'cachegetrow':
case 'cachegetall':