summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
diff options
context:
space:
mode:
authorTom Lane2009-02-28 03:51:05 +0000
committerTom Lane2009-02-28 03:51:05 +0000
commit21eb6aeb36b691b2b57d8a1445c665330b669552 (patch)
tree456732cf430bc85ce7af52c68f08e5753e230c2b /src/backend/optimizer
parent640796ff4122c01ab96780cbbee88479c3694907 (diff)
Shave a few cycles in compare_pathkeys() by checking for pointer-identical
input lists before we grovel through the lists. This doesn't save much, but testing shows that the case of both inputs NIL is common enough that it saves something. And this is used enough to be a hotspot.
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r--src/backend/optimizer/path/pathkeys.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index 0c03f5e812..469ff82db3 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.96 2009/01/01 17:23:44 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.97 2009/02/28 03:51:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -332,6 +332,14 @@ compare_pathkeys(List *keys1, List *keys2)
ListCell *key1,
*key2;
+ /*
+ * Fall out quickly if we are passed two identical lists. This mostly
+ * catches the case where both are NIL, but that's common enough to
+ * warrant the test.
+ */
+ if (keys1 == keys2)
+ return PATHKEYS_EQUAL;
+
forboth(key1, keys1, key2, keys2)
{
PathKey *pathkey1 = (PathKey *) lfirst(key1);
@@ -354,11 +362,11 @@ compare_pathkeys(List *keys1, List *keys2)
* If we reached the end of only one list, the other is longer and
* therefore not a subset.
*/
- if (key1 == NULL && key2 == NULL)
- return PATHKEYS_EQUAL;
if (key1 != NULL)
return PATHKEYS_BETTER1; /* key1 is longer */
- return PATHKEYS_BETTER2; /* key2 is longer */
+ if (key2 != NULL)
+ return PATHKEYS_BETTER2; /* key2 is longer */
+ return PATHKEYS_EQUAL;
}
/*