rdbms: add IDatabase::UNION_* constants for readability
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 28 Mar 2019 17:58:42 +0000 (10:58 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 28 Mar 2019 18:01:02 +0000 (11:01 -0700)
Change-Id: I0d39242d1c4bd8c2236f0b0cd21eb3f604b7d2bd

includes/api/ApiQueryRevisions.php
includes/libs/rdbms/database/IDatabase.php
includes/specials/SpecialRecentchangeslinked.php
maintenance/findOrphanedFiles.php

index 3781ab0..7e46c1a 100644 (file)
@@ -268,7 +268,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                                                [ 'ar_rev_id' => $revids ],
                                                __METHOD__
                                        ),
-                               ], false );
+                               ], $db::UNION_DISTINCT );
                                $res = $db->query( $sql, __METHOD__ );
                                foreach ( $res as $row ) {
                                        if ( (int)$row->id === (int)$params['startid'] ) {
index eac9bae..b4440d6 100644 (file)
@@ -114,6 +114,11 @@ interface IDatabase {
         */
        const QUERY_PSEUDO_PERMANENT = 2;
 
+       /** @var bool Parameter to unionQueries() for UNION ALL */
+       const UNION_ALL = true;
+       /** @var bool Parameter to unionQueries() for UNION DISTINCT */
+       const UNION_DISTINCT = false;
+
        /**
         * A string describing the current software version, and possibly
         * other details in a user-friendly way. Will be listed on Special:Version, etc.
@@ -1384,7 +1389,7 @@ interface IDatabase {
         * This is used for providing overload point for other DB abstractions
         * not compatible with the MySQL syntax.
         * @param array $sqls SQL statements to combine
-        * @param bool $all Use UNION ALL
+        * @param bool $all Either IDatabase::UNION_ALL or IDatabase::UNION_DISTINCT
         * @return string SQL fragment
         */
        public function unionQueries( $sqls, $all );
index 62c867b..8865654 100644 (file)
@@ -224,7 +224,8 @@ class SpecialRecentChangesLinked extends SpecialRecentChanges {
                        $sql = $subsql[0];
                } else {
                        // need to resort and relimit after union
-                       $sql = $dbr->unionQueries( $subsql, false ) . ' ORDER BY rc_timestamp DESC';
+                       $sql = $dbr->unionQueries( $subsql, $dbr::UNION_DISTINCT ) .
+                               ' ORDER BY rc_timestamp DESC';
                        $sql = $dbr->limitResult( $sql, $limit, false );
                }
 
index 57e04e0..e81e197 100644 (file)
@@ -117,7 +117,7 @@ class FindOrphanedFiles extends Maintenance {
                                                $oiWheres ? $dbr->makeList( $oiWheres, LIST_OR ) : '1=0'
                                        )
                                ],
-                               true // UNION ALL (performance)
+                               $dbr::UNION_ALL
                        ),
                        __METHOD__
                );