From d8b35e0a771e92fa8a4e24bf62efa800567ffd08 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 30 Jun 2014 09:05:16 +0000 Subject: [PATCH] only join in extra table, if we really need it, to improve performance --- etemplate/inc/class.so_sql_cf.inc.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/etemplate/inc/class.so_sql_cf.inc.php b/etemplate/inc/class.so_sql_cf.inc.php index 7c70802147..1dba60208d 100644 --- a/etemplate/inc/class.so_sql_cf.inc.php +++ b/etemplate/inc/class.so_sql_cf.inc.php @@ -437,8 +437,6 @@ class so_sql_cf extends so_sql } if ($criteria && is_array($criteria)) { - $join .= $this->extra_join; - // check if we search in the custom fields if (isset($criteria[$this->extra_value])) { @@ -462,8 +460,15 @@ class so_sql_cf extends so_sql unset($criteria[$this->autoinc_id]); } // replace ambiguous column with (an exact match of) table_name.column + $extra_join_added = $join && strpos($join, $this->extra_join) !== false; foreach($criteria as $name => $val) { + // only add extra_join, if we really need it + if (!$extra_join_added && is_int($name) && strpos($val, $this->extra_value) !== false) + { + $join .= $this->extra_join; + $extra_join_added = true; + } $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) {