1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

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.
This commit is contained in:
Tom Lane
2009-04-05 22:28:59 +00:00
parent eb4c723e56
commit f2110a757d
4 changed files with 30 additions and 7 deletions

View File

@ -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