Skip to content

Very slow Fuseki FTS search queries for v4.21+ #462

Description

@jamiefeiss

When performing search via the /search endpoint for SEARCH_METHOD=fts_fuseki, versions 4.21 and above produce significantly slower SPARQL queries. I believe the ordering of pattern matches in the underlying SPARQL query may be the culprit.

I've tested the underlying query from multiple versions, and propose to move the pattern match below the nested select block.

Average response times (SPARQL straight to Fuseki):

v4.20 v4.21+ Proposed Fix
~0.06s ~13.5s ~0.06s
CONSTRUCT {
    ?focus_node <https://prez.dev/type> <https://prez.dev/FocusNode> .
    ?focus_node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?prof_1_node_1 .
    ?focus_node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?prof_1_node_1 .
    ?hashID <https://prez.dev/searchResultWeight> ?weight .
    ?hashID <https://prez.dev/searchResultPredicate> ?pred .
    ?hashID <https://prez.dev/searchResultMatch> ?match .
    ?hashID <https://prez.dev/searchResultURI> ?focus_node .
    ?hashID <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://prez.dev/SearchResult>
}
WHERE {
    {
        SELECT DISTINCT ?focus_node ?pred ?match ?weight (URI(CONCAT ("urn:hash:", SHA256(CONCAT (STR(?focus_node), STR(?pred), STR(?match), STR(?weight))))) AS ?hashID)
        WHERE {
            ?focus_node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?prof_1_node_1 . # introduced in v4.21
            ?focus_node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?default_class_var . # introduced in v4.23.1, replaces above line
            {
                {
                    (?focus_node ?weight ?match ?g ?pred ) <http://jena.apache.org/text#query> (<http://www.w3.org/2000/01/rdf-schema#label> <http://www.w3.org/2004/02/skos/core#prefLabel> <http://www.w3.org/2004/02/skos/core#altLabel> <http://www.w3.org/2004/02/skos/core#hiddenLabel> <https://schema.org/name> <http://purl.org/dc/terms/title> "sea" ) .
                    FILTER (!ISBLANK(?focus_node))
                }
            }
        }
        ORDER BY DESC (?weight)
        LIMIT 11
        OFFSET 0
    }
    ?focus_node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?prof_1_node_1 .
    ?focus_node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?default_class_var . # proposed move here
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions