Aggregate Functions
Aggregate functions are used in the select list of SELECT statements and use the values of multiple rows to calculate a single value.
ActiveSpaces supports the following aggregate functions:
- COUNT
- SUM
- MIN
- MAX
- AVG
- GROUP_CONCAT
Performance of Aggregate Functions
When using an aggregate function as a value expression, the performance of the aggregation depends on how many rows are used in the aggregation. A query that includes aggregation, but does not contain a WHERE clause performs aggregation using all the rows from the table but must be avoided, if possible.
For the best aggregation performance, the column used as an argument to your aggregation function must have an index defined, which uses that column, and your query must include a WHERE clause that causes that index to be selected for the query. For example, if you have a secondary index named
lastname_idx
defined for the lastname column, the following queries use
lastname_idx
to reduce the number of rows in the query on which aggregation is performed:
SELECT COUNT(lastname) FROM mytable WHERE lastname LIKE 'B%' SELECT lastname, COUNT(lastname) FROM mytable WHERE lastname LIKE 'B%' GROUP BY lastnameFor more information about query performance see Tips on Constructing an Efficient WHERE Clause.
TIBDG_STATEMENT_PROPERTY_DOUBLE_FETCH_TIMEOUT
to a value that prevents timeouts. For example, if the client request timeout is
5
seconds, a more complex query can set the fetch timeout to a value larger than
5
seconds to prevent a timeout. AVG(col1)The aggregate function argument cannot be an expression or function. For example, the following function arguments are invalid uses of aggregate functions:
AVG(col1 + col2) MIN(trim(col1))For SQL keywords that cannot be used with aggregation functions, see Unsupported SQL Features.