-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a460e2
commit be3b022
Showing
15 changed files
with
826 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,4 @@ linters-settings: | |
- Constant | ||
- Term | ||
- Statement$ | ||
- Scan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package planner | ||
|
||
import "github.com/pkg/errors" | ||
|
||
var ErrFailedToCreatePlan = errors.New("failed to create plan") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package planner | ||
|
||
import ( | ||
"github.com/unhandled-exception/sophiadb/pkg/records" | ||
"github.com/unhandled-exception/sophiadb/pkg/scan" | ||
) | ||
|
||
type Plan interface { | ||
Open() (scan.Scan, error) | ||
Schema() records.Schema | ||
BlocksAccessed() int64 | ||
Records() int64 | ||
DistinctValues(string) (int64, bool) | ||
String() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package planner | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/unhandled-exception/sophiadb/pkg/metadata" | ||
"github.com/unhandled-exception/sophiadb/pkg/records" | ||
"github.com/unhandled-exception/sophiadb/pkg/scan" | ||
) | ||
|
||
type TablePlan struct { | ||
trx scan.TRXInt | ||
tablename string | ||
layout records.Layout | ||
stats metadata.StatInfo | ||
} | ||
|
||
type tablePlanMetadataManager interface { | ||
Layout(tableName string, trx scan.TRXInt) (records.Layout, error) | ||
GetStatInfo(tableName string, layout records.Layout, trx scan.TRXInt) (metadata.StatInfo, error) | ||
} | ||
|
||
func NewTablePlan(trx scan.TRXInt, tableName string, md tablePlanMetadataManager) (*TablePlan, error) { | ||
p := &TablePlan{ | ||
trx: trx, | ||
tablename: tableName, | ||
} | ||
|
||
var err error | ||
|
||
p.layout, err = md.Layout(tableName, trx) | ||
if err != nil { | ||
return nil, errors.WithMessage(ErrFailedToCreatePlan, err.Error()) | ||
} | ||
|
||
p.stats, err = md.GetStatInfo(tableName, p.layout, trx) | ||
if err != nil { | ||
return nil, errors.WithMessage(ErrFailedToCreatePlan, err.Error()) | ||
} | ||
|
||
return p, nil | ||
} | ||
|
||
func (p *TablePlan) Open() (scan.Scan, error) { | ||
return scan.NewTableScan(p.trx, p.tablename, p.layout) | ||
} | ||
|
||
func (p *TablePlan) Schema() records.Schema { | ||
return p.layout.Schema | ||
} | ||
|
||
func (p *TablePlan) BlocksAccessed() int64 { | ||
return p.stats.Blocks | ||
} | ||
|
||
func (p *TablePlan) Records() int64 { | ||
return p.stats.Records | ||
} | ||
|
||
func (p *TablePlan) DistinctValues(fieldName string) (int64, bool) { | ||
return p.stats.DistinctValues(fieldName) | ||
} | ||
|
||
func (p *TablePlan) String() string { | ||
return fmt.Sprintf("scan table %s", p.tablename) | ||
} |
Oops, something went wrong.