Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7f24c02

Browse files
committed
Improve possible performance regression
Commit ce62f2f introduced calls to GetIndexAmRoutineByAmId() in lsyscache.c functions. This call is a bit more expensive than a simple syscache lookup. So rearrange the nesting so that we call that one last and do the cheaper checks first. Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/E1tngY6-0000UL-2n%40gemulon.postgresql.org
1 parent af4002b commit 7f24c02

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/backend/utils/cache/lsyscache.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,16 @@ equality_ops_are_compatible(Oid opno1, Oid opno2)
717717
{
718718
HeapTuple op_tuple = &catlist->members[i]->tuple;
719719
Form_pg_amop op_form = (Form_pg_amop) GETSTRUCT(op_tuple);
720-
IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false);
721720

722-
if (amroutine->amconsistentequality)
721+
/*
722+
* op_in_opfamily() is cheaper than GetIndexAmRoutineByAmId(), so
723+
* check it first
724+
*/
725+
if (op_in_opfamily(opno2, op_form->amopfamily))
723726
{
724-
if (op_in_opfamily(opno2, op_form->amopfamily))
727+
IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false);
728+
729+
if (amroutine->amconsistentequality)
725730
{
726731
result = true;
727732
break;
@@ -768,11 +773,16 @@ comparison_ops_are_compatible(Oid opno1, Oid opno2)
768773
{
769774
HeapTuple op_tuple = &catlist->members[i]->tuple;
770775
Form_pg_amop op_form = (Form_pg_amop) GETSTRUCT(op_tuple);
771-
IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false);
772776

773-
if (amroutine->amcanorder && amroutine->amconsistentordering)
777+
/*
778+
* op_in_opfamily() is cheaper than GetIndexAmRoutineByAmId(), so
779+
* check it first
780+
*/
781+
if (op_in_opfamily(opno2, op_form->amopfamily))
774782
{
775-
if (op_in_opfamily(opno2, op_form->amopfamily))
783+
IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false);
784+
785+
if (amroutine->amcanorder && amroutine->amconsistentordering)
776786
{
777787
result = true;
778788
break;

0 commit comments

Comments
 (0)