Commit ff386b90 authored by Steven Wittens's avatar Steven Wittens
Browse files

#17747: PGSQL improvements

parent a203f728
......@@ -1961,7 +1961,7 @@ function update_110() {
#$ret[] = update_sql('ALTER TABLE {blocks} DROP path');
$ret[] = update_sql('ALTER TABLE {blocks} ADD visibility smallint');
$ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN type set default ''");
$ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN visibility set default 0");
$ret[] = update_sql('UPDATE {blocks} SET visibility = 0');
$ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN visibility SET NOT NULL');
$ret[] = update_sql('ALTER TABLE {blocks} ADD pages text');
......@@ -2291,7 +2291,7 @@ function update_125() {
if ($GLOBALS['db_type'] == 'pgsql') {
$ret[] = update_sql[] = ("CREATE FUNCTION "if"(boolean, anyelement, anyelement) RETURNS anyelement AS '
$ret[] = update_sql("CREATE OR REPLACE FUNCTION if(boolean, anyelement, anyelement) RETURNS anyelement AS '
SELECT CASE WHEN $1 THEN $2 ELSE $3 END;
' LANGUAGE 'sql'");
......
......@@ -21,11 +21,11 @@ function sess_close() {
function sess_read($key) {
global $user;
$uid = (isset($user->uid)) ? $user-uid : 0;
$result = db_query_range("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s' AND u.status < 3", $key, 0, 1);
if (!db_num_rows($result)) {
db_query("INSERT INTO {sessions} (sid, hostname, timestamp) values('%s', '%s', %d)", $key, $_SERVER["REMOTE_ADDR"], time());
db_query("INSERT INTO {sessions} (sid, uid, hostname, timestamp) VALUES ('%s', %d, '%s', %d)", $key, $uid, $_SERVER["REMOTE_ADDR"], time());
$result = db_query("SELECT u.* FROM {users} u WHERE u.uid = 0");
}
......
......@@ -582,7 +582,7 @@ function node_search($op = 'search', $keys = null) {
case 'status':
$last = variable_get('node_cron_last', 0);
$total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND moderate = 0'));
$remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last));
$remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d)', $last, $last, $last));
return array('remaining' => $remaining, 'total' => $total);
case 'search':
list($join, $where) = _db_rewrite_sql();
......
......@@ -582,7 +582,7 @@ function node_search($op = 'search', $keys = null) {
case 'status':
$last = variable_get('node_cron_last', 0);
$total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND moderate = 0'));
$remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last));
$remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d)', $last, $last, $last));
return array('remaining' => $remaining, 'total' => $total);
case 'search':
list($join, $where) = _db_rewrite_sql();
......
......@@ -511,7 +511,7 @@ function do_search($keys, $type, $join = '', $where = '1') {
$count_query = "SELECT $count";
// Do pager query
$query = "SELECT i.type, i.sid, i.word, SUM(i.score/t.count) AS score FROM {search_index} i $join INNER JOIN {search_total} t ON i.word = t.word WHERE $where GROUP BY i.type, i.sid ORDER BY score DESC";
$query = "SELECT i.type, i.sid, SUM(i.score/t.count) AS score FROM {search_index} i $join INNER JOIN {search_total} t ON i.word = t.word WHERE $where GROUP BY i.type, i.sid ORDER BY score DESC";
$result = pager_query($query, 15, 0, $count_query, $arguments);
$results = array();
......
......@@ -511,7 +511,7 @@ function do_search($keys, $type, $join = '', $where = '1') {
$count_query = "SELECT $count";
// Do pager query
$query = "SELECT i.type, i.sid, i.word, SUM(i.score/t.count) AS score FROM {search_index} i $join INNER JOIN {search_total} t ON i.word = t.word WHERE $where GROUP BY i.type, i.sid ORDER BY score DESC";
$query = "SELECT i.type, i.sid, SUM(i.score/t.count) AS score FROM {search_index} i $join INNER JOIN {search_total} t ON i.word = t.word WHERE $where GROUP BY i.type, i.sid ORDER BY score DESC";
$result = pager_query($query, 15, 0, $count_query, $arguments);
$results = array();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment