From a2622536e99315033a53e8d9a4d9770c6f7cf813 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Wed, 18 Nov 2015 18:42:20 -0500 Subject: [PATCH] Fix SLOW DELETEs subject, predicate, object and labels are not indexed, thus, using a where clause on these fields for the DELETE statement does a full-table scan. Using *_hash columns instead will use the indexes. --- graph/sql/quadstore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graph/sql/quadstore.go b/graph/sql/quadstore.go index 24ff262..0977382 100644 --- a/graph/sql/quadstore.go +++ b/graph/sql/quadstore.go @@ -212,8 +212,8 @@ func (qs *QuadStore) runTxPostgres(tx *sql.Tx, in []graph.Delta, opts graph.Igno return err } case graph.Delete: - result, err := tx.Exec(`DELETE FROM quads WHERE subject=$1 and predicate=$2 and object=$3 and label=$4;`, - d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, d.Quad.Label) + result, err := tx.Exec(`DELETE FROM quads WHERE subject_hash=$1 and predicate_hash=$2 and object_hash=$3 and label_hash=$4;`, + hashOf(d.Quad.Subject), hashOf(d.Quad.Predicate), hashOf(d.Quad.Object), hashOf(d.Quad.Label)) if err != nil { glog.Errorf("couldn't exec DELETE statement: %v", err) return err