Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf2110a7

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 doubtlessnegligible --- what I'm interested in is making sure that if we havesecond thoughts about the definition, we will not have to force apost-beta initdb to change the implementation.
1 parenteb4c723 commitf2110a7

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

‎src/backend/utils/adt/arrayfuncs.c

Lines changed: 23 additions & 1 deletion
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+
intresult;
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

Lines changed: 2 additions & 2 deletions
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-
#defineCATALOG_VERSION_NO200903311
56+
#defineCATALOG_VERSION_NO200904051
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 3 deletions
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(insertOID=2176 (array_lengthPGNSPPGUID12100ffftfi2023"2277 23"_null__null__null__null_array_length_null__null__null_ ));
10071007
DESCR("array length");
1008-
DATA(insertOID=2179 (cardinalityPGNSPPGUID14100ffftfi1023"2277"_null__null__null__null_"select pg_catalog.array_length($1, 1)"_null__null__null_ ));
1009-
DESCR("arraylength");
1008+
DATA(insertOID=2179 (cardinalityPGNSPPGUID12100ffftfi1023"2277"_null__null__null__null_array_cardinality_null__null__null_ ));
1009+
DESCR("arraycardinality");
10101010
DATA(insertOID=378 (array_appendPGNSPPGUID12100fffffi202277"2277 2283"_null__null__null__null_array_push_null__null__null_ ));
10111011
DESCR("append element onto end of array");
10121012
DATA(insertOID=379 (array_prependPGNSPPGUID12100fffffi202277"2283 2277"_null__null__null__null_array_push_null__null__null_ ));

‎src/include/utils/array.h

Lines changed: 2 additions & 1 deletion
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
externDatumarray_lower(PG_FUNCTION_ARGS);
201201
externDatumarray_upper(PG_FUNCTION_ARGS);
202202
externDatumarray_length(PG_FUNCTION_ARGS);
203+
externDatumarray_cardinality(PG_FUNCTION_ARGS);
203204
externDatumarray_larger(PG_FUNCTION_ARGS);
204205
externDatumarray_smaller(PG_FUNCTION_ARGS);
205206
externDatumgenerate_subscripts(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp