plspl aggregate problem

Seero

Golden Member
Nov 4, 2009
1,456
0
0
Dear experts, I have a problem that i don't know how to solve effectively. I am trying to use User-Defined Aggregates Interface to similate count, yet the performance is no where close to the built in. For example:

select count(1) from table1;

it will return 20000 in about 31 msecs.

select mycount(1) from table1;

it will also return 20000 in about 400 msecs.

I implemented mycount with hf_type defined as follows:

CREATE OR REPLACE TYPE BODY DA.hf_type IS
STATIC FUNCTION odciaggregateinitialize (sctx IN OUT hf_type)
RETURN NUMBER IS
BEGIN
IF sctx IS NULL THEN
sctx := hf_type (0);
ELSE
sctx.num := 0;
END IF;

RETURN odciconst.success;
END;

MEMBER FUNCTION odciaggregatedelete (self IN OUT hf_type, val NUMBER)
RETURN NUMBER IS
BEGIN
self.num := self.num - VAL;
RETURN odciconst.success;
END;

MEMBER FUNCTION odciaggregateiterate (self IN OUT hf_type, VAL IN NUMBER)
RETURN NUMBER IS
BEGIN
self.num := self.num + VAL;
RETURN odciconst.success;
END;

MEMBER FUNCTION odciaggregateterminate (self IN hf_type
,returnvalue OUT NUMBER
,flags IN NUMBER)
RETURN NUMBER IS
BEGIN
returnvalue := self.num;
RETURN odciconst.success;
END;

MEMBER FUNCTION odciaggregatemerge (self IN OUT hf_type, ctx2 IN hf_type)
RETURN NUMBER IS
BEGIN
self.num := self.num + ctx2.num;

RETURN odciconst.success;
END;
END;

CREATE OR REPLACE FUNCTION DA.hf_test (input NUMBER)
RETURN NUMBER
PARALLEL_ENABLE
AGGREGATE USING hf_type;

Of course that isn't the goal, my goal is to implement string aggregate, which there isn't a built-in. If i am able to make the above code as fast as built-in, then I will be golden.

Anyone had ran into this problem?