MDL-22910 workaround for inability of Oracle and MS sql to find distinct text fields, improved perf in all dbs

This commit is contained in:
Petr Skoda 2010-06-30 20:42:11 +00:00
parent 9e39483a01
commit eae1948cee
4 changed files with 9 additions and 6 deletions

View File

@ -299,7 +299,8 @@ $sqltotal = "SELECT COUNT(DISTINCT u.id)
JOIN {enrol} e ON (e.id = ue.enrolid)";
$totalusers = $DB->count_records_sql($sqltotal, $params);
$sql = "SELECT DISTINCT u.*, ul.timeaccess AS lastseen
$ufields = user_picture::fields('u');
$sql = "SELECT DISTINCT $ufields, ul.timeaccess AS lastseen
FROM {user} u
JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid $instancessql)
JOIN {enrol} e ON (e.id = ue.enrolid)

View File

@ -296,10 +296,10 @@ class user_picture implements renderable {
* List of mandatory fields in user record here.
* @var string
*/
const FIELDS = 'id,picture,firstname,lastname,imagealt';
const FIELDS = 'id,picture,firstname,lastname,imagealt,email'; //note: the email will be useful for gravatar support int the future ;-)
/**
* @var object $user A user object with at least fields id, picture, imagealt, firstname and lastname set.
* @var object $user A user object with at least fields all columns specified in FIELDS constant set.
*/
public $user;
/**

View File

@ -827,7 +827,8 @@ function feedback_get_complete_users($cm, $group = false, $where, $sort = '', $s
$sortsql = '';
}
$sql = 'SELECT DISTINCT u.* FROM {user} u, {feedback_completed} c'.$fromgroup.'
$ufields = user_picture::fields('u');
$sql = 'SELECT DISTINCT '.$ufields.' FROM {user} u, {feedback_completed} c'.$fromgroup.'
WHERE '.$where.' anonymous_response = ? AND u.id = c.userid AND c.feedback = ?
'.$wheregroup.$sortsql;
;

View File

@ -242,9 +242,10 @@ switch ($mode) {
list($usql, $parameters) = $DB->get_in_or_equal(array_keys($pages));
if ($essayattempts = $DB->get_records_select('lesson_attempts', 'pageid '.$usql, $parameters)) {
// Get all the users who have taken this lesson, order by their last name
$ufields = user_picture::fields('u');
if (!empty($cm->groupingid)) {
$params["groupinid"] = $cm->groupingid;
$sql = "SELECT DISTINCT u.*
$sql = "SELECT DISTINCT $ufields
FROM {lesson_attempts} a
INNER JOIN {user} u ON u.id = a.userid
INNER JOIN {groups_members} gm ON gm.userid = u.id
@ -252,7 +253,7 @@ switch ($mode) {
WHERE a.lessonid = :lessonid
ORDER BY u.lastname";
} else {
$sql = "SELECT DISTINCT u.*
$sql = "SELECT DISTINCT $ufields
FROM {user} u,
{lesson_attempts} a
WHERE a.lessonid = :lessonid and