From 8956e65b2074570a757f83e492baa63825ab9cf2 Mon Sep 17 00:00:00 2001 From: moeed-k <99591855+moeed-k@users.noreply.github.com> Date: Thu, 26 Jan 2023 04:41:02 +0500 Subject: [PATCH] Optimize age_exists function (#586) -age_exists, which is the executor for exists(property) function, was making up to 3 redundant memory accesses. -exists(property) predicate function only serves to check if a property exists or not. -In Cypher, if a property is assigned the value of NULL, this is considered the same as the property not existing at all. Thus the function calls to get the value type is not needed as the check for the null argument itself filters out all NULL inputs. If a property passes this check, it implies existence. --- src/backend/utils/adt/agtype.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c index e98b0bb0b..30c76ca4c 100644 --- a/src/backend/utils/adt/agtype.c +++ b/src/backend/utils/adt/agtype.c @@ -5457,26 +5457,10 @@ PG_FUNCTION_INFO_V1(age_exists); */ Datum age_exists(PG_FUNCTION_ARGS) { - agtype *agt_arg = NULL; - agtype_value *agtv_value = NULL; - /* check for NULL, NULL is FALSE */ if (PG_ARGISNULL(0)) PG_RETURN_BOOL(false); - /* get the argument */ - agt_arg = AG_GET_ARG_AGTYPE_P(0); - - /* check for a scalar AGTV_NULL */ - if (AGT_ROOT_IS_SCALAR(agt_arg)) - { - agtv_value = get_ith_agtype_value_from_container(&agt_arg->root, 0); - - /* again, if NULL, NULL is FALSE */ - if (agtv_value->type == AGTV_NULL) - PG_RETURN_BOOL(false); - } - /* otherwise, we have something, and something is TRUE */ PG_RETURN_BOOL(true); }