Last modified: 2014-02-03 20:10:29 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T41635, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 39635 - PostgreSQL LOCK IN SHARE MODE option is a syntax error
PostgreSQL LOCK IN SHARE MODE option is a syntax error
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Database (Other open bugs)
1.19.0
All All
: Normal major (vote)
: ---
Assigned To: Christopher John Harrington
:
: 46594 (view as bug list)
Depends on:
Blocks: postgres
  Show dependency treegraph
 
Reported: 2012-08-24 23:44 UTC by Christopher John Harrington
Modified: 2014-02-03 20:10 UTC (History)
10 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Avoid SQL Syntax Error on Postgres (952 bytes, patch)
2012-08-24 23:51 UTC, Christopher John Harrington
Details

Description Christopher John Harrington 2012-08-24 23:44:18 UTC
When refreshing a category page, MediaWiki issues a query to my PostgreSQL backend ending in "LOCK IN SHARED MODE". This isn't valid syntax to PGSQL.

I have edited my copy of includes/db/Database.php, DatabaseBase::selectSQLText() to include...

                if ($this->getType() == 'postgres' and
                        (in_array('LOCK IN SHARE MODE', $options, true) or
                        isset($options['LOCK IN SHARE MODE'])))
                {
                        // just fail       
                        //throw new Exception('Cannot use LOCK IN SHARE MODE with Postgresql');
                        // or just remove the option
                        unset($options['LOCK IN SHARE MODE']);
                        unset($options[array_search('LOCK IN SHARE MODE', $options, true)]);
                }

The lack of a locking operation seems to me to be a better tradeoff than a category page flooded with pg_query error output.
Comment 1 Christopher John Harrington 2012-08-24 23:51:54 UTC
Created attachment 10999 [details]
Avoid SQL Syntax Error on Postgres
Comment 2 Christopher John Harrington 2012-08-25 20:14:24 UTC
Add keywords that might help identify how trivial the fix is...
Comment 3 OverlordQ 2012-08-25 23:40:47 UTC
What are the steps to reproduce this? I cannot say I've ran into this issue.
Comment 4 Christopher John Harrington 2012-08-25 23:55:46 UTC
Viewing a category page reproduces it for me after creating about 20 articles in various categories from a clean install.

I can uncomment the exception line and generate a backtrace if that's useful.

Gentoo Linux (`portage` versions listed)
MediaWiki 1.19.1 (not available from this Bugzilla's version selector)
PostgreSQL 9.1.4-r1
Apache 2.2.22-r1
PHP 5.4.6
Comment 5 Christopher John Harrington 2012-08-26 15:44:16 UTC
Just to add more comment spam (sorry) it's worth noting that the patch is sane even if this isn't a bug in current code, since the 'LOCK IN SHARED MODE' isn't valid syntax in Postgres, and will always fail. Hence why I left an exception there (but commented) as an option instead of silently discarding the flag, as that particular flag simply doesn't make sense with Postgres and should be treated as a bug.

I assume Mediawiki has some sort of assert() construct, though I'm not a MW dev so I'm not aware of it. If so, that might be a smarter approach.
Comment 6 Marcin Cieślak 2012-08-27 16:55:02 UTC
This is was added in r32085 to bring in "Category" object. I wonder if this construct shouldn't really become "SELECT FOR UPDATE" instead?

I think we should really patch it like this:

iff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php
index 8f8f5e8..457bf38 100644
--- a/includes/db/DatabasePostgres.php
+++ b/includes/db/DatabasePostgres.php
@@ -1406,9 +1406,6 @@ SQL;
                if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
                        $postLimitTail .= ' FOR UPDATE';
                }
-               if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) {
-                       $postLimitTail .= ' LOCK IN SHARE MODE';
-               }
                if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) {
                        $startOpts .= 'DISTINCT';
                }

Since getting the code path in question executed is not easy (I can't reproduce the problem right now), can you see if this patch helps?
Comment 7 Marcin Cieślak 2012-08-27 17:01:17 UTC
Patch filed as Gerrit change #21606
Comment 8 Dereckson 2012-08-28 12:12:19 UTC
Thank you for your patch. It has been successfully merged into the git repository this night.

In the future, if you're willing to submit patch, you can request a developer access, to be able to push code directly in our code review (Gerrit) infrastructure.

[Removing Linux platform, issue isn't OS depending. Pruning keywords. Bug assigned to code submitter. Resolved fixed.]
Comment 9 Dereckson 2012-08-28 12:13:15 UTC
(In reply to comment #8)
> In the future, if you're willing to submit patch, you can request a developer
> access, to be able to push code directly in our code review (Gerrit)
> infrastructure.

You can do so at https://www.mediawiki.org/wiki/Developer_access
Comment 10 Umherirrender 2014-02-03 20:10:29 UTC
*** Bug 46594 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links