Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f2110a7

Browse files
committed
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.
1 parent eb4c723 commit f2110a7

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

src/backend/utils/adt/arrayfuncs.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.153 2009/01/30 21:21:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.154 2009/04/05 22:28:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1668,6 +1668,28 @@ array_length(PG_FUNCTION_ARGS)
16681668
PG_RETURN_INT32(result);
16691669
}
16701670

1671+
/*
1672+
* array_cardinality :
1673+
* SQL-spec alias for array_length(v, 1)
1674+
*/
1675+
Datum
1676+
array_cardinality(PG_FUNCTION_ARGS)
1677+
{
1678+
ArrayType *v = PG_GETARG_ARRAYTYPE_P(0);
1679+
int *dimv;
1680+
int result;
1681+
1682+
/* Sanity check: does it look like an array at all? */
1683+
if (ARR_NDIM(v) <= 0 || ARR_NDIM(v) > MAXDIM)
1684+
PG_RETURN_NULL();
1685+
1686+
dimv = ARR_DIMS(v);
1687+
1688+
result = dimv[0];
1689+
1690+
PG_RETURN_INT32(result);
1691+
}
1692+
16711693
/*
16721694
* array_ref :
16731695
* This routine takes an array pointer and a subscript array and returns

src/include/catalog/catversion.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.527 2009/03/31 17:59:56 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.528 2009/04/05 22:28:59 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200903311
56+
#define CATALOG_VERSION_NO 200904051
5757

5858
#endif

src/include/catalog/pg_proc.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.539 2009/03/25 22:19:02 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.540 2009/04/05 22:28:59 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1005,8 +1005,8 @@ DATA(insert OID = 2092 ( array_upper PGNSP PGUID 12 1 0 0 f f f t f i 2 0 23
10051005
DESCR("array upper dimension");
10061006
DATA(insert OID = 2176 ( array_length PGNSP PGUID 12 1 0 0 f f f t f i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ array_length _null_ _null_ _null_ ));
10071007
DESCR("array length");
1008-
DATA(insert OID = 2179 ( cardinality PGNSP PGUID 14 1 0 0 f f f t f i 1 0 23 "2277" _null_ _null_ _null_ _null_ "select pg_catalog.array_length($1, 1)" _null_ _null_ _null_ ));
1009-
DESCR("array length");
1008+
DATA(insert OID = 2179 ( cardinality PGNSP PGUID 12 1 0 0 f f f t f i 1 0 23 "2277" _null_ _null_ _null_ _null_ array_cardinality _null_ _null_ _null_ ));
1009+
DESCR("array cardinality");
10101010
DATA(insert OID = 378 ( array_append PGNSP PGUID 12 1 0 0 f f f f f i 2 0 2277 "2277 2283" _null_ _null_ _null_ _null_ array_push _null_ _null_ _null_ ));
10111011
DESCR("append element onto end of array");
10121012
DATA(insert OID = 379 ( array_prepend PGNSP PGUID 12 1 0 0 f f f f f i 2 0 2277 "2283 2277" _null_ _null_ _null_ _null_ array_push _null_ _null_ _null_ ));

src/include/utils/array.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
5050
* Portions Copyright (c) 1994, Regents of the University of California
5151
*
52-
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.74 2009/01/01 17:24:02 momjian Exp $
52+
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.75 2009/04/05 22:28:59 tgl Exp $
5353
*
5454
*-------------------------------------------------------------------------
5555
*/
@@ -200,6 +200,7 @@ extern Datum array_dims(PG_FUNCTION_ARGS);
200200
extern Datum array_lower(PG_FUNCTION_ARGS);
201201
extern Datum array_upper(PG_FUNCTION_ARGS);
202202
extern Datum array_length(PG_FUNCTION_ARGS);
203+
extern Datum array_cardinality(PG_FUNCTION_ARGS);
203204
extern Datum array_larger(PG_FUNCTION_ARGS);
204205
extern Datum array_smaller(PG_FUNCTION_ARGS);
205206
extern Datum generate_subscripts(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)