Skip to content

Add columns used to BestIndex callback, add missing index constraint op types. #1336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _example/vtable/vtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (v *ghRepoTable) Open() (sqlite3.VTabCursor, error) {
return &ghRepoCursor{0, repos}, nil
}

func (v *ghRepoTable) BestIndex(csts []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
func (v *ghRepoTable) BestIndex(csts []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy, colsUsed uint64) (*sqlite3.IndexResult, error) {
used := make([]bool, len(csts))
return &sqlite3.IndexResult{
IdxNum: 0,
Expand Down
2 changes: 1 addition & 1 deletion _example/vtable_eponymous_only/vtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (v *seriesTable) Open() (sqlite3.VTabCursor, error) {
return &seriesCursor{v, 0}, nil
}

func (v *seriesTable) BestIndex(csts []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
func (v *seriesTable) BestIndex(csts []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy, colsUsed uint64) (*sqlite3.IndexResult, error) {
used := make([]bool, len(csts))
for c, cst := range csts {
if cst.Usable && cst.Op == sqlite3.OpEQ {
Expand Down
20 changes: 14 additions & 6 deletions sqlite3_opt_vtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,18 @@ const (
OpLT = 16
OpGE = 32
OpMATCH = 64
OpLIKE = 65 /* 3.10.0 and later only */
OpGLOB = 66 /* 3.10.0 and later only */
OpREGEXP = 67 /* 3.10.0 and later only */
OpScanUnique = 1 /* Scan visits at most 1 row */
OpLIKE = 65 /* 3.10.0 and later only */
OpGLOB = 66 /* 3.10.0 and later only */
OpREGEXP = 67 /* 3.10.0 and later only */
OpNE = 68 /* 3.21.0 and later only */
OpISNOT = 69 /* 3.21.0 and later */
OpISNOTNULL = 70 /* 3.21.0 and later */
OpISNULL = 71 /* 3.21.0 and later */
OpIS = 72 /* 3.21.0 and later */
OpLIMIT = 73 /* 3.38.0 and later */
OpOFFSET = 74 /* 3.38.0 and later */
OpFUNCTION = 150 /* 3.25.0 and later */
OpScanUnique = 1 /* Scan visits at most 1 row */
)

// InfoConstraint give information of constraint.
Expand Down Expand Up @@ -448,7 +456,7 @@ func goVBestIndex(pVTab unsafe.Pointer, icp unsafe.Pointer) *C.char {
vt := lookupHandle(pVTab).(*sqliteVTab)
info := (*C.sqlite3_index_info)(icp)
csts := constraints(info)
res, err := vt.vTab.BestIndex(csts, orderBys(info))
res, err := vt.vTab.BestIndex(csts, orderBys(info), uint64(info.colUsed))
if err != nil {
return mPrintf("%s", err.Error())
}
Expand Down Expand Up @@ -650,7 +658,7 @@ type EponymousOnlyModule interface {
// See: http://sqlite.org/c3ref/vtab.html
type VTab interface {
// http://sqlite.org/vtab.html#xbestindex
BestIndex([]InfoConstraint, []InfoOrderBy) (*IndexResult, error)
BestIndex([]InfoConstraint, []InfoOrderBy, uint64) (*IndexResult, error)
// http://sqlite.org/vtab.html#xdisconnect
Disconnect() error
// http://sqlite.org/vtab.html#sqlite3_module.xDestroy
Expand Down
6 changes: 3 additions & 3 deletions sqlite3_opt_vtable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m testModule) Connect(c *SQLiteConn, args []string) (VTab, error) {

func (m testModule) DestroyModule() {}

func (v *testVTab) BestIndex(cst []InfoConstraint, ob []InfoOrderBy) (*IndexResult, error) {
func (v *testVTab) BestIndex(cst []InfoConstraint, ob []InfoOrderBy, colsUsed uint64) (*IndexResult, error) {
used := make([]bool, 0, len(cst))
for range cst {
used = append(used, false)
Expand Down Expand Up @@ -377,7 +377,7 @@ func (t *vtabUpdateTable) Open() (VTabCursor, error) {
return &vtabUpdateCursor{t, 0}, nil
}

func (t *vtabUpdateTable) BestIndex(cst []InfoConstraint, ob []InfoOrderBy) (*IndexResult, error) {
func (t *vtabUpdateTable) BestIndex(cst []InfoConstraint, ob []InfoOrderBy, colsUsed uint64) (*IndexResult, error) {
return &IndexResult{Used: make([]bool, len(cst))}, nil
}

Expand Down Expand Up @@ -516,7 +516,7 @@ func (m testModuleEponymousOnly) Connect(c *SQLiteConn, args []string) (VTab, er

func (m testModuleEponymousOnly) DestroyModule() {}

func (v *testVTabEponymousOnly) BestIndex(cst []InfoConstraint, ob []InfoOrderBy) (*IndexResult, error) {
func (v *testVTabEponymousOnly) BestIndex(cst []InfoConstraint, ob []InfoOrderBy, colsUsed uint64) (*IndexResult, error) {
used := make([]bool, 0, len(cst))
for range cst {
used = append(used, false)
Expand Down