Index: trunk/phase3/includes/LogEventsList.php |
— | — | @@ -938,12 +938,21 @@ |
939 | 939 | $this->mConds[] = 'user_id = log_user'; |
940 | 940 | $index = array(); |
941 | 941 | $options = array(); |
942 | | - # Add log_search table if there are conditions on it |
943 | | - if( array_key_exists('ls_field',$this->mConds) ) { |
| 942 | + # Add log_search table if there are conditions on it. |
| 943 | + # This filters the results to only include log rows that have |
| 944 | + # log_search records with the specified ls_field and ls_value values. |
| 945 | + if( array_key_exists( 'ls_field', $this->mConds ) ) { |
944 | 946 | $tables[] = 'log_search'; |
945 | 947 | $index['log_search'] = 'ls_field_val'; |
946 | 948 | $index['logging'] = 'PRIMARY'; |
947 | | - $options[] = 'DISTINCT'; |
| 949 | + if ( !$this->hasEqualsClause( 'ls_field' ) |
| 950 | + || !$this->hasEqualsClause( 'ls_value' ) ) |
| 951 | + { |
| 952 | + # Since (ls_field,ls_value,ls_logid) is unique, if the condition is |
| 953 | + # to match a specific (ls_field,ls_value) tuple, then there will be |
| 954 | + # no duplicate log rows. Otherwise, we need to remove the duplicates. |
| 955 | + $options[] = 'DISTINCT'; |
| 956 | + } |
948 | 957 | # Avoid usage of the wrong index by limiting |
949 | 958 | # the choices of available indexes. This mainly |
950 | 959 | # avoids site-breaking filesorts. |
— | — | @@ -967,7 +976,7 @@ |
968 | 977 | 'conds' => $this->mConds, |
969 | 978 | 'options' => $options, |
970 | 979 | 'join_conds' => array( |
971 | | - 'user' => array( 'INNER JOIN', 'user_id=log_user' ), |
| 980 | + 'user' => array( 'INNER JOIN', 'user_id=log_user' ), |
972 | 981 | 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' ) |
973 | 982 | ) |
974 | 983 | ); |
— | — | @@ -977,6 +986,14 @@ |
978 | 987 | return $info; |
979 | 988 | } |
980 | 989 | |
| 990 | + // Checks if $this->mConds has $field matched to a *single* value |
| 991 | + protected function hasEqualsClause( $field ) { |
| 992 | + return ( |
| 993 | + array_key_exists( $field, $this->mConds ) && |
| 994 | + ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 ) |
| 995 | + ); |
| 996 | + } |
| 997 | + |
981 | 998 | function getIndexField() { |
982 | 999 | return 'log_timestamp'; |
983 | 1000 | } |