Page MenuHomePhabricator

Type mismatch when caching SMW IDs
Closed, ResolvedPublic

Description

Author: allex

Description:
MediaWiki 1.22.1 (721b9e0) 22:03, 14 January 2014
Semantic MediaWiki (Version 1.9 alpha-3) (9a55761) 19:21, 22 October 2013

mediawiki/extensions/SemanticMediaWiki/includes/storage/SQLStore:

(SMW_Sql3SmwIds.php)SMWSql3SmwIds->setCache() is called from

(SMW_SQLStore3_Queries.php)SMWSQLStore3QueryEngine->getInstanceQueryResult()

with $id that is string, not integer as documented for setCache.

In most cases it is not a problem, php cast values automatically.
But arrays containing ids are serialized
when hashes for property tables are computed.
In this case, types of ids are important - serialized arrays differs
and md5 hashes also differs.

For example (take a look at s_id or p_id):

smw_di_wikipage data:
a:2:{i:0;a:3:{s:4:"s_id";i:53;s:4:"p_id";i:55;s:4:"o_id";s:2:"51";}i:1;a:3:{s:4:"s_id";i:53;s:4:"p_id";i:56;s:4:"o_id";i:57;}}

a:2:{i:0;a:3:{s:4:"s_id";s:2:"53";s:4:"p_id";s:2:"55";s:4:"o_id";s:2:"51";}i:1;a:3:{s:4:"s_id";s:2:"53";s:4:"p_id";s:2:"56";s:4:"o_id";s:2:"57";}}

These hashes are used to compare new semantic data
with current semantic data stored in database to avoid unnecessary writes.

Fortunately functionality is not affected, only performance.

I propose to add explicit type cast in (SMW_Sql3SmwIds.php)SMWSql3SmwIds->setCache() method
to make sure ids are always integer.


Version: unspecified
Severity: normal
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=53034

Details

Reference
bz60213

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:05 AM
bzimport set Reference to bz60213.
bzimport added a subscriber: Unknown Object (MLST).
Unknown Object (User) added a comment.Jan 18 2014, 9:11 PM

As site note, you may want to use the released 1.9.0.2 version for verification and post a PR via [1].

[1] https://github.com/SemanticMediaWiki/SemanticMediaWiki

allex wrote:

@mwjames, I've upgraded my SMW to 1.9.0.2, no relevant changes were made.
So, pull request is created.