dcausse added a comment.

  @Herzi.Pinki sorry to see that this problem is hitting your query again, I 
still believe that this might be a bug in blazegraph possibly related to how it 
optimizes it query plan.
  I think the section to cause much trouble to blazegraph is the named query:
  
    SELECT DISTINCT ?item WHERE {
        ?item wdt:P17 wd:Q40 ;
              wdt:P625 [] ;
              wdt:P31/wdt:P279* wd:Q271669 .
        minus {?item wdt:P31/wdt:P279* wd:Q46831 .}
        minus {?item wdt:P31/wdt:P279* wd:Q39816 .}
        filter not exists { ?item wdt:P131 [] }
    }
  
  I seem to obtain better performances by disabling the blazegraph optimizer 
(`hint:Query hint:optimizer "None". `):
  
    SELECT DISTINCT ?item WHERE {
        hint:Query hint:optimizer "None".  
        ?item wdt:P17 wd:Q40 ;
              wdt:P625 [] ;
              wdt:P31/wdt:P279* wd:Q271669 .
        minus {?item wdt:P31/wdt:P279* wd:Q46831 .}
        minus {?item wdt:P31/wdt:P279* wd:Q39816 .}
        filter not exists { ?item wdt:P131 [] }
    }
  
  But telling blazegraph to disable its optimizer we uncover yet another issue:
  `BIND(IF(EXISTS { ?item p:P18 [] }, '0000ff', 'ff0000') AS ?rgb)  .`
  no longer appears to work appropriately and have to be rewritten as:
  `BIND(IF(BOUND(?image), '0000ff', 'ff0000') AS ?rgb) .`
  reusing the `?image` var which is attached in an optional clause couple lines 
before.
  
  I took the liberty to attempt a rewrite of your query as:
  
    #defaultView:Map{"hide":"?rgb"}
    SELECT ?item ?itemLabel ?itemDescription (GROUP_CONCAT(DISTINCT 
?whereLabel; SEPARATOR=', ') AS ?whereLabels) (SAMPLE(?image) AS ?image) ?coord 
?rgb ?layer WITH {
      SELECT DISTINCT ?item WHERE {
        hint:Query hint:optimizer "None".  
        ?item wdt:P17 wd:Q40 .
        ?item wdt:P625 [] .
        ?item wdt:P31/wdt:P279* wd:Q271669 . #Q35145263 . # Q271669 . #
    
        #?item wdt:P31/wdt:P279* wd:Q35509 .
        minus {?item wdt:P31/wdt:P279* wd:Q46831 .}
    
        filter not exists {
          ?item wdt:P131 ?wo
          }
      #minus {?item wdt:P31/wdt:P279* wd:Q27686 .}
      #minus {?item wdt:P31/wdt:P279* wd:Q1444 .}
      minus {?item wdt:P31/wdt:P279* wd:Q39816 .}
      }
    } AS %subquery1 WHERE {
      INCLUDE %subquery1 .
      ?item wdt:P31 [] .
      ?item p:P625 ?coordStatement .
      ?coordStatement ps:P625 ?coord .
      #MINUS { ?coordStatement prov:wasDerivedFrom/pr:P143 wd:Q169514 } # 
imported from Wikimedia project: Swedish Wikipedia 
      #MINUS { ?coordStatement prov:wasDerivedFrom/pr:P143 wd:Q837615 } # 
imported from Wikimedia project: Cebuano Wikipedia 
      #MINUS { ?coordStatement prov:wasDerivedFrom/pr:P248 wd:Q1194038 } # 
stated in: GEOnet Names Server
      OPTIONAL {
        ?item wdt:P131 ?where .
        OPTIONAL {
          ?where rdfs:label ?whereLiteral .
          FILTER(LANG(?whereLiteral) = 'de') .
        }
      }
      BIND(IF(BOUND(?where), IF(BOUND(?whereLiteral), ?whereLiteral, 
STRAFTER(STR(?where), 'entity/')), 'no P131') AS ?whereLabel) .
      OPTIONAL { ?item wdt:P18 ?image }
      BIND(IF(BOUND(?image), '0000ff', 'ff0000') AS ?rgb) .
      BIND(IF(BOUND(?image), IF(BOUND(?where), 'With Image & P131', 'With Image 
but without P131'), IF(BOUND(?where), 'Without Image but with P131', 'Without 
Image and without P131')) AS ?layer) .
      SERVICE wikibase:label { bd:serviceParam wikibase:language 
'[AUTO_LANGUAGE,de,en]' }
    } GROUP BY ?item ?itemLabel ?itemDescription ?whereLabels ?coord ?rgb ?layer
  
  It does seem to be slightly faster, I also added two new layers to select of 
items with a P131 <https://phabricator.wikimedia.org/P131> (hoping that it 
might ease detecting when this similar bug happens).
  
  Please let us know if this rewritten query suits your needs and if it helps 
mitigate the issue you're experiencing.

TASK DETAIL
  https://phabricator.wikimedia.org/T350348

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: dcausse
Cc: Aklapper, dcausse, Herzi.Pinki, Danny_Benjafield_WMDE, Astuthiodit_1, 
AWesterinen, karapayneWMDE, Invadibot, maantietaja, ItamarWMDE, Akuckartz, 
Nandana, Namenlos314, Lahi, Gq86, Lucas_Werkmeister_WMDE, GoranSMilovanovic, 
QZanden, EBjune, merbst, LawExplorer, _jensen, rosalieper, Scott_WUaS, Jonas, 
Xmlizer, jkroll, Wikidata-bugs, Jdouglas, aude, Tobias1984, Manybubbles, Mbch331
_______________________________________________
Wikidata-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to