Changed use of tag_summary to use change_tag with GROUP_CONCAT()

* Added buildGroupConcatField() method to the DB classes

bug: 53577
Change-Id: I976f297653880e66af429ba9b622a954fefcc512
This commit is contained in:
Aaron Schulz 2013-11-14 23:23:36 -08:00 committed by Springle
parent 2a0da3b558
commit a97402559b
5 changed files with 47 additions and 4 deletions

View file

@ -193,10 +193,9 @@ class ChangeTags {
throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' );
}
// JOIN on tag_summary
$tables[] = 'tag_summary';
$join_conds['tag_summary'] = array( 'LEFT JOIN', "ts_$join_cond=$join_cond" );
$fields[] = 'ts_tags';
$fields['ts_tags'] = wfGetDB( DB_SLAVE )->buildGroupConcatField(
',', 'change_tag', 'ct_tag', "ct_$join_cond=$join_cond"
);
if ( $wgUseTagFilter && $filter_tag ) {
// Somebody wants to filter on a tag.

View file

@ -2079,6 +2079,29 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
return 'CONCAT(' . implode( ',', $stringList ) . ')';
}
/**
* Build a GROUP_CONCAT or equivalent statement for a query.
*
* This is useful for combining a field for several rows into a single string.
* NULL values will not appear in the output, duplicated values will appear,
* and the resulting delimiter-separated values have no defined sort order.
* Code using the results may need to use the PHP unique() or sort() methods.
*
* @param string $delim Glue to bind the results together
* @param string|array $table Table name
* @param string $field Field name
* @param string|array $conds Conditions
* @param string|array $join_conds Join conditions
* @return String SQL text
* @since 1.23
*/
public function buildGroupConcatField(
$delim, $table, $field, $conds = '', $join_conds = array()
) {
$fld = "GROUP_CONCAT($field SEPARATOR " . $this->addQuotes( $delim ) . ')';
return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
}
/**
* Change the current database
*

View file

@ -1354,6 +1354,13 @@ class DatabaseOracle extends DatabaseBase {
return $this->mServer;
}
public function buildGroupConcatField(
$delim, $table, $field, $conds = '', $join_conds = array()
) {
$fld = "LISTAGG($field," . $this->addQuotes( $delim ) . ") WITHIN GROUP (ORDER BY $field)";
return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
}
public function getSearchEngine() {
return 'SearchOracle';
}

View file

@ -1431,6 +1431,13 @@ SQL;
return implode( ' || ', $stringList );
}
public function buildGroupConcatField(
$delimiter, $table, $field, $conds = '', $options = array(), $join_conds = array()
) {
$fld = "array_to_string(array_agg($field)," . $this->addQuotes( $delimiter ) . ')';
return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
}
public function getSearchEngine() {
return 'SearchPostgres';
}

View file

@ -828,6 +828,13 @@ class DatabaseSqlite extends DatabaseBase {
return '(' . implode( ') || (', $stringList ) . ')';
}
public function buildGroupConcatField(
$delim, $table, $field, $conds = '', $join_conds = array()
) {
$fld = "group_concat($field," . $this->addQuotes( $delim ) . ')';
return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
}
/**
* @throws MWException
* @param $oldName