jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/351120 )

Change subject: Make registerTempTableOperation() detect TRUNCATE operations
......................................................................


Make registerTempTableOperation() detect TRUNCATE operations

Bug: T145947
Change-Id: I6094624fc594b23b1df6107f7ac1c3d93f609ebc
---
M includes/libs/rdbms/database/Database.php
1 file changed, 20 insertions(+), 6 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index 3bb7e6a..5f266e4 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -817,7 +817,7 @@
 
        /**
         * @param string $sql A SQL query
-        * @return bool Whether $sql is SQL for creating/dropping a new 
TEMPORARY table
+        * @return bool Whether $sql is SQL for TEMPORARY table operation
         */
        protected function registerTempTableOperation( $sql ) {
                if ( preg_match(
@@ -838,6 +838,12 @@
 
                        return $isTemp;
                } elseif ( preg_match(
+                       
'/^TRUNCATE\s+(?:TEMPORARY\s+)?TABLE\s+(?:IF\s+EXISTS\s+)?[`"\']?(\w+)[`"\']?/i',
+                       $sql,
+                       $matches
+               ) ) {
+                       return isset( $this->mSessionTempTables[$matches[1]] );
+               } elseif ( preg_match(
                        
'/^(?:INSERT\s+(?:\w+\s+)?INTO|UPDATE|DELETE\s+FROM)\s+[`"\']?(\w+)[`"\']?/i',
                        $sql,
                        $matches
@@ -852,8 +858,16 @@
                $priorWritesPending = $this->writesOrCallbacksPending();
                $this->mLastQuery = $sql;
 
-               $isWrite = $this->isWriteQuery( $sql ) && 
!$this->registerTempTableOperation( $sql );
+               $isWrite = $this->isWriteQuery( $sql );
                if ( $isWrite ) {
+                       $isNonTempWrite = !$this->registerTempTableOperation( 
$sql );
+               } else {
+                       $isNonTempWrite = false;
+               }
+
+               if ( $isWrite ) {
+                       # In theory, non-persistent writes are allowed in 
read-only mode, but due to things
+                       # like https://bugs.mysql.com/bug.php?id=33669 that 
might not work anyway...
                        $reason = $this->getReadOnlyReason();
                        if ( $reason !== false ) {
                                throw new DBReadOnlyError( $this, "Database is 
read-only: $reason" );
@@ -862,8 +876,8 @@
                        $this->mLastWriteTime = microtime( true );
                }
 
-               // Add trace comment to the begin of the sql string, right 
after the operator.
-               // Or, for one-word queries (like "BEGIN" or COMMIT") add it to 
the end (T44598)
+               # Add trace comment to the begin of the sql string, right after 
the operator.
+               # Or, for one-word queries (like "BEGIN" or COMMIT") add it to 
the end (T44598)
                $commentedSql = preg_replace( '/\s|$/', " /* $fname 
{$this->agent} */ ", $sql, 1 );
 
                # Start implicit transactions that wrap the request if DBO_TRX 
is enabled
@@ -889,7 +903,7 @@
                $this->assertOpen();
 
                # Send the query to the server
-               $ret = $this->doProfiledQuery( $sql, $commentedSql, $isWrite, 
$fname );
+               $ret = $this->doProfiledQuery( $sql, $commentedSql, 
$isNonTempWrite, $fname );
 
                # Try reconnecting if the connection was lost
                if ( false === $ret && $this->wasErrorReissuable() ) {
@@ -910,7 +924,7 @@
                                        $this->reportQueryError( $lastError, 
$lastErrno, $sql, $fname );
                                } else {
                                        # Should be safe to silently retry the 
query
-                                       $ret = $this->doProfiledQuery( $sql, 
$commentedSql, $isWrite, $fname );
+                                       $ret = $this->doProfiledQuery( $sql, 
$commentedSql, $isNonTempWrite, $fname );
                                }
                        } else {
                                $msg = __METHOD__ . ": lost connection to 
{$this->getServer()} permanently";

-- 
To view, visit https://gerrit.wikimedia.org/r/351120
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6094624fc594b23b1df6107f7ac1c3d93f609ebc
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to