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

Commitaf025ee

Browse files
committed
Add combine functions for various floating-point aggregates.
This allows parallel aggregation to use them. It may seem surprisingthat we use float8_combine for both float4_accum and float8_accumtransition functions, but that's because those functions differ onlyin the type of the non-transition-state argument.Haribabu Kommi, reviewed by David Rowley and Tomas Vondra
1 parent38627f6 commitaf025ee

File tree

5 files changed

+159
-46
lines changed

5 files changed

+159
-46
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12743,7 +12743,7 @@ NULL baz</literallayout>(3 rows)</entry>
1274312743
<type>double precision</type> for a floating-point argument,
1274412744
otherwise the same as the argument data type
1274512745
</entry>
12746-
<entry>All types apart from floating-point types</entry>
12746+
<entry>Yes</entry>
1274712747
<entry>the average (arithmetic mean) of all input values</entry>
1274812748
</row>
1274912749

@@ -13001,7 +13001,7 @@ NULL baz</literallayout>(3 rows)</entry>
1300113001
<type>bigint</type> arguments, otherwise the same as the
1300213002
argument data type
1300313003
</entry>
13004-
<entry>All types apart from floating-point types</entry>
13004+
<entry>Yes</entry>
1300513005
<entry>sum of <replaceable class="parameter">expression</replaceable> across all input values</entry>
1300613006
</row>
1300713007

@@ -13153,7 +13153,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1315313153
<entry>
1315413154
<type>double precision</type>
1315513155
</entry>
13156-
<entry>No</entry>
13156+
<entry>Yes</entry>
1315713157
<entry>correlation coefficient</entry>
1315813158
</row>
1315913159

@@ -13174,7 +13174,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1317413174
<entry>
1317513175
<type>double precision</type>
1317613176
</entry>
13177-
<entry>No</entry>
13177+
<entry>Yes</entry>
1317813178
<entry>population covariance</entry>
1317913179
</row>
1318013180

@@ -13195,7 +13195,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1319513195
<entry>
1319613196
<type>double precision</type>
1319713197
</entry>
13198-
<entry>No</entry>
13198+
<entry>Yes</entry>
1319913199
<entry>sample covariance</entry>
1320013200
</row>
1320113201

@@ -13212,7 +13212,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1321213212
<entry>
1321313213
<type>double precision</type>
1321413214
</entry>
13215-
<entry>No</entry>
13215+
<entry>Yes</entry>
1321613216
<entry>average of the independent variable
1321713217
(<literal>sum(<replaceable class="parameter">X</replaceable>)/<replaceable class="parameter">N</replaceable></literal>)</entry>
1321813218
</row>
@@ -13230,7 +13230,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1323013230
<entry>
1323113231
<type>double precision</type>
1323213232
</entry>
13233-
<entry>No</entry>
13233+
<entry>Yes</entry>
1323413234
<entry>average of the dependent variable
1323513235
(<literal>sum(<replaceable class="parameter">Y</replaceable>)/<replaceable class="parameter">N</replaceable></literal>)</entry>
1323613236
</row>
@@ -13248,7 +13248,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1324813248
<entry>
1324913249
<type>bigint</type>
1325013250
</entry>
13251-
<entry>No</entry>
13251+
<entry>Yes</entry>
1325213252
<entry>number of input rows in which both expressions are nonnull</entry>
1325313253
</row>
1325413254

@@ -13268,7 +13268,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1326813268
<entry>
1326913269
<type>double precision</type>
1327013270
</entry>
13271-
<entry>No</entry>
13271+
<entry>Yes</entry>
1327213272
<entry>y-intercept of the least-squares-fit linear equation
1327313273
determined by the (<replaceable
1327413274
class="parameter">X</replaceable>, <replaceable
@@ -13288,7 +13288,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1328813288
<entry>
1328913289
<type>double precision</type>
1329013290
</entry>
13291-
<entry>No</entry>
13291+
<entry>Yes</entry>
1329213292
<entry>square of the correlation coefficient</entry>
1329313293
</row>
1329413294

@@ -13308,7 +13308,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1330813308
<entry>
1330913309
<type>double precision</type>
1331013310
</entry>
13311-
<entry>No</entry>
13311+
<entry>Yes</entry>
1331213312
<entry>slope of the least-squares-fit linear equation determined
1331313313
by the (<replaceable class="parameter">X</replaceable>,
1331413314
<replaceable class="parameter">Y</replaceable>) pairs</entry>
@@ -13327,7 +13327,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1332713327
<entry>
1332813328
<type>double precision</type>
1332913329
</entry>
13330-
<entry>No</entry>
13330+
<entry>Yes</entry>
1333113331
<entry><literal>sum(<replaceable
1333213332
class="parameter">X</replaceable>^2) - sum(<replaceable
1333313333
class="parameter">X</replaceable>)^2/<replaceable
@@ -13348,7 +13348,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1334813348
<entry>
1334913349
<type>double precision</type>
1335013350
</entry>
13351-
<entry>No</entry>
13351+
<entry>Yes</entry>
1335213352
<entry><literal>sum(<replaceable
1335313353
class="parameter">X</replaceable>*<replaceable
1335413354
class="parameter">Y</replaceable>) - sum(<replaceable
@@ -13372,7 +13372,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1337213372
<entry>
1337313373
<type>double precision</type>
1337413374
</entry>
13375-
<entry>No</entry>
13375+
<entry>Yes</entry>
1337613376
<entry><literal>sum(<replaceable
1337713377
class="parameter">Y</replaceable>^2) - sum(<replaceable
1337813378
class="parameter">Y</replaceable>)^2/<replaceable
@@ -13399,7 +13399,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1339913399
<type>double precision</type> for floating-point arguments,
1340013400
otherwise <type>numeric</type>
1340113401
</entry>
13402-
<entry>All types apart from floating-point types</entry>
13402+
<entry>Yes</entry>
1340313403
<entry>historical alias for <function>stddev_samp</function></entry>
1340413404
</row>
1340513405

@@ -13423,7 +13423,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1342313423
<type>double precision</type> for floating-point arguments,
1342413424
otherwise <type>numeric</type>
1342513425
</entry>
13426-
<entry>All types apart from floating-point types</entry>
13426+
<entry>Yes</entry>
1342713427
<entry>population standard deviation of the input values</entry>
1342813428
</row>
1342913429

@@ -13447,7 +13447,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1344713447
<type>double precision</type> for floating-point arguments,
1344813448
otherwise <type>numeric</type>
1344913449
</entry>
13450-
<entry>All types apart from floating-point types</entry>
13450+
<entry>Yes</entry>
1345113451
<entry>sample standard deviation of the input values</entry>
1345213452
</row>
1345313453

@@ -13467,7 +13467,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1346713467
<type>double precision</type> for floating-point arguments,
1346813468
otherwise <type>numeric</type>
1346913469
</entry>
13470-
<entry>All types apart from floating-point types</entry>
13470+
<entry>Yes</entry>
1347113471
<entry>historical alias for <function>var_samp</function></entry>
1347213472
</row>
1347313473

@@ -13491,7 +13491,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1349113491
<type>double precision</type> for floating-point arguments,
1349213492
otherwise <type>numeric</type>
1349313493
</entry>
13494-
<entry>All types apart from floating-point types</entry>
13494+
<entry>Yes</entry>
1349513495
<entry>population variance of the input values (square of the population standard deviation)</entry>
1349613496
</row>
1349713497

@@ -13515,7 +13515,7 @@ SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab;
1351513515
<type>double precision</type> for floating-point arguments,
1351613516
otherwise <type>numeric</type>
1351713517
</entry>
13518-
<entry>All types apart from floating-point types</entry>
13518+
<entry>Yes</entry>
1351913519
<entry>sample variance of the input values (square of the sample standard deviation)</entry>
1352013520
</row>
1352113521
</tbody>

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,50 @@ check_float8_array(ArrayType *transarray, const char *caller, int n)
24352435
return (float8*)ARR_DATA_PTR(transarray);
24362436
}
24372437

2438+
/*
2439+
* float8_combine
2440+
*
2441+
* An aggregate combine function used to combine two 3 fields
2442+
* aggregate transition data into a single transition data.
2443+
* This function is used only in two stage aggregation and
2444+
* shouldn't be called outside aggregate context.
2445+
*/
2446+
Datum
2447+
float8_combine(PG_FUNCTION_ARGS)
2448+
{
2449+
ArrayType*transarray1=PG_GETARG_ARRAYTYPE_P(0);
2450+
ArrayType*transarray2=PG_GETARG_ARRAYTYPE_P(1);
2451+
float8*transvalues1;
2452+
float8*transvalues2;
2453+
float8N,
2454+
sumX,
2455+
sumX2;
2456+
2457+
if (!AggCheckCallContext(fcinfo,NULL))
2458+
elog(ERROR,"aggregate function called in non-aggregate context");
2459+
2460+
transvalues1=check_float8_array(transarray1,"float8_combine",3);
2461+
N=transvalues1[0];
2462+
sumX=transvalues1[1];
2463+
sumX2=transvalues1[2];
2464+
2465+
transvalues2=check_float8_array(transarray2,"float8_combine",3);
2466+
2467+
N+=transvalues2[0];
2468+
sumX+=transvalues2[1];
2469+
CHECKFLOATVAL(sumX,isinf(transvalues1[1])||isinf(transvalues2[1]),
2470+
true);
2471+
sumX2+=transvalues2[2];
2472+
CHECKFLOATVAL(sumX2,isinf(transvalues1[2])||isinf(transvalues2[2]),
2473+
true);
2474+
2475+
transvalues1[0]=N;
2476+
transvalues1[1]=sumX;
2477+
transvalues1[2]=sumX2;
2478+
2479+
PG_RETURN_ARRAYTYPE_P(transarray1);
2480+
}
2481+
24382482
Datum
24392483
float8_accum(PG_FUNCTION_ARGS)
24402484
{
@@ -2762,6 +2806,69 @@ float8_regr_accum(PG_FUNCTION_ARGS)
27622806
}
27632807
}
27642808

2809+
/*
2810+
* float8_regr_combine
2811+
*
2812+
* An aggregate combine function used to combine two 6 fields
2813+
* aggregate transition data into a single transition data.
2814+
* This function is used only in two stage aggregation and
2815+
* shouldn't be called outside aggregate context.
2816+
*/
2817+
Datum
2818+
float8_regr_combine(PG_FUNCTION_ARGS)
2819+
{
2820+
ArrayType*transarray1=PG_GETARG_ARRAYTYPE_P(0);
2821+
ArrayType*transarray2=PG_GETARG_ARRAYTYPE_P(1);
2822+
float8*transvalues1;
2823+
float8*transvalues2;
2824+
float8N,
2825+
sumX,
2826+
sumX2,
2827+
sumY,
2828+
sumY2,
2829+
sumXY;
2830+
2831+
if (!AggCheckCallContext(fcinfo,NULL))
2832+
elog(ERROR,"aggregate function called in non-aggregate context");
2833+
2834+
transvalues1=check_float8_array(transarray1,"float8_regr_combine",6);
2835+
N=transvalues1[0];
2836+
sumX=transvalues1[1];
2837+
sumX2=transvalues1[2];
2838+
sumY=transvalues1[3];
2839+
sumY2=transvalues1[4];
2840+
sumXY=transvalues1[5];
2841+
2842+
transvalues2=check_float8_array(transarray2,"float8_regr_combine",6);
2843+
2844+
N+=transvalues2[0];
2845+
sumX+=transvalues2[1];
2846+
CHECKFLOATVAL(sumX,isinf(transvalues1[1])||isinf(transvalues2[1]),
2847+
true);
2848+
sumX2+=transvalues2[2];
2849+
CHECKFLOATVAL(sumX2,isinf(transvalues1[2])||isinf(transvalues2[2]),
2850+
true);
2851+
sumY+=transvalues2[3];
2852+
CHECKFLOATVAL(sumY,isinf(transvalues1[3])||isinf(transvalues2[3]),
2853+
true);
2854+
sumY2+=transvalues2[4];
2855+
CHECKFLOATVAL(sumY2,isinf(transvalues1[4])||isinf(transvalues2[4]),
2856+
true);
2857+
sumXY+=transvalues2[5];
2858+
CHECKFLOATVAL(sumXY,isinf(transvalues1[5])||isinf(transvalues2[5]),
2859+
true);
2860+
2861+
transvalues1[0]=N;
2862+
transvalues1[1]=sumX;
2863+
transvalues1[2]=sumX2;
2864+
transvalues1[3]=sumY;
2865+
transvalues1[4]=sumY2;
2866+
transvalues1[5]=sumXY;
2867+
2868+
PG_RETURN_ARRAYTYPE_P(transarray1);
2869+
}
2870+
2871+
27652872
Datum
27662873
float8_regr_sxx(PG_FUNCTION_ARGS)
27672874
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp