diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2025-03-07 11:20:26 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2025-03-07 11:46:33 +0100 |
commit | 7f24c0274385ea3d4c797cc2fd60d9a55f3a8d74 (patch) | |
tree | 675c0e17ebc4a97b655ac8128f5729d14a8205a6 /src/backend/utils/cache/lsyscache.c | |
parent | af4002b381d86df6479962953d82f03ecb4e2e06 (diff) | |
download | postgresql-7f24c0274385ea3d4c797cc2fd60d9a55f3a8d74.tar.gz postgresql-7f24c0274385ea3d4c797cc2fd60d9a55f3a8d74.zip |
Improve possible performance regression
Commit ce62f2f2a0a 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
Diffstat (limited to 'src/backend/utils/cache/lsyscache.c')
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 97ad36a031b..a712a432938 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -717,11 +717,16 @@ equality_ops_are_compatible(Oid opno1, Oid opno2) { HeapTuple op_tuple = &catlist->members[i]->tuple; Form_pg_amop op_form = (Form_pg_amop) GETSTRUCT(op_tuple); - IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false); - if (amroutine->amconsistentequality) + /* + * op_in_opfamily() is cheaper than GetIndexAmRoutineByAmId(), so + * check it first + */ + if (op_in_opfamily(opno2, op_form->amopfamily)) { - if (op_in_opfamily(opno2, op_form->amopfamily)) + IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false); + + if (amroutine->amconsistentequality) { result = true; break; @@ -768,11 +773,16 @@ comparison_ops_are_compatible(Oid opno1, Oid opno2) { HeapTuple op_tuple = &catlist->members[i]->tuple; Form_pg_amop op_form = (Form_pg_amop) GETSTRUCT(op_tuple); - IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false); - if (amroutine->amcanorder && amroutine->amconsistentordering) + /* + * op_in_opfamily() is cheaper than GetIndexAmRoutineByAmId(), so + * check it first + */ + if (op_in_opfamily(opno2, op_form->amopfamily)) { - if (op_in_opfamily(opno2, op_form->amopfamily)) + IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(op_form->amopmethod, false); + + if (amroutine->amcanorder && amroutine->amconsistentordering) { result = true; break; |