Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5306df2

Browse files
committed
Clean up foreign-key caching code in planner.
Coverity complained that the code added by015e889 lacked anerror check for SearchSysCache1 failures, which it should have. Butthe code was pretty duff in other ways too, including failure to thinkabout whether it could really cope with arrays of different lengths.
1 parent7e3bb08 commit5306df2

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

‎src/backend/optimizer/util/plancat.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,20 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
408408

409409
foreach(l,fkoidlist)
410410
{
411-
inti;
412-
ArrayType*arr;
411+
Oidfkoid=lfirst_oid(l);
412+
HeapTuplehtup;
413+
Form_pg_constraintconstraint;
414+
ForeignKeyOptInfo*info;
413415
Datumadatum;
414416
boolisnull;
417+
ArrayType*arr;
415418
intnumkeys;
416-
Oidfkoid=lfirst_oid(l);
417-
418-
HeapTuplehtup=SearchSysCache1(CONSTROID,ObjectIdGetDatum(fkoid));
419-
Form_pg_constraintconstraint= (Form_pg_constraint)GETSTRUCT(htup);
419+
inti;
420420

421-
ForeignKeyOptInfo*info;
421+
htup=SearchSysCache1(CONSTROID,ObjectIdGetDatum(fkoid));
422+
if (!HeapTupleIsValid(htup))/* should not happen */
423+
elog(ERROR,"cache lookup failed for constraint %u",fkoid);
424+
constraint= (Form_pg_constraint)GETSTRUCT(htup);
422425

423426
Assert(constraint->contype==CONSTRAINT_FOREIGN);
424427

@@ -434,8 +437,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
434437

435438
arr=DatumGetArrayTypeP(adatum);
436439
numkeys=ARR_DIMS(arr)[0];
437-
info->conkeys= (int*)palloc0(numkeys*sizeof(int));
438-
440+
info->conkeys= (int*)palloc(numkeys*sizeof(int));
439441
for (i=0;i<numkeys;i++)
440442
info->conkeys[i]= ((int16*)ARR_DATA_PTR(arr))[i];
441443

@@ -445,9 +447,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
445447
Assert(!isnull);
446448

447449
arr=DatumGetArrayTypeP(adatum);
448-
numkeys=ARR_DIMS(arr)[0];
449-
info->confkeys= (int*)palloc0(numkeys*sizeof(int));
450-
450+
Assert(numkeys==ARR_DIMS(arr)[0]);
451+
info->confkeys= (int*)palloc(numkeys*sizeof(int));
451452
for (i=0;i<numkeys;i++)
452453
info->confkeys[i]= ((int16*)ARR_DATA_PTR(arr))[i];
453454

@@ -457,17 +458,16 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
457458
Assert(!isnull);
458459

459460
arr=DatumGetArrayTypeP(adatum);
460-
numkeys=ARR_DIMS(arr)[0];
461-
info->conpfeqop= (Oid*)palloc0(numkeys*sizeof(Oid));
462-
461+
Assert(numkeys==ARR_DIMS(arr)[0]);
462+
info->conpfeqop= (Oid*)palloc(numkeys*sizeof(Oid));
463463
for (i=0;i<numkeys;i++)
464464
info->conpfeqop[i]= ((Oid*)ARR_DATA_PTR(arr))[i];
465465

466466
info->nkeys=numkeys;
467467

468468
ReleaseSysCache(htup);
469469

470-
fkinfos=lcons(info,fkinfos);
470+
fkinfos=lappend(fkinfos,info);
471471
}
472472

473473
list_free(fkoidlist);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp