Respond to PR feedback: fix typos and outline methods.

This commit is contained in:
Nick Tobey
2025-01-06 15:40:34 -08:00
parent d844f69f0d
commit 84f0b04ac1
4 changed files with 48 additions and 38 deletions
+1 -1
View File
@@ -2901,7 +2901,7 @@ func (t *WritableDoltTable) UpdateForeignKey(ctx *sql.Context, fkName string, sq
// CreateIndexForForeignKey implements sql.ForeignKeyTable
func (t *AlterableDoltTable) CreateIndexForForeignKey(ctx *sql.Context, idx sql.IndexDef) error {
if idx.Constraint != sql.IndexConstraint_None && idx.Constraint != sql.IndexConstraint_Unique && idx.Constraint != sql.IndexConstraint_Spatial {
return fmt.Errorf("only the following types of index constraints are supported for foriegn keys: none, unique, spatial")
return fmt.Errorf("only the following types of index constraints are supported for foreign keys: none, unique, spatial")
}
columns := make([]string, len(idx.Columns))
for i, indexCol := range idx.Columns {
@@ -59,35 +59,7 @@ func BuildProllyIndexExternal(ctx *sql.Context, vrw types.ValueReadWriter, ns tr
}
if idx.IsVector() {
// Secondary indexes are always covering and have no non-key columns
valDesc := val.NewTupleDescriptor()
proximityMapBuilder, err := prolly.NewProximityMapBuilder(ctx, ns, idx.VectorProperties().DistanceType, keyDesc, valDesc, prolly.DefaultLogChunkSize)
if err != nil {
return nil, err
}
for {
k, v, err := iter.Next(ctx)
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
idxKey, err := secondaryBld.SecondaryKeyFromRow(ctx, k, v)
if err != nil {
return nil, err
}
if uniqCb != nil && prefixDesc.HasNulls(idxKey) {
continue
}
if err := proximityMapBuilder.Insert(ctx, idxKey, val.EmptyTuple); err != nil {
return nil, err
}
}
proximityMap, err := proximityMapBuilder.Flush(ctx)
return durable.IndexFromProximityMap(proximityMap), nil
return BuildProximityIndex(ctx, ns, idx, keyDesc, prefixDesc, iter, secondaryBld, uniqCb)
}
sorter := sort.NewTupleSorter(batchSize, fileMax, func(t1, t2 val.Tuple) bool {
@@ -144,6 +116,48 @@ func BuildProllyIndexExternal(ctx *sql.Context, vrw types.ValueReadWriter, ns tr
return durable.IndexFromProllyMap(ret), nil
}
// func BuildProximityIndexExternal(ctx *sql.Context, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema, tableName string, idx schema.Index, primary prolly.Map, uniqCb DupEntryCb) (durable.Index, error) {
func BuildProximityIndex(
ctx *sql.Context,
ns tree.NodeStore,
idx schema.Index,
keyDesc val.TupleDesc,
prefixDesc val.TupleDesc,
iter prolly.MapIter,
secondaryBld index.SecondaryKeyBuilder,
uniqCb DupEntryCb,
) (durable.Index, error) {
// Secondary indexes have no non-key columns
valDesc := val.NewTupleDescriptor()
proximityMapBuilder, err := prolly.NewProximityMapBuilder(ctx, ns, idx.VectorProperties().DistanceType, keyDesc, valDesc, prolly.DefaultLogChunkSize)
if err != nil {
return nil, err
}
for {
k, v, err := iter.Next(ctx)
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
idxKey, err := secondaryBld.SecondaryKeyFromRow(ctx, k, v)
if err != nil {
return nil, err
}
if uniqCb != nil && prefixDesc.HasNulls(idxKey) {
continue
}
if err := proximityMapBuilder.Insert(ctx, idxKey, val.EmptyTuple); err != nil {
return nil, err
}
}
proximityMap, err := proximityMapBuilder.Flush(ctx)
return durable.IndexFromProximityMap(proximityMap), nil
}
type tupleIterWithCb struct {
iter sort.KeyIter
err error
+1 -1
View File
@@ -109,7 +109,7 @@ table Index {
fulltext_key:bool;
fulltext_info:FulltextInfo;
// fulltext information
// vector information
// these fields should be set for vector indexes and otherwise omitted, for backwards compatibility
vector_key:bool;
vector_info:VectorInfo;
+3 -7
View File
@@ -19,25 +19,21 @@ namespace serial;
table VectorIndexNode {
// sorted array of key items
key_items:[ubyte] (required);
// items offets for |key_items|
// item offsets for |key_items|
// first offset is 0, last offset is len(key_items)
key_offsets:[uint32] (required);
// item type for |key_items|
// key_type:ItemType;
// array of values items, ordered by paired key
value_items:[ubyte];
// item offsets for |value_items|
// first offset is 0, last offset is len(value_items)
value_offsets:[uint32];
// item type for |value_items|
// value_type:ItemType;
// array of chunk addresses
// - subtree addresses for internal prolly tree nodes
// - value addresses for AddressMap leaf nodes
// node that while the keys in this index are addresses to JSON chunks, we don't store those in the address_array
// because we are guarenteed to have other references to those chunks in the primary index.
// note that while the keys in this index are addresses to JSON chunks, we don't store those in the address_array
// because we are guaranteed to have other references to those chunks in the primary index.
address_array:[ubyte] (required);
// array of varint encoded subtree counts