1

我正在针对Wikidata 查询服务对Blazegraph RDF Graph 数据库进行 SPARQL 查询。这些查询涉及几个 UNION,通常是一个 FILTER

SELECT DISTINCT ?music_track ?music_trackLabel ?artist ?artistLabel ?album ?albumLabel ?publication_date WHERE {
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

      { ?music_track wdt:P31 wd:Q134556. }
      UNION
      { ?music_track wdt:P31 wd:Q7366. }
      UNION
      { ?music_track wdt:P31 wd:Q2188189. }
      UNION
      { ?music_track wdt:P31 wd:Q207628. }
      UNION
      { ?music_track wdt:P31 wd:Q7302866. }
      UNION
      { ?music_track wdt:P31 wd:Q9748. }
      UNION
      { ?music_track wdt:P2207 ?_spotifyTrackID_. }

      ?music_track rdfs:label ?music_trackLabel.

      ?music_track wdt:P175 ?artist. 
      ?artist rdfs:label ?artistLabel.

      OPTIONAL { ?music_track wdt:P361 ?album.}
      OPTIONAL { ?music_track wdt:P577 ?publication_date. }

      FILTER regex(?music_trackLabel, "^Castle on the Hill$", "i")
      FILTER (regex(?artistLabel, "ed sheeran", "i"))
    }
    LIMIT 10

或喜欢

SELECT DISTINCT ?artist ?artistLabel ?birth_nameLabel  ?date ?website ?instagramID ?facebookID ?twitterID ?musicBrainzArtistID WHERE {
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

    { ?artist wdt:P31 wd:Q215380. }
    UNION
    { ?artist wdt:P31 wd:Q2088357. }
    UNION
    { ?artist wdt:P31 wd:Q5741069. }
    UNION
    { ?artist wdt:P31 wd:Q641066. }
     UNION
    { ?artist wdt:P1902 ?_spotifyArtistID_. }
    UNION
    { ?artist wdt:P2850 ?_itunesArtistID_. }
    UNION
    { ?artist wdt:P434 ?musicBrainzArtistID. } 

      FILTER(REGEX(?artistLabel, "^Fall Out Boy$", "i"))
      ?artist rdfs:label ?artistLabel.

      OPTIONAL { ?artist wdt:P571 ?date. }
      OPTIONAL { ?artist wdt:P1477 ?birth_nameLabel. }
      OPTIONAL { ?artist wdt:P856 ?website. }
      OPTIONAL { ?artist wdt:P2003 ?instagramID. }
      OPTIONAL { ?artist wdt:P2013 ?facebookID. }
      OPTIONAL { ?artist wdt:P2002 ?twitterID. }


  }
  LIMIT 10

这些查询非常慢(从几秒到十多秒不等),我想优化这些查询。

使用 Blazegraph 仪表板,我做了一个查询 EXPLAIN,但我不了解如何优化以及优化什么。

4

0 回答 0