IDEMPIERE-1953 Performance problem of postgresql functions - adding STABLE/IMMUTABLE attribute.

This commit is contained in:
Carlos Ruiz 2014-05-30 12:11:20 -05:00
parent 06ed133b34
commit d7147dc1f5
32 changed files with 2192 additions and 53 deletions

View File

@ -35,7 +35,5 @@ BEGIN
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -9,5 +9,6 @@ BEGIN
return cast(datetime + cast(duration as interval) as date); return cast(datetime + cast(duration as interval) as date);
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql' IMMUTABLE
; ;

View File

@ -20,5 +20,5 @@ BEGIN
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -48,4 +48,5 @@ BEGIN
RETURN currencyConvert (p_Amount, p_CurFrom_ID, v_CurTo_ID, p_ConvDate, null, p_Client_ID, p_Org_ID); RETURN currencyConvert (p_Amount, p_CurFrom_ID, v_CurTo_ID, p_ConvDate, null, p_Client_ID, p_Org_ID);
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -55,8 +55,5 @@ BEGIN
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -175,4 +175,5 @@ EXCEPTION WHEN OTHERS THEN
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -57,6 +57,5 @@ BEGIN
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' VOLATILE; LANGUAGE 'plpgsql' STABLE;
ALTER FUNCTION currencyround(p_amount numeric, p_curto_id numeric, p_costing character varying) OWNER TO adempiere;

View File

@ -78,6 +78,5 @@ EXCEPTION
RETURN NULL; RETURN NULL;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -116,5 +116,6 @@ BEGIN
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql' STABLE
; ;

View File

@ -132,7 +132,8 @@ BEGIN
RETURN v_TotalOpenAmt; RETURN v_TotalOpenAmt;
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' ; LANGUAGE 'plpgsql' STABLE;
CREATE OR REPLACE FUNCTION InvoiceopenToDate CREATE OR REPLACE FUNCTION InvoiceopenToDate
( (
@ -233,4 +234,5 @@ BEGIN
RETURN v_TotalOpenAmt; RETURN v_TotalOpenAmt;
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' ; LANGUAGE 'plpgsql' STABLE;

View File

@ -77,5 +77,5 @@ BEGIN
RETURN v_PaymentAmt * v_MultiplierAP; RETURN v_PaymentAmt * v_MultiplierAP;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -85,4 +85,5 @@ BEGIN
RETURN v_PaymentAmt * v_MultiplierAP; RETURN v_PaymentAmt * v_MultiplierAP;
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' ; LANGUAGE 'plpgsql' STABLE;

View File

@ -80,5 +80,5 @@ BEGIN
RETURN Discount; RETURN Discount;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -45,5 +45,6 @@ BEGIN
RETURN DueDate; RETURN DueDate;
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql' STABLE
; ;

View File

@ -116,7 +116,5 @@ BEGIN
RETURN Days; RETURN Days;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -74,6 +74,5 @@ BEGIN
RETURN v_AllocatedAmt; RETURN v_AllocatedAmt;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -74,4 +74,5 @@ BEGIN
RETURN v_AvailableAmt; RETURN v_AvailableAmt;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -88,5 +88,5 @@ BEGIN
RETURN v_Name; RETURN v_Name;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql STABLE;

View File

@ -30,11 +30,12 @@ BEGIN
duration = days || ' day'; duration = days || ' day';
return cast(date_trunc('day',datetime) + cast(duration as interval) as date); return cast(date_trunc('day',datetime) + cast(duration as interval) as date);
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION subtractdays (day TIMESTAMP WITH TIME ZONE, days NUMERIC) CREATE OR REPLACE FUNCTION subtractdays (day TIMESTAMP WITH TIME ZONE, days NUMERIC)
RETURNS DATE AS $$ RETURNS DATE AS $$
BEGIN BEGIN
RETURN addDays(day,(days * -1)); RETURN addDays(day,(days * -1));
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;

View File

@ -21,8 +21,6 @@
*/ */
/** Get Character at Position */ /** Get Character at Position */
SET search_path = adempiere, pg_catalog;
CREATE OR REPLACE FUNCTION charAt ( CREATE OR REPLACE FUNCTION charAt (
IN VARCHAR, -- $1 the string IN VARCHAR, -- $1 the string
IN INTEGER -- $2 the position IN INTEGER -- $2 the position
@ -31,4 +29,5 @@ $$
BEGIN BEGIN
RETURN SUBSTR($1, $2, 1); RETURN SUBSTR($1, $2, 1);
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;

View File

@ -25,4 +25,5 @@ RETURNS INTEGER AS $$
BEGIN BEGIN
RETURN CAST(p_date1 AS DATE) - CAST(p_date2 as DATE); RETURN CAST(p_date1 AS DATE) - CAST(p_date2 as DATE);
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;

View File

@ -47,4 +47,5 @@ BEGIN
RETURN v_DocumentNo; RETURN v_DocumentNo;
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' ; LANGUAGE 'plpgsql' STABLE;

View File

@ -73,4 +73,5 @@ BEGIN
datetime = date_trunc(datepart, $1); datetime = date_trunc(datepart, $1);
RETURN cast(datetime as date) + offsetdays; RETURN cast(datetime as date) + offsetdays;
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;

View File

@ -39,7 +39,6 @@ BEGIN
RETURN tmpvar; RETURN tmpvar;
END; END;
$BODY$ $BODY$
LANGUAGE plpgsql VOLATILE LANGUAGE plpgsql STABLE
COST 100
; ;

View File

@ -44,4 +44,5 @@ BEGIN
RETURN v_value; RETURN v_value;
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql'; LANGUAGE 'plpgsql' STABLE;

View File

@ -63,4 +63,5 @@ begin
return v_nextDate::timestamp with time zone; return v_nextDate::timestamp with time zone;
end; end;
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql STABLE;

View File

@ -59,5 +59,6 @@ BEGIN
RETURN 0; RETURN 0;
END; END;
$BODY$ $BODY$
LANGUAGE plpgsql VOLATILE LANGUAGE plpgsql STABLE
COST 100; ;

View File

@ -59,5 +59,6 @@ BEGIN
RETURN 0; RETURN 0;
END; END;
$BODY$ $BODY$
LANGUAGE plpgsql VOLATILE LANGUAGE plpgsql STABLE
COST 100; ;

View File

@ -6,4 +6,5 @@ $$
BEGIN BEGIN
RETURN ROUND($1, cast($2 as integer)); RETURN ROUND($1, cast($2 as integer));
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;

View File

@ -24,7 +24,7 @@ RETURNS TIMESTAMP WITH TIME ZONE AS $$
BEGIN BEGIN
RETURN CAST(datetime AS DATE); RETURN CAST(datetime AS DATE);
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar) CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar)
RETURNS DATE AS $$ RETURNS DATE AS $$
@ -43,11 +43,12 @@ BEGIN
RETURN CAST(datetime AS DATE); RETURN CAST(datetime AS DATE);
END IF; END IF;
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION trunc(i INTERVAL) CREATE OR REPLACE FUNCTION trunc(i INTERVAL)
RETURNS INTEGER AS $$ RETURNS INTEGER AS $$
BEGIN BEGIN
RETURN EXTRACT(DAY FROM i); RETURN EXTRACT(DAY FROM i);
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql IMMUTABLE;

View File

@ -0,0 +1,4 @@
-- just for postgresql
SELECT register_migration_script('201405301149_IDEMPIERE-1953.sql') FROM dual
;

File diff suppressed because it is too large Load Diff