Merge pull request #336 from Quentin-M/master
Use a Size() estimate for SQL Quadstore when noSizes is enabled.
This commit is contained in:
commit
6027e4c48b
1 changed files with 23 additions and 6 deletions
|
|
@ -42,6 +42,7 @@ type QuadStore struct {
|
||||||
size int64
|
size int64
|
||||||
lru *cache
|
lru *cache
|
||||||
noSizes bool
|
noSizes bool
|
||||||
|
useEstimates bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectSQLTables(addr string, _ graph.Options) (*sql.DB, error) {
|
func connectSQLTables(addr string, _ graph.Options) (*sql.DB, error) {
|
||||||
|
|
@ -132,6 +133,11 @@ func newQuadStore(addr string, options graph.Options) (graph.QuadStore, error) {
|
||||||
qs.noSizes = false
|
qs.noSizes = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qs.useEstimates, _, err = options.BoolKey("use_estimates")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &qs, nil
|
return &qs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,7 +292,18 @@ func (qs *QuadStore) Size() int64 {
|
||||||
if qs.size != -1 {
|
if qs.size != -1 {
|
||||||
return qs.size
|
return qs.size
|
||||||
}
|
}
|
||||||
c := qs.db.QueryRow("SELECT COUNT(*) FROM quads;")
|
|
||||||
|
query := "SELECT COUNT(*) FROM quads;"
|
||||||
|
if qs.useEstimates {
|
||||||
|
switch qs.sqlFlavor {
|
||||||
|
case "postgres":
|
||||||
|
query = "SELECT reltuples::BIGINT AS estimate FROM pg_class WHERE relname='quads';"
|
||||||
|
default:
|
||||||
|
panic("no estimate support for flavor: " + qs.sqlFlavor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c := qs.db.QueryRow(query)
|
||||||
err := c.Scan(&qs.size)
|
err := c.Scan(&qs.size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Couldn't execute COUNT: %v", err)
|
glog.Errorf("Couldn't execute COUNT: %v", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue