Skip to content

Commit fd0cdeb

Browse files
Maksim MilyutinMaksim Milyutin
Maksim Milyutin
authored and
Maksim Milyutin
committed
Replace multiplication ops on multiple additions
1 parent e710bbf commit fd0cdeb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

range.sql

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ DECLARE
9191
v_rows_count INTEGER;
9292
v_max p_start_value%TYPE;
9393
v_cur_value p_start_value%TYPE := p_start_value;
94+
p_end_value p_start_value%TYPE;
9495
i INTEGER;
9596

9697
BEGIN
@@ -132,12 +133,19 @@ BEGIN
132133
* and specifies partition count as 0 then do not check boundaries
133134
*/
134135
IF p_count != 0 THEN
136+
/* compute right bound of partitioning through additions */
137+
p_end_value := p_start_value;
138+
FOR i IN 1..p_count
139+
LOOP
140+
p_end_value := p_end_value + p_interval;
141+
END LOOP;
142+
135143
/* Check boundaries */
136144
EXECUTE format('SELECT @extschema@.check_boundaries(''%s'', ''%s'', ''%s'', ''%s''::%s)',
137145
parent_relid,
138146
p_attribute,
139147
p_start_value,
140-
p_start_value + p_interval * p_count,
148+
p_end_value,
141149
pg_typeof(p_start_value));
142150
END IF;
143151

@@ -190,6 +198,7 @@ DECLARE
190198
v_rows_count INTEGER;
191199
v_max p_start_value%TYPE;
192200
v_cur_value p_start_value%TYPE := p_start_value;
201+
p_end_value p_start_value%TYPE;
193202
i INTEGER;
194203

195204
BEGIN
@@ -235,11 +244,18 @@ BEGIN
235244
* and specifies partition count as 0 then do not check boundaries
236245
*/
237246
IF p_count != 0 THEN
247+
/* compute right bound of partitioning through additions */
248+
p_end_value := p_start_value;
249+
FOR i IN 1..p_count
250+
LOOP
251+
p_end_value := p_end_value + p_interval;
252+
END LOOP;
253+
238254
/* check boundaries */
239255
PERFORM @extschema@.check_boundaries(parent_relid,
240256
p_attribute,
241257
p_start_value,
242-
p_start_value + p_interval * p_count);
258+
p_end_value);
243259
END IF;
244260

245261
/* Create sequence for child partitions names */

0 commit comments

Comments
 (0)