From a97402559b540052fc54ddce830cca1f5d7464a2 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 14 Nov 2013 23:23:36 -0800 Subject: [PATCH] Changed use of tag_summary to use change_tag with GROUP_CONCAT() * Added buildGroupConcatField() method to the DB classes bug: 53577 Change-Id: I976f297653880e66af429ba9b622a954fefcc512 --- includes/ChangeTags.php | 7 +++---- includes/db/Database.php | 23 +++++++++++++++++++++++ includes/db/DatabaseOracle.php | 7 +++++++ includes/db/DatabasePostgres.php | 7 +++++++ includes/db/DatabaseSqlite.php | 7 +++++++ 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php index 7ec641d9d6..3c734c4e69 100644 --- a/includes/ChangeTags.php +++ b/includes/ChangeTags.php @@ -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. diff --git a/includes/db/Database.php b/includes/db/Database.php index c677d7437a..e2c59edb6b 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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 * diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 97070fb863..6b4113e9a1 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -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'; } diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 72371a25a8..46880009cd 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -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'; } diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 79a3b1ecf3..84f1bcf3b4 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -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 -- 2.20.1