Skip to content

Index is not used for bound variables #1

@Gundolf68

Description

@Gundolf68

Hi,

first of all, I would like to express my enthusiasm for the very elegant implementation: This could serve as a perfect textbook example of Functional Programming.
I would have one small suggestion for improvement: In the function "relevantTriples" already bound variables are not considered. This can have big disadvantages in performance in practice, because the optimal index is not chosen. This could be solved by passing the context to the function:

function relevantTriples(pattern, db, context) {
  const [id, attribute, value] = pattern;
  if (!isVariable(id))
    return db.entityIndex[id];
  if (context[id])
    return db.entityIndex[context[id]];
  if (!isVariable(value)) 
    return db.valueIndex[value];
  if (context[value]) 
    return db.entityIndex[context[value]];
  if (!isVariable(attribute))
    return db.attrIndex[attribute];
  if (context[attribute]) 
    return db.entityIndex[context[attribute]];
  return db.triples;
}

Also the sequence plays a role: First the id, as second value and last attribute, since in practice this sequence might have the largest influence on the performance.

Greetings
Bernd

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions