Page MenuHomePhabricator

Warning: SQLPlatform::isWriteQuery fallback to regex (from ApiQueryRevisions)
Closed, ResolvedPublic

Description

Similar to T332941: Warning: SQLPlatform::isWriteQuery fallback to regex (from Wikibase EntityUsageTable):

@Krinkle wrote:

The immediate reason for the warning is that it is calling query() without indication of whether it is a write query or not, thus requiring Rdbms to perform its legacy regexes on the SQL text to guess it.

However, more important than whether it passes the second parameter of query(), is that it calls query() at all, as this should not be used outside Rdbms internals. It exposes raw SQL and should be avoided in favour of safe interfaces like SelectQueryBuilder or IDatabase::select().

Triggered around 28K/hour. Like the Wikibase violation above, this too is due the API code using IDatabase::unionQueries(). It seems the Rdbms library currently doesn't offer any other way to run union queries.

Wikimedia\Rdbms\Platform\SQLPlatform::isWriteQuery fallback to regex
#0 /srv/mediawiki/php-1.41.0-wmf.1/includes/libs/rdbms/database/Database.php(934): Wikimedia\Rdbms\Platform\SQLPlatform->isWriteQuery(string, integer)
…
#4 /srv/mediawiki/php-1.41.0-wmf.1/includes/api/ApiQueryRevisions.php(261): Wikimedia\Rdbms\DBConnRef->query(string, string)
#5 /srv/mediawiki/php-1.41.0-wmf.1/includes/api/ApiQueryRevisionsBase.php(136): ApiQueryRevisions->run()
#6 /srv/mediawiki/php-1.41.0-wmf.1/includes/api/ApiQuery.php(679): ApiQueryRevisionsBase->execute()
#7 /srv/mediawiki/php-1.41.0-wmf.1/includes/api/ApiMain.php(1906): ApiQuery->execute()
#8 /srv/mediawiki/php-1.41.0-wmf.1/includes/api/ApiMain.php(883): ApiMain->executeAction()
#9 /srv/mediawiki/php-1.41.0-wmf.1/includes/api/ApiMain.php(854): ApiMain->executeActionWithErrorHandling()
#10 /srv/mediawiki/php-1.41.0-wmf.1/api.php(91): ApiMain->execute()
#11 /srv/mediawiki/php-1.41.0-wmf.1/api.php(46): wfApiMain()
#12 /srv/mediawiki/w/api.php(3): require(string)
#13 {main}

Event Timeline

Change 903211 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@master] api: Mark query as read-only to avoid regex on SQL

https://gerrit.wikimedia.org/r/903211

Change 903211 merged by jenkins-bot:

[mediawiki/core@master] api: Mark query as read-only to avoid regex on SQL

https://gerrit.wikimedia.org/r/903211

Can this task be closed now?

It got merged today, I'm planning to deploy this tomorrow and until then it shouldn't be closed, otherwise people might see the warning and create it again.

Change 903549 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@wmf/1.41.0-wmf.1] api: Mark query as read-only to avoid regex on SQL

https://gerrit.wikimedia.org/r/903549

Change 903549 merged by jenkins-bot:

[mediawiki/core@wmf/1.41.0-wmf.1] api: Mark query as read-only to avoid regex on SQL

https://gerrit.wikimedia.org/r/903549

Mentioned in SAL (#wikimedia-operations) [2023-03-28T11:32:57Z] <ladsgroup@deploy2002> Started scap: Backport for [[gerrit:903549|api: Mark query as read-only to avoid regex on SQL (T332942)]]

Mentioned in SAL (#wikimedia-operations) [2023-03-28T11:34:24Z] <ladsgroup@deploy2002> ladsgroup: Backport for [[gerrit:903549|api: Mark query as read-only to avoid regex on SQL (T332942)]] synced to the testservers: mwdebug2001.codfw.wmnet, mwdebug1001.eqiad.wmnet, mwdebug1002.eqiad.wmnet, mwdebug2002.codfw.wmnet

Mentioned in SAL (#wikimedia-operations) [2023-03-28T11:51:40Z] <ladsgroup@deploy2002> Finished scap: Backport for [[gerrit:903549|api: Mark query as read-only to avoid regex on SQL (T332942)]] (duration: 18m 42s)

Ladsgroup claimed this task.

Change 904206 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Amir Sarabadani):

[mediawiki/core@REL1_40] api: Mark query as read-only to avoid regex on SQL

https://gerrit.wikimedia.org/r/904206

Change 904206 merged by jenkins-bot:

[mediawiki/core@REL1_40] api: Mark query as read-only to avoid regex on SQL

https://gerrit.wikimedia.org/r/904206