Increase search space of ids by 100x #305

This commit is contained in:
Rafa de la Torre 2017-06-29 17:54:42 +02:00
parent 8db73ae9bd
commit ffb779eb74

View File

@ -1,3 +1,7 @@
-- Create a sequence that belongs to the schema of the extension.
-- It will be used to generate unique identifiers within the
-- UTF8 safe and length aware. Find a unique identifier with a given prefix -- UTF8 safe and length aware. Find a unique identifier with a given prefix
-- and/or suffix and withing a schema. If a schema is not specified, the identifier -- and/or suffix and withing a schema. If a schema is not specified, the identifier
-- is guaranteed to be unique for all schemas. -- is guaranteed to be unique for all schemas.
@ -15,8 +19,8 @@ DECLARE
i INTEGER; i INTEGER;
BEGIN BEGIN
-- Accounts for the _XX incremental suffix in case the identifier is taken -- Accounts for the XXXX incremental suffix in case the identifier is taken
usedspace := 3; usedspace := 4;
usedspace := usedspace + coalesce(octet_length(prefix), 0); usedspace := usedspace + coalesce(octet_length(prefix), 0);
usedspace := usedspace + coalesce(octet_length(suffix), 0); usedspace := usedspace + coalesce(octet_length(suffix), 0);
@ -31,7 +35,7 @@ BEGIN
i := 0; i := 0;
origident := ident; origident := ident;
WHILE i < 100 LOOP WHILE i < 10000 LOOP
IF schema IS NOT NULL THEN IF schema IS NOT NULL THEN
SELECT c.relname, n.nspname SELECT c.relname, n.nspname
INTO rec INTO rec
@ -51,7 +55,7 @@ BEGIN
RETURN ident; RETURN ident;
END IF; END IF;
ident := origident || '_' || i; ident := origident || i;
i := i + 1; i := i + 1;
END LOOP; END LOOP;
@ -76,8 +80,8 @@ DECLARE
i INTEGER; i INTEGER;
BEGIN BEGIN
-- Accounts for the _XX incremental suffix in case the identifier is taken -- Accounts for the XXXX incremental suffix in case the identifier is taken
usedspace := 3; usedspace := 4;
usedspace := usedspace + coalesce(octet_length(prefix), 0); usedspace := usedspace + coalesce(octet_length(prefix), 0);
usedspace := usedspace + coalesce(octet_length(suffix), 0); usedspace := usedspace + coalesce(octet_length(suffix), 0);
@ -92,7 +96,7 @@ BEGIN
i := 0; i := 0;
origident := ident; origident := ident;
WHILE i < 100 LOOP WHILE i < 10000 LOOP
SELECT a.attname SELECT a.attname
INTO rec INTO rec
FROM pg_class c FROM pg_class c
@ -106,7 +110,7 @@ BEGIN
RETURN ident; RETURN ident;
END IF; END IF;
ident := origident || '_' || i; ident := origident || i;
i := i + 1; i := i + 1;
END LOOP; END LOOP;