From f2110a757d0bdca766fa1b8562c7dcb1a53fd422 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 5 Apr 2009 22:28:59 +0000 Subject: Change cardinality() into a C-code function, instead of a SQL-language alias for array_length(v,1). The efficiency gain here is doubtless negligible --- what I'm interested in is making sure that if we have second thoughts about the definition, we will not have to force a post-beta initdb to change the implementation. --- src/backend/utils/adt/arrayfuncs.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/arrayfuncs.c') diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 111d6b8c263..8b36edc42fa 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.153 2009/01/30 21:21:18 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.154 2009/04/05 22:28:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1668,6 +1668,28 @@ array_length(PG_FUNCTION_ARGS) PG_RETURN_INT32(result); } +/* + * array_cardinality : + * SQL-spec alias for array_length(v, 1) + */ +Datum +array_cardinality(PG_FUNCTION_ARGS) +{ + ArrayType *v = PG_GETARG_ARRAYTYPE_P(0); + int *dimv; + int result; + + /* Sanity check: does it look like an array at all? */ + if (ARR_NDIM(v) <= 0 || ARR_NDIM(v) > MAXDIM) + PG_RETURN_NULL(); + + dimv = ARR_DIMS(v); + + result = dimv[0]; + + PG_RETURN_INT32(result); +} + /* * array_ref : * This routine takes an array pointer and a subscript array and returns -- cgit v1.2.3