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;
$body$ LANGUAGE plpgsql;
$body$ LANGUAGE plpgsql STABLE;

View File

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

View File

@ -20,5 +20,5 @@ BEGIN
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);
END;
$body$ LANGUAGE plpgsql;
$body$ LANGUAGE plpgsql STABLE;

View File

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

View File

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

View File

@ -57,6 +57,5 @@ BEGIN
END;
$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;
END;
$body$ LANGUAGE plpgsql;
$body$ LANGUAGE plpgsql STABLE;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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