Created
December 1, 2013 09:50
-
-
Save lirantal/7730563 to your computer and use it in GitHub Desktop.
Drupal 6 - slow queries improvements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/drupal/includes/bootstrap.inc b/src/drupal/includes/bootstrap.inc | |
index a895ab5..33f13c6 100644 | |
--- a/src/drupal/includes/bootstrap.inc | |
+++ b/src/drupal/includes/bootstrap.inc | |
@@ -1064,7 +1064,7 @@ function drupal_is_denied($type, $mask) { | |
// We deny access if the only matching records in the {access} table have | |
// status 0 (deny). If any have status 1 (allow), or if there are no | |
// matching records, we allow access. | |
- $sql = "SELECT 1 FROM {access} WHERE type = '%s' AND LOWER('%s') LIKE LOWER(mask) AND status = %d"; | |
+ $sql = "SELECT 1 FROM {access} WHERE type = '%s' AND ('%s') LIKE (mask) AND status = %d"; | |
return db_result(db_query_range($sql, $type, $mask, 0, 0, 1)) && !db_result(db_query_range($sql, $type, $mask, 1, 0, 1)); | |
} | |
diff --git a/src/drupal/modules/comment/comment.module b/src/drupal/modules/comment/comment.module | |
index 58e9ce6..425b80a 100644 | |
--- a/src/drupal/modules/comment/comment.module | |
+++ b/src/drupal/modules/comment/comment.module | |
@@ -1201,7 +1201,7 @@ function comment_validate($edit) { | |
$node = node_load($edit['nid']); | |
if (variable_get('comment_anonymous_'. $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) { | |
if ($edit['name']) { | |
- $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name'])); | |
+ $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE (name) = '%s'", $edit['name'])); | |
if ($taken != 0) { | |
form_set_error('name', t('The name you used belongs to a registered user.')); | |
diff --git a/src/drupal/modules/profile/profile.admin.inc b/src/drupal/modules/profile/profile.admin.inc | |
index 089b5ea..6f7b220 100644 | |
--- a/src/drupal/modules/profile/profile.admin.inc | |
+++ b/src/drupal/modules/profile/profile.admin.inc | |
@@ -395,7 +395,7 @@ function profile_field_delete_submit($form, &$form_state) { | |
*/ | |
function profile_admin_settings_autocomplete($string) { | |
$matches = array(); | |
- $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER('%s%%')", $string, 0, 10); | |
+ $result = db_query_range("SELECT category FROM {profile_fields} WHERE (category) LIKE ('%s%%')", $string, 0, 10); | |
while ($data = db_fetch_object($result)) { | |
$matches[$data->category] = check_plain($data->category); | |
} | |
diff --git a/src/drupal/modules/profile/profile.module b/src/drupal/modules/profile/profile.module | |
index d3ff8c6..856bd19 100644 | |
--- a/src/drupal/modules/profile/profile.module | |
+++ b/src/drupal/modules/profile/profile.module | |
@@ -564,7 +564,7 @@ function _profile_get_fields($category, $register = FALSE) { | |
} | |
else { | |
// Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues. | |
- $filters[] = "LOWER(category) = LOWER('%s')"; | |
+ $filters[] = "(category) = ('%s')"; | |
$args[] = $category; | |
} | |
if (!user_access('administer users')) { | |
diff --git a/src/drupal/modules/profile/profile.pages.inc b/src/drupal/modules/profile/profile.pages.inc | |
index 5e45499..5e60fde 100644 | |
--- a/src/drupal/modules/profile/profile.pages.inc | |
+++ b/src/drupal/modules/profile/profile.pages.inc | |
@@ -109,7 +109,7 @@ function profile_browse() { | |
function profile_autocomplete($field, $string) { | |
$matches = array(); | |
if (db_result(db_query_range("SELECT 1 FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field, 0, 1))) { | |
- $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10); | |
+ $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND (value) LIKE ('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10); | |
while ($data = db_fetch_object($result)) { | |
$matches[$data->value] = check_plain($data->value); | |
} | |
diff --git a/src/drupal/modules/statistics/statistics.admin.inc b/src/drupal/modules/statistics/statistics.admin.inc | |
index 63845fe..86089f3 100644 | |
--- a/src/drupal/modules/statistics/statistics.admin.inc | |
+++ b/src/drupal/modules/statistics/statistics.admin.inc | |
@@ -81,7 +81,7 @@ function statistics_top_visitors() { | |
array('data' => t('Operations')) | |
); | |
- $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, ac.aid FROM {accesslog} a LEFT JOIN {access} ac ON ac.type = 'host' AND LOWER(a.hostname) LIKE (ac.mask) LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, ac.aid". tablesort_sql($header); | |
+ $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, ac.aid FROM {accesslog} a LEFT JOIN {access} ac ON ac.type = 'host' AND (a.hostname) LIKE (ac.mask) LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, ac.aid". tablesort_sql($header); | |
$sql_cnt = "SELECT COUNT(*) FROM (SELECT DISTINCT uid, hostname FROM {accesslog}) AS unique_visits"; | |
$result = pager_query($sql, 30, 0, $sql_cnt); | |
diff --git a/src/drupal/modules/taxonomy/taxonomy.module b/src/drupal/modules/taxonomy/taxonomy.module | |
index cb982b5..30669b9 100644 | |
--- a/src/drupal/modules/taxonomy/taxonomy.module | |
+++ b/src/drupal/modules/taxonomy/taxonomy.module | |
@@ -985,7 +985,7 @@ function _taxonomy_term_children($tid) { | |
* An array of matching term objects. | |
*/ | |
function taxonomy_get_term_by_name($name) { | |
- $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) = LOWER('%s')", 't', 'tid'), trim($name)); | |
+ $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE (t.name) = ('%s')", 't', 'tid'), trim($name)); | |
$result = array(); | |
while ($term = db_fetch_object($db_result)) { | |
$result[] = $term; | |
diff --git a/src/drupal/modules/taxonomy/taxonomy.pages.inc b/src/drupal/modules/taxonomy/taxonomy.pages.inc | |
index aa3e68d..2608e23 100644 | |
--- a/src/drupal/modules/taxonomy/taxonomy.pages.inc | |
+++ b/src/drupal/modules/taxonomy/taxonomy.pages.inc | |
@@ -118,7 +118,7 @@ function taxonomy_autocomplete($vid, $string = '') { | |
$last_string = trim(array_pop($array)); | |
$matches = array(); | |
if ($last_string != '') { | |
- $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10); | |
+ $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND (t.name) LIKE ('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10); | |
$prefix = count($array) ? implode(', ', $array) .', ' : ''; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment