Skip to content

Commit

Permalink
Oracle, read config values as varchar
Browse files Browse the repository at this point in the history
When using Oracle database, read config values as varchar type whenever
it's possible, to avoid performance issues of reading clob field types.

Even if the issue may also exist with other tables, config table is
especially sensitive, as it is fully fetched  for every page execution.

Fixes: #23395
  • Loading branch information
cproensa authored and dregad committed Sep 28, 2017
1 parent 6b0df30 commit 1b1f2b2
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions core/config_api.php
Expand Up @@ -132,15 +132,7 @@ function config_get( $p_option, $p_default = null, $p_user = null, $p_project =
# @@ debug @@ echo 'pr= '; var_dump($t_projects);
# @@ debug @@ echo 'u= '; var_dump($t_users);
if( !$g_cache_filled ) {
$t_query = 'SELECT config_id, user_id, project_id, type, value, access_reqd FROM {config}';
$t_result = db_query( $t_query );
while( false <> ( $t_row = db_fetch_array( $t_result ) ) ) {
$t_config = $t_row['config_id'];
$t_user = $t_row['user_id'];
$t_project = $t_row['project_id'];
$g_cache_config[$t_config][$t_user][$t_project] = $t_row['type'] . ';' . $t_row['value'];
$g_cache_config_access[$t_config][$t_user][$t_project] = $t_row['access_reqd'];
}
config_cache_all();
$g_cache_filled = true;
}

Expand Down Expand Up @@ -727,3 +719,48 @@ function config_is_defined( $p_option, $p_value = null ) {
# Value not found in cache
return false;
}

/**
* Loads the contents of config table into cache
* @return void
*/
function config_cache_all() {
global $g_cache_config, $g_cache_config_access;

$t_config_rows = array();

# With oracle databse, ADOdb maps column type "L" to clob.
# Because reading clobs is significantly slower, cast them to varchar for faster query execution
# Standard max size for varchar is 4000 bytes, so a safe limit is used as 1000 charancters
# for multibyte strings (up to 4 bytes per char)
if( db_is_oracle() ) {
$t_query = 'SELECT config_id, user_id, project_id, type, CAST(value AS VARCHAR(4000)) AS value, access_reqd'
. ' FROM {config}'
. ' WHERE dbms_lob.getlength(value)<=1000';
$t_result = db_query( $t_query );
while( $t_row = db_fetch_array( $t_result ) ) {
$t_config_rows[] = $t_row;
}
$t_query = 'SELECT config_id, user_id, project_id, type, value, access_reqd'
. ' FROM {config}'
. ' WHERE dbms_lob.getlength(value)>1000';
$t_result = db_query( $t_query );
while( $t_row = db_fetch_array( $t_result ) ) {
$t_config_rows[] = $t_row;
}
} else {
$t_query = 'SELECT config_id, user_id, project_id, type, value, access_reqd FROM {config}';
$t_result = db_query( $t_query );
while( false <> ( $t_row = db_fetch_array( $t_result ) ) ) {
$t_config_rows[] = $t_row;
}
}

foreach( $t_config_rows as $t_row ) {
$t_config = $t_row['config_id'];
$t_user = $t_row['user_id'];
$t_project = $t_row['project_id'];
$g_cache_config[$t_config][$t_user][$t_project] = $t_row['type'] . ';' . $t_row['value'];
$g_cache_config_access[$t_config][$t_user][$t_project] = $t_row['access_reqd'];
}
}

0 comments on commit 1b1f2b2

Please sign in to comment.