From: Domas Mituzas Date: Sat, 8 Apr 2006 09:22:33 +0000 (+0000) Subject: Fetch user_id before doing logging table scan, this helps a lot. X-Git-Tag: 1.31.0-rc.0~57550 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=7ddf03f2ca19d3a1ed86fddce850ea6140d91f29;p=lhc%2Fweb%2Fwiklou.git Fetch user_id before doing logging table scan, this helps a lot. Remove FORCE INDEX, STRAIGHT JOIN, refactor query building a bit. --- diff --git a/includes/SpecialLog.php b/includes/SpecialLog.php index 5281898275..c8b9a13691 100644 --- a/includes/SpecialLog.php +++ b/includes/SpecialLog.php @@ -61,8 +61,10 @@ class LogReader { function setupQuery( $request ) { $page = $this->db->tableName( 'page' ); $user = $this->db->tableName( 'user' ); - $this->joinClauses = array( "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title" ); - $this->whereClauses = array( 'user_id=log_user' ); + $this->joinClauses = array( + "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title", + "INNER JOIN $user ON user_id=log_user" ); + $this->whereClauses = array(); $this->limitType( $request->getVal( 'type' ) ); $this->limitUser( $request->getText( 'user' ) ); @@ -95,13 +97,19 @@ class LogReader { function limitUser( $name ) { if ( $name == '' ) return false; - $title = Title::makeTitle( NS_USER, $name ); - if ( is_null( $title ) ) + $usertitle = Title::makeTitle( NS_USER, $name ); + if ( is_null( $usertitle ) ) return false; - $this->user = $title->getText(); - $safename = $this->db->strencode( $this->user ); - $user = $this->db->tableName( 'user' ); - $this->whereClauses[] = "user_name='$safename'"; + $this->user = $usertitle->getText(); + + /* Fetch userid at first, if known, provides awesome query plan afterwards */ + $userid = $this->db->selectField('user','user_id',array('user_name'=>$this->user)); + if (!$userid) + /* It should be nicer to abort query at all, + but for now it won't pass anywhere behind the optimizer */ + $this->whereClauses[] = "NULL"; + else + $this->whereClauses[] = "log_user=$userid"; } /** @@ -147,12 +155,9 @@ class LogReader { $sql = "SELECT log_type, log_action, log_timestamp, log_user, user_name, log_namespace, log_title, page_id, - log_comment, log_params FROM $user, $logging "; - if ($this->type=="" && $this->db->indexExists('logging','times')) { - $sql .= ' /*! FORCE INDEX (times) */ '; - } + log_comment, log_params FROM $logging "; if( !empty( $this->joinClauses ) ) { - $sql .= implode( ',', $this->joinClauses ); + $sql .= implode( ' ', $this->joinClauses ); } if( !empty( $this->whereClauses ) ) { $sql .= " WHERE " . implode( ' AND ', $this->whereClauses );