Skip to content

Commit

Permalink
Adding godocs to newNonCoveringLookupBuilder and changing it to retur…
Browse files Browse the repository at this point in the history
…n an error (instead of panic'ing) if a primary index is passed in
  • Loading branch information
fulghum committed Oct 26, 2023
1 parent 1eda292 commit 3f2e09e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions go/libraries/doltcore/sqle/index/index_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func NewLookupBuilder(
// the current schema. In those cases, the primary index is still the best we have, so go ahead and use it.
return newCoveringLookupBuilder(base), nil
default:
return newNonCoveringLookupBuilder(s, base), nil
return newNonCoveringLookupBuilder(s, base)
}
}

Expand All @@ -306,7 +306,17 @@ func newCoveringLookupBuilder(b *baseLookupBuilder) *coveringLookupBuilder {
}
}

func newNonCoveringLookupBuilder(s *durableIndexState, b *baseLookupBuilder) *nonCoveringLookupBuilder {
// newNonCoveringLookupBuilder returns a LookupBuilder that uses the specified index state and
// base lookup builder to create a nonCoveringLookupBuilder that uses the secondary index (from
// |b|) to find the PK row identifier, and then uses that PK to look up the complete row from
// the primary index (from |s|). If a baseLookupBuilder built on the primary index is passed in,
// this function returns an error.
func newNonCoveringLookupBuilder(s *durableIndexState, b *baseLookupBuilder) (*nonCoveringLookupBuilder, error) {
if b.idx.ID() == "PRIMARY" {
return nil, fmt.Errorf("incompatible index passed to newNonCoveringLookupBuilder: " +
"primary index passed, but only secondary indexes are supported")
}

primary := durable.ProllyMapFromIndex(s.Primary)
priKd, _ := primary.Descriptors()
tbBld := val.NewTupleBuilder(priKd)
Expand All @@ -321,7 +331,7 @@ func newNonCoveringLookupBuilder(s *durableIndexState, b *baseLookupBuilder) *no
keyMap: keyProj,
valMap: valProj,
ordMap: ordProj,
}
}, nil
}

var _ LookupBuilder = (*baseLookupBuilder)(nil)
Expand Down Expand Up @@ -416,7 +426,7 @@ func (lb *coveringLookupBuilder) NewRowIter(ctx *sql.Context, part sql.Partition

// nonCoveringLookupBuilder constructs row iters for non-covering lookups,
// where we need to seek on the secondary table for key identity, and then
// the primary table to fill all requrested projections.
// the primary table to fill all requested projections.
type nonCoveringLookupBuilder struct {
*baseLookupBuilder

Expand Down

0 comments on commit 3f2e09e

Please sign in to comment.