]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move procedure to new file
authorAlan T. DeKok <aland@freeradius.org>
Thu, 28 Feb 2019 16:16:37 +0000 (11:16 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 3 Mar 2019 13:32:27 +0000 (08:32 -0500)
It's better to have a different file than to ask the admin
to un-comment lots of code.

raddb/mods-config/sql/ippool/postgresql/procedure.sql [new file with mode: 0644]
raddb/mods-config/sql/ippool/postgresql/queries.conf
raddb/mods-config/sql/ippool/postgresql/schema.sql

diff --git a/raddb/mods-config/sql/ippool/postgresql/procedure.sql b/raddb/mods-config/sql/ippool/postgresql/procedure.sql
new file mode 100644 (file)
index 0000000..e68160d
--- /dev/null
@@ -0,0 +1,57 @@
+--
+-- Use the following indexes and function if using the stored procedure to
+-- find the previously used address.
+--
+-- You may wish to set the ORDER BY expiry_time to DESC for the first two
+-- queries in order to assign the address that the user had most recently,
+-- instead of assigning the oldest address the user had used.
+--
+
+CREATE INDEX radippool_pool_name ON radippool USING btree (pool_name);
+CREATE INDEX radippool_username ON radippool USING btree (username);
+CREATE INDEX radippool_callingstationid ON radippool USING btree (callingstationid);
+
+CREATE OR REPLACE FUNCTION find_previous_or_new_framedipaddress (
+       v_pool_name VARCHAR(64),
+       v_username VARCHAR(64),
+       v_callingstationid VARCHAR(64)
+)
+RETURNS inet
+LANGUAGE plpgsql
+AS $$
+DECLARE
+       r_address inet;
+BEGIN
+       SELECT framedipaddress INTO r_address
+       FROM radippool
+       WHERE radippool.pool_name = v_pool_name
+               AND radippool.expiry_time < 'now'::timestamp(0)
+               AND radippool.username = v_username
+               AND radippool.callingstationid = v_callingstationid
+       ORDER BY expiry_time
+       LIMIT 1
+       FOR UPDATE SKIP LOCKED;
+       IF r_address <> NULL THEN
+               RETURN r_address;
+       END IF;
+ SELECT framedipaddress INTO r_address
+       FROM radippool
+       WHERE radippool.pool_name = v_pool_name
+               AND radippool.expiry_time < 'now'::timestamp(0)
+               AND radippool.username = v_username
+       ORDER BY expiry_time
+       LIMIT 1
+       FOR UPDATE SKIP LOCKED;
+       IF r_address <> NULL THEN
+               RETURN r_address;
+       END IF;
+ SELECT framedipaddress INTO r_address
+       FROM radippool
+       WHERE radippool.pool_name = v_pool_name
+               AND radippool.expiry_time < 'now'::timestamp(0)
+       ORDER BY expiry_time
+       LIMIT 1
+       FOR UPDATE SKIP LOCKED;
+       RETURN r_address;
+END
+$$;
index fbf59f4cd09f1be19cf97fb66e7934d63b62c23d..560bdb4b05349b7655576f75eaa0c08100ed2d27 100644 (file)
@@ -29,7 +29,8 @@ allocate_find = "\
 
 #
 #  Use a stored procedure to find the address. This requires PostgreSQL >= 9.5 as
-#  SKIP LOCKED is used.
+#  SKIP LOCKED is used.  See `procedure.sql` in this directory for the
+#  indices and stored procedure used by this query.
 #
 # allocate_find = "\
 #  SELECT find_previous_or_new_framedipaddress( \
index 66591725bed9928250c44bd5c2959ae561f7ac6c..37a3599d18776c820482610ffe208a622f7a128b 100644 (file)
@@ -1,6 +1,9 @@
 --
 -- Table structure for table 'radippool'
 --
+-- See also "procedure.sql" in this directory for additional
+-- indices and a stored procedure that is much faster.
+--
 
 CREATE TABLE radippool (
        id                      BIGSERIAL PRIMARY KEY,
@@ -17,62 +20,3 @@ CREATE TABLE radippool (
 CREATE INDEX radippool_poolname_expire ON radippool USING btree (pool_name, expiry_time);
 CREATE INDEX radippool_framedipaddress ON radippool USING btree (framedipaddress);
 CREATE INDEX radippool_nasip_poolkey_ipaddress ON radippool USING btree (nasipaddress, pool_key, framedipaddress);
-
-
---
--- Use the following indexes and function if using the stored procedure to
--- find the previously used address.
---
--- You may wish to set the ORDER BY expiry_time to DESC for the first two
--- queries in order to assign the address that the user last had, rather
--- than the oldest address the user had.
---
-
--- CREATE INDEX radippool_pool_name ON radippool USING btree (pool_name);
--- CREATE INDEX radippool_username ON radippool USING btree (username);
--- CREATE INDEX radippool_callingstationid ON radippool USING btree (callingstationid);
-
--- CREATE OR REPLACE FUNCTION find_previous_or_new_framedipaddress (
---     v_pool_name VARCHAR(64),
---     v_username VARCHAR(64),
---     v_callingstationid VARCHAR(64)
--- )
--- RETURNS inet
--- LANGUAGE plpgsql
--- AS $$
--- DECLARE
---     r_address inet;
--- BEGIN
---     SELECT framedipaddress INTO r_address
---             FROM radippool
---             WHERE radippool.pool_name = v_pool_name
---                     AND radippool.expiry_time < 'now'::timestamp(0)
---                     AND radippool.username = v_username
---                     AND radippool.callingstationid = v_callingstationid
---             ORDER BY expiry_time
---             LIMIT 1
---             FOR UPDATE SKIP LOCKED;
---     IF r_address <> NULL THEN
---             RETURN r_address;
---     END IF;
---  SELECT framedipaddress INTO r_address
---             FROM radippool
---             WHERE radippool.pool_name = v_pool_name
---                     AND radippool.expiry_time < 'now'::timestamp(0)
---                     AND radippool.username = v_username
---             ORDER BY expiry_time
---             LIMIT 1
---             FOR UPDATE SKIP LOCKED;
---     IF r_address <> NULL THEN
---             RETURN r_address;
---     END IF;
---  SELECT framedipaddress INTO r_address
---             FROM radippool
---             WHERE radippool.pool_name = v_pool_name
---                     AND radippool.expiry_time < 'now'::timestamp(0)
---             ORDER BY expiry_time
---             LIMIT 1
---             FOR UPDATE SKIP LOCKED;
---     RETURN r_address;
--- END
--- $$;