Statistics for MySQL  1.1
 All Classes Files Functions Variables Typedefs Macros Pages
Classes | Functions
avgw.c File Reference

Weighted average. More...

#include "sqlstat.h"
Include dependency graph for avgw.c:

Go to the source code of this file.

Classes

struct  avgw_storage
 Storage for weighted average. More...
 

Functions

my_bool avgw_init (UDF_INIT *initid, UDF_ARGS *args, char *message)
 Called before first usage of function. More...
 
void avgw_reset (UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
 Reset function and add first group member Calls clear and add. More...
 
void avgw_clear (UDF_INIT *initid, char *is_null, char *error)
 Called at start of group. More...
 
void avgw_add (UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
 Add a member of the group. More...
 
double avgw (UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
 Retrieve weighted average. Called at end of group. More...
 
void avgw_deinit (UDF_INIT *initid)
 Called after last access to function. More...
 

Detailed Description

Weighted average.

CREATE AGGREGATE FUNCTION avgw RETURNS REAL SONAME 'libsqlstat.so';
SELECT avgw(x, w) FROM mytab;
DROP FUNCTION avgw;

Definition in file avgw.c.

Function Documentation

double avgw ( UDF_INIT *  initid,
UDF_ARGS *  args,
char *  is_null,
char *  error 
)

Retrieve weighted average. Called at end of group.

Parameters
initidfunction description
argsargument values
is_nullresult is NULL
errorerror message
Returns
weighted average

Definition at line 157 of file avgw.c.

void avgw_add ( UDF_INIT *  initid,
UDF_ARGS *  args,
char *  is_null,
char *  error 
)

Add a member of the group.

The sums are updated

Parameters
initidfunction description
argsargument values
is_null
errorerror message

Definition at line 125 of file avgw.c.

Here is the caller graph for this function:

void avgw_clear ( UDF_INIT *  initid,
char *  is_null,
char *  error 
)

Called at start of group.

void avgw_clear(UDF_INIT *initid, char *is_null, char *error) The sums are cleared.

Parameters
initidfunction description
is_null
errorerror message

Definition at line 108 of file avgw.c.

Here is the caller graph for this function:

void avgw_deinit ( UDF_INIT *  initid)

Called after last access to function.

Deallocate memory for counter and sums.

Parameters
initid

Definition at line 177 of file avgw.c.

my_bool avgw_init ( UDF_INIT *  initid,
UDF_ARGS *  args,
char *  message 
)

Called before first usage of function.

Check parameters.
Indicate type of return value.
Allocate memory for sums.

Parameters
initidfunction description
argsparameters
messageerror message
Returns
success = 0

Definition at line 55 of file avgw.c.

void avgw_reset ( UDF_INIT *  initid,
UDF_ARGS *  args,
char *  is_null,
char *  error 
)

Reset function and add first group member Calls clear and add.

Parameters
initidfunction description
argsargument values
is_null
errorerror message
Deprecated:
Reset is only called by MySQL 4.0 and below. It is implemented for backwards compatibility.

Definition at line 94 of file avgw.c.

Here is the call graph for this function: