optional index strategies
This commit is contained in:
parent
3f391a782c
commit
da391c3db7
2 changed files with 27 additions and 7 deletions
|
|
@ -95,12 +95,11 @@ func NewIterator(qs *QuadStore, d quad.Direction, val graph.Value) *Iterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAllIterator(qs *QuadStore, table string) *Iterator {
|
func NewAllIterator(qs *QuadStore, table string) *Iterator {
|
||||||
var size int64
|
|
||||||
it := &Iterator{
|
it := &Iterator{
|
||||||
uid: iterator.NextUID(),
|
uid: iterator.NextUID(),
|
||||||
qs: qs,
|
qs: qs,
|
||||||
dir: quad.Any,
|
dir: quad.Any,
|
||||||
size: size,
|
size: qs.Size(),
|
||||||
table: table,
|
table: table,
|
||||||
isAll: true,
|
isAll: true,
|
||||||
}
|
}
|
||||||
|
|
@ -255,7 +254,7 @@ func (it *Iterator) Describe() graph.Description {
|
||||||
|
|
||||||
func (it *Iterator) Stats() graph.IteratorStats {
|
func (it *Iterator) Stats() graph.IteratorStats {
|
||||||
size, _ := it.Size()
|
size, _ := it.Size()
|
||||||
if it.table == "nodes" {
|
if it.table == "nodes" || it.isAll {
|
||||||
return graph.IteratorStats{
|
return graph.IteratorStats{
|
||||||
ContainsCost: 1,
|
ContainsCost: 1,
|
||||||
NextCost: 9999,
|
NextCost: 9999,
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,31 @@ func createSQLTables(addr string, options graph.Options) error {
|
||||||
glog.Errorf("Cannot create quad table: %v", quadTable)
|
glog.Errorf("Cannot create quad table: %v", quadTable)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
index, err := tx.Exec(`
|
idxStrat, _, err := options.StringKey("db_index_strategy")
|
||||||
CREATE INDEX pos_index ON quads (predicate, object, subject) WITH (FILLFACTOR = 50);
|
factor, factorOk, err := options.IntKey("db_fill_factor")
|
||||||
CREATE INDEX osp_index ON quads (object, subject, predicate) WITH (FILLFACTOR = 50);
|
if !factorOk {
|
||||||
`)
|
factor = 50
|
||||||
|
}
|
||||||
|
var index sql.Result
|
||||||
|
if idxStrat == "brin" {
|
||||||
|
index, err = tx.Exec(`
|
||||||
|
CREATE INDEX spo_index ON quads USING brin(subject) WITH (pages_per_range = 32);
|
||||||
|
CREATE INDEX pos_index ON quads USING brin(predicate) WITH (pages_per_range = 32);
|
||||||
|
CREATE INDEX osp_index ON quads USING brin(object) WITH (pages_per_range = 32);
|
||||||
|
`)
|
||||||
|
} else if idxStrat == "prefix" {
|
||||||
|
index, err = tx.Exec(fmt.Sprintf(`
|
||||||
|
CREATE INDEX spo_index ON quads (substr(subject, 0, 8)) WITH (FILLFACTOR = %d);
|
||||||
|
CREATE INDEX pos_index ON quads (substr(predicate, 0, 8)) WITH (FILLFACTOR = %d);
|
||||||
|
CREATE INDEX osp_index ON quads (substr(object, 0, 8)) WITH (FILLFACTOR = %d);
|
||||||
|
`, factor, factor, factor))
|
||||||
|
} else {
|
||||||
|
index, err = tx.Exec(fmt.Sprintf(`
|
||||||
|
CREATE INDEX spo_index ON quads (subject, predicate, object) WITH (FILLFACTOR = %d);
|
||||||
|
CREATE INDEX pos_index ON quads (predicate, object, subject) WITH (FILLFACTOR = %d);
|
||||||
|
CREATE INDEX osp_index ON quads (object, subject, predicate) WITH (FILLFACTOR = %d);
|
||||||
|
`, factor, factor, factor))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Cannot create indices: %v", index)
|
glog.Errorf("Cannot create indices: %v", index)
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue