Skip to content
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
4 changes: 3 additions & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3915,6 +3915,7 @@ CREATE TABLE crdb_internal.table_indexes (
is_inverted BOOL NOT NULL,
is_sharded BOOL NOT NULL,
is_visible BOOL NOT NULL,
is_vector BOOL NOT NULL,
visibility FLOAT NOT NULL,
shard_bucket_count INT,
created_at TIMESTAMP,
Expand All @@ -3924,7 +3925,7 @@ CREATE TABLE crdb_internal.table_indexes (
generator: func(ctx context.Context, p *planner, dbContext catalog.DatabaseDescriptor, _ int64, stopper *stop.Stopper) (virtualTableGenerator, cleanupFunc, error) {
primary := tree.NewDString("primary")
secondary := tree.NewDString("secondary")
const numDatums = 13
const numDatums = 14
row := make([]tree.Datum, numDatums)
worker := func(ctx context.Context, pusher rowPusher) error {
alloc := &tree.DatumAlloc{}
Expand Down Expand Up @@ -3998,6 +3999,7 @@ CREATE TABLE crdb_internal.table_indexes (
tree.MakeDBool(idx.GetType() == idxtype.INVERTED),
tree.MakeDBool(tree.DBool(idx.IsSharded())),
tree.MakeDBool(idxInvisibility == 0.0),
tree.MakeDBool(idx.GetType() == idxtype.VECTOR),
tree.NewDFloat(tree.DFloat(1-idxInvisibility)),
shardBucketCnt,
createdAt,
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ FROM pg_catalog.pg_am
oid amname amstrategies amsupport amcanorder amcanorderbyop amcanbackward amcanunique amcanmulticol amoptionalkey amsearcharray amsearchnulls amstorage amclusterable ampredlocks amkeytype aminsert ambeginscan amgettuple amgetbitmap amrescan amendscan ammarkpos amrestrpos ambuild ambuildempty ambulkdelete amvacuumcleanup amcanreturn amcostestimate amoptions amhandler amtype
2631952481 prefix 0 0 true false true true true true true true false false false 0 NULL NULL 0 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL i
4004609370 inverted 0 0 false false false false false false false true false false false 0 NULL NULL 0 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL i
3220470259 vector 0 0 false false false false false false false false false false false 0 NULL NULL 0 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL i

## pg_catalog.pg_attrdef

Expand Down
44 changes: 44 additions & 0 deletions pkg/sql/pg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var (
const (
indexTypeForwardIndex = "prefix"
indexTypeInvertedIndex = "inverted"
indexTypeVectorIndex = "vector"
)

// Bitmasks for pg_index.indoption. Each column in the index has a bitfield
Expand Down Expand Up @@ -115,6 +116,7 @@ const (

var forwardIndexOid = stringOid(indexTypeForwardIndex)
var invertedIndexOid = stringOid(indexTypeInvertedIndex)
var vectorIndexOid = stringOid(indexTypeVectorIndex)

// pgCatalog contains a set of system tables mirroring PostgreSQL's pg_catalog schema.
// This code attempts to comply as closely as possible to the system catalogs documented
Expand Down Expand Up @@ -275,6 +277,45 @@ var pgCatalogAmTable = virtualSchemaTable{
https://www.postgresql.org/docs/9.5/catalog-pg-am.html`,
schema: vtable.PGCatalogAm,
populate: func(_ context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
// add row for vector indexes
if err := addRow(
vectorIndexOid, // oid - assign a new OID constant
tree.NewDName(indexTypeVectorIndex), // amname = 'vector'
zeroVal, // amstrategies - < v9.6
zeroVal, // amsupport - < v9.6
tree.DBoolFalse, // amcanorder - < v9.6
tree.DBoolFalse, // amcanorderbyop - < v9.6
tree.DBoolFalse, // amcanbackward - < v9.6
tree.DBoolFalse, // amcanunique - < v9.6
tree.DBoolFalse, // amcanmulticol - < v9.6
tree.DBoolFalse, // amoptionalkey - < v9.6
tree.DBoolFalse, // amsearcharray - < v9.6
tree.DBoolFalse, // amsearchnulls - < v9.6
tree.DBoolFalse, // amstorage - < v9.6
tree.DBoolFalse, // amclusterable - < v9.6
tree.DBoolFalse, // ampredlocks - < v9.6
oidZero, // amkeytype - < v9.6
tree.DNull, // aminsert - < v9.6
tree.DNull, // ambeginscan - < v9.6
oidZero, // amgettuple - < v9.6
oidZero, // amgetbitmap - < v9.6
tree.DNull, // amrescan - < v9.6
tree.DNull, // amendscan - < v9.6
tree.DNull, // ammarkpos - < v9.6
tree.DNull, // amrestrpos - < v9.6
tree.DNull, // ambuild - < v9.6
tree.DNull, // ambuildempty - < v9.6
tree.DNull, // ambulkdelete - < v9.6
tree.DNull, // amvacuumcleanup - < v9.6
tree.DNull, // amcanreturn - < v9.6
tree.DNull, // amcostestimate - < v9.6
tree.DNull, // amoptions - < v9.6
tree.DNull, // amhandler - > v9.6
tree.NewDString("i"), // amtype - > v9.6 (index)
); err != nil {
return err
}

// add row for forward indexes
if err := addRow(
forwardIndexOid, // oid - all versions
Expand Down Expand Up @@ -855,6 +896,9 @@ https://www.postgresql.org/docs/9.5/catalog-pg-class.html`,
if index.GetType() == idxtype.INVERTED {
indexType = invertedIndexOid
}
if index.GetType() == idxtype.VECTOR {
indexType = vectorIndexOid
}
ownerOid, err := getOwnerOID(ctx, p, table)
if err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/vecindex/vecindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,30 @@ func insertVectors(t *testing.T, runner *sqlutils.SQLRunner, startId int, vector
runner.Exec(t, query, args...)
}

func TestVecIndexMetadata(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

ctx := context.Background()
srv, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{})
runner := sqlutils.MakeSQLRunner(sqlDB)
defer srv.Stopper().Stop(ctx)

// Construct the table.
runner.Exec(t, "CREATE TABLE t (id INT PRIMARY KEY, v VECTOR(512), VECTOR INDEX (v))")

// Get the table descriptor to find the vector index ID.
var tableID uint32
runner.QueryRow(t, "SELECT id FROM system.namespace WHERE name = 't'").Scan(&tableID)

// Get the index ID from crdb_internal.table_indexes
var isVector bool
runner.QueryRow(t, "SELECT is_vector FROM crdb_internal.table_indexes WHERE descriptor_id = $1 AND index_name = 't_v_idx'", tableID).Scan(&isVector)
if isVector == false {
t.Errorf("Expected is_vector=true for index t_v_idx on table t (id=%d), got false", tableID)
}
}

// TestVecIndexDeletion tests that rows can be properly deleted from a vector index.
func TestVecIndexDeletion(t *testing.T) {
defer leaktest.AfterTest(t)()
Expand Down
Loading