Project

General

Profile

« Previous | Next » 

Revision 14208

fix: check_constraint_replace(): avoid re-running the constraint on all rows if expr hasn't changed

View differences:

trunk/schemas/util.sql
1057 1057
CREATE FUNCTION check_constraint_replace(def check_constraint_def) RETURNS void
1058 1058
    LANGUAGE sql
1059 1059
    AS $_$
1060
SELECT util.check_constraint_drop(def.constraint_);
1061
SELECT util.eval($$ALTER TABLE $$||(def).constraint_.table_
1060
SELECT CASE
1061
WHEN def.expr IS DISTINCT FROM util.check_constraint_expr(def.constraint_) THEN
1062
-- only re-run constraint on all rows if expr has changed
1063
(SELECT NULL::void FROM (SELECT
1064
util.check_constraint_drop(def.constraint_)
1065
,
1066
util.eval($$ALTER TABLE $$||(def).constraint_.table_
1062 1067
||$$ ADD CONSTRAINT $$||quote_ident((def).constraint_.name)
1063
||$$ CHECK ($$||def.expr||$$)$$);
1068
||$$ CHECK ($$||def.expr||$$)$$)
1069
) s)
1070
END
1064 1071
$_$;
1065 1072

  
1066 1073

  
1067 1074
--
1075
-- Name: FUNCTION check_constraint_replace(def check_constraint_def); Type: COMMENT; Schema: util; Owner: -
1076
--
1077

  
1078
COMMENT ON FUNCTION check_constraint_replace(def check_constraint_def) IS '
1079
idempotent, and avoids re-running constraint on all rows if expr hasn''t changed
1080
';
1081

  
1082

  
1083
--
1068 1084
-- Name: cluster(regclass, regclass); Type: FUNCTION; Schema: util; Owner: -
1069 1085
--
1070 1086

  

Also available in: Unified diff