Project

General

Profile

« Previous | Next » 

Revision 14242

fix: schemas/util.sql: check_constraint_expr_disable(): need to use CASE instead of `true OR ` because OR always evaluates both sides, slowing down constraint evaluation

View differences:

util.sql
1086 1086
CREATE FUNCTION check_constraint_enabled(constraint_def check_constraint_def) RETURNS boolean
1087 1087
    LANGUAGE sql STABLE
1088 1088
    AS $_$
1089
SELECT NOT /*disabled*/util.starts_with($$true OR $$, constraint_def.expr)
1089
SELECT NOT /*disabled*/util.starts_with($$CASE WHEN true THEN true ELSE $$,
1090
constraint_def.expr)
1090 1091
$_$;
1091 1092

  
1092 1093

  
......
1120 1121
CREATE FUNCTION check_constraint_expr_disable(expr text) RETURNS text
1121 1122
    LANGUAGE sql IMMUTABLE
1122 1123
    AS $_$
1123
SELECT $$true OR $$||expr
1124
-- always returns true, but stores the expr for later use
1125
-- can't use `true OR ` because OR always evaluates both sides
1126
SELECT $$CASE WHEN true THEN true ELSE $$||expr||$$ END$$
1124 1127
$_$;
1125 1128

  
1126 1129

  
......
1132 1135
    LANGUAGE sql IMMUTABLE
1133 1136
    AS $_$
1134 1137
-- **IMPORTANT**: need to remove the enclosing () to be consistent everywhere
1135
SELECT util.trim_parens(util.remove_prefix($$true OR $$, util.trim_parens(expr),
1136
require:= false))
1138
SELECT util.trim_parens(
1139
util.remove_prefix($$CASE WHEN true THEN true ELSE $$,
1140
util.remove_suffix($$ END$$,
1141
util.trim_parens(expr), require := false), require := false))
1137 1142
$_$;
1138 1143

  
1139 1144

  

Also available in: Unified diff