Page MenuHomePhabricator

Checking if a book is an instance of work is slow without explicit gearing hint
Open, LowPublic

Description

This query, without caching, takes about six seconds, sometimes up to eight:

ASK { wd:Q6012487 wdt:P31/wdt:P279* wd:Q386724. }

With explicit gearing hint, it takes less than half a second:

ASK { wd:Q6012487 wdt:P31/wdt:P279* wd:Q386724. hint:Prior hint:gearing "forward". }

This is the kind of query (does x have class y?) that we’ll run very often for WikibaseQualityConstraints type checks, so it would be great if it performed well without such optimizer hand-holding. (We also set the maxQueryTimeMillis URL parameter that BlazeGraph supports, so a long query runtime, even if below the default 60 s timeout, can result in false positives (constraint violations) for us.)

This query, on the other hand, which in a way inlines the start of the path (Q6012487 has only a single P​31 statement), runs just as fast with and without gearing hint:

ASK { wd:Q571 wdt:P279* wd:Q386724. }

I assume BlazeGraph chooses the forward hearing for this query by default, for whatever reason. (With explicit "reverse" gearing hint, it takes about as long as the original query without hint.)

And finally, just to paint the full picture, the query we actually use in WikibaseQualityConstraints for type checking is this:

ASK {
  BIND(wd:Q6012487 AS ?item)
  VALUES ?class { wd:Q386724 }
  ?item wdt:P31/wdt:P279* ?class.
}

since there can be multiple permitted classes. This currently behaves just like the original query both with and without gearing hint, but it would be unfortunate if the fix for this bug only affected the first query but not the one we actually use :)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 361687 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/WikibaseQualityConstraints@master] Add explicit gearing hint to type query

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

Change 361687 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Add explicit gearing hint to type query

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