Skip to content

Commit 9401fdc

Browse files
committed
[#26879] YSQL: Fix PG segfault during rewrite on tables with vector indexes
Summary: The segfault happens because a null pointer is passed for the opclassOids argument to YBCCreateIndex, and subsequently to ybhnswbindcolumnschema. This issue was introduced in commit f8950ff. Fix the segfault by properly constructing and passing the operator class oids. Specific code changes: - pg_yb_utils.c: retrieve the operator class oids from the sys cache (pg_index.indclass) in YbIndexSetNewRelfileNode, and pass it to YBCCreateIndex - ybvectorwrite.c: use YbGetRelfileNodeId(index) instead of the index's oid in ybvectorcopartitionedbuild. Jira: DB-16293 Test Plan: Note: rewrites on tables with vector indexes are still flaky (occasionally cause a tserver FATAL at a later stage) due to a different issue, so this revision doesn't add any automated tests. Manual test: ``` yugabyte=# CREATE EXTENSION vector; CREATE EXTENSION yugabyte=# CREATE TABLE IF NOT EXISTS ybarticles (id int, content_vector vector(1536)); CREATE TABLE yugabyte=# CREATE INDEX ON ybarticles USING ybhnsw (content_vector vector_l2_ops); CREATE INDEX yugabyte=# TRUNCATE TABLE ybarticles; TRUNCATE TABLE yugabyte=# SELECT * FROM ybarticles; id | content_vector ----+---------------- (0 rows) ``` Reviewers: myang, sergei Reviewed By: myang Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D44458
1 parent 60083dc commit 9401fdc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/postgres/src/backend/utils/misc/pg_yb_utils.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7122,10 +7122,13 @@ YbIndexSetNewRelfileNode(Relation indexRel, Oid newRelfileNodeId,
71227122
bool yb_copy_split_options)
71237123
{
71247124
bool isNull;
7125+
HeapTuple indexTuple;
71257126
HeapTuple tuple;
71267127
Datum reloptions = (Datum) 0;
71277128
Relation indexedRel;
71287129
IndexInfo *indexInfo;
7130+
oidvector *indclass = NULL;
7131+
Datum indclassDatum;
71297132

71307133
tuple = SearchSysCache1(RELOID,
71317134
ObjectIdGetDatum(RelationGetRelid(indexRel)));
@@ -7142,6 +7145,19 @@ YbIndexSetNewRelfileNode(Relation indexRel, Oid newRelfileNodeId,
71427145
indexInfo = BuildIndexInfo(indexRel);
71437146

71447147
YbGetTableProperties(indexRel);
7148+
7149+
indexTuple = SearchSysCache1(INDEXRELID,
7150+
ObjectIdGetDatum(RelationGetRelid(indexRel)));
7151+
if (!HeapTupleIsValid(indexTuple))
7152+
elog(ERROR, "cache lookup failed for index %u",
7153+
RelationGetRelid(indexRel));
7154+
7155+
indclassDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
7156+
Anum_pg_index_indclass, &isNull);
7157+
if (!isNull)
7158+
indclass = (oidvector *) DatumGetPointer(indclassDatum);
7159+
ReleaseSysCache(indexTuple);
7160+
71457161
YBCCreateIndex(RelationGetRelationName(indexRel),
71467162
indexInfo,
71477163
RelationGetDescr(indexRel),
@@ -7157,7 +7173,7 @@ YbIndexSetNewRelfileNode(Relation indexRel, Oid newRelfileNodeId,
71577173
indexRel->rd_rel->reltablespace,
71587174
newRelfileNodeId,
71597175
YbGetRelfileNodeId(indexRel),
7160-
NULL /* opclassOids */ );
7176+
indclass ? indclass->values : NULL);
71617177

71627178
table_close(indexedRel, ShareLock);
71637179

src/postgres/third-party-extensions/pgvector/src/ybvector/ybvectorwrite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ IndexBuildResult *
457457
ybvectorcopartitionedbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
458458
{
459459
HandleYBStatus(YBCPgWaitVectorIndexReady(
460-
YBCGetDatabaseOid(index), index->rd_id));
460+
YBCGetDatabaseOid(index), YbGetRelfileNodeId(index)));
461461

462462
IndexBuildResult *result = palloc0(sizeof(IndexBuildResult));
463463

0 commit comments

Comments
 (0)