The following table lists the data type and format for the result of COUNT.
|Mode||Data Type and Format|
MaxDecimal is general field 13 in the DBS Control utility.
If MaxDecimal in DBSControl is…
|Teradata||INTEGER and the format is the default format for INTEGER.|
The default value for the DBSControl General Field(80), COUNT_mode, is 0. The default is compatibility mode, which disables all extensions that impact external applications.
BIGINT and NUMBER modes impact COUNT performance:
- Type promotion may entail computing expressions using a different type if the mode is changed. This occurs when the result of the COUNT (*) based expression is materialized as a BIGINT/NUMBER type, and later used as a subexpression for computing another expression. The performance overhead is the same as that incurred when casting COUNT (*) as BIGINT/NUMBER.
- Since the data type of COUNT (*) changes if the mode is changed, queries that made assumptions on format, title, and data type must be aware of the change.
If the result of COUNT overflows and reports an error, you can cast the result to another data type, as illustrated by the following example.
SELECT CAST(COUNT(*) AS BIGINT) FROM BIGTABLE;
A similar example is provided for COUNT and rank window functions:
SELECT CAST(COUNT(*) over([PARTITION/ORDER BY]) AS BIGINT) FROM BIGTABLE; SELECT CAST(rank over([PARTITION/ORDER BY]) AS BIGINT) FROM BIGTABLE;
The following table lists the default title for the result of COUNT.
COUNT Specification in Aggregate Join Index
You can specify COUNT, COUNT cast to FLOAT OR DECIMAL(38,0), BIGINT, or NUMBER for a COUNT aggregate function in a join index. The following illustrates a SHOW JOIN INDEX that accommodates data type casts to BIGINT:
CREATE JOIN INDEX TEST.j1 ,NO FALLBACK ,CHECKSUM = DEFAULT AS SELECT COUNT (*)(BIGINT, NAMED a ),TEST.t1.a1 FROM TEST.t1 GROUP BY TEST.t1.a1 PRIMARY INDEX ( a1 );