Database: Recognize USE queries as non-write queries
authorRoan Kattouw <roan.kattouw@gmail.com>
Wed, 12 Jun 2019 23:29:50 +0000 (16:29 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Wed, 12 Jun 2019 23:33:24 +0000 (16:33 -0700)
This should unbreak Ie7341a0e6c41, which switched
DatabaseMysql::doSelectDomain() from using doQuery() to using
executeQuery() for its USE query, which means it no longer
bypasses the isWriteQuery() check. This caused every USE query on a
replica DB to fail, because it was considered a write query.

Bug: T225682
Bug: T212284
Change-Id: Iecb8b9f6e64d08df8c64b3133078b5324e654ed1
Follows-Up: Ie7341a0e6c4149fc375cc357877486efe9e56eb9

includes/libs/rdbms/database/Database.php

index ab718ec..a2caa96 100644 (file)
@@ -1120,11 +1120,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                // for all queries within a request. Use cases:
                // - Treating these as writes would trigger ChronologyProtector (see method doc).
                // - We use this method to reject writes to replicas, but we need to allow
-               //   use of transactions on replicas for read snapshots. This fine given
+               //   use of transactions on replicas for read snapshots. This is fine given
                //   that transactions by themselves don't make changes, only actual writes
                //   within the transaction matter, which we still detect.
                return !preg_match(
-                       '/^(?:SELECT|BEGIN|ROLLBACK|COMMIT|SAVEPOINT|RELEASE|SET|SHOW|EXPLAIN|\(SELECT)\b/i',
+                       '/^(?:SELECT|BEGIN|ROLLBACK|COMMIT|SAVEPOINT|RELEASE|SET|SHOW|EXPLAIN|USE|\(SELECT)\b/i',
                        $sql
                );
        }