Yedidyah Bar David has uploaded a new change for review. Change subject: db: add a common function for index creation ......................................................................
db: add a common function for index creation This patch adds a common function that drop the index if exists and creates it after that. This is done in order to prevent scripts failures when the index is not dropped and an attempt to re-create it is done Change-Id: I6e6e2577ceac435e25030dfde6ff6c4c3f8a7278 Signed-off-by: Eli Mesika <[email protected]> (cherry picked from commit d65b5293b48d552d90cc4dbf44d2c09769548906) --- M packaging/dbscripts/common_sp.sql 1 file changed, 19 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/95/35195/1 diff --git a/packaging/dbscripts/common_sp.sql b/packaging/dbscripts/common_sp.sql index 3a1178d..18951ac 100644 --- a/packaging/dbscripts/common_sp.sql +++ b/packaging/dbscripts/common_sp.sql @@ -421,6 +421,25 @@ END; $procedure$ LANGUAGE plpgsql; +-- Creates an index on an existing table, if there is no WHERE condition, the last argument should be empty ('') +-- Example : Table T with columns a,b and c +-- fn_db_create_index('T_INDEX', 'T', 'a,b', ''); ==> Creates an index named T_INDEX on table T (a,b) +create or replace FUNCTION fn_db_create_index(v_index_name varchar(128), v_table_name varchar(128), v_column_names text, v_where_predicate text) +returns void +AS $procedure$ +DECLARE + v_sql TEXT; +BEGIN + v_sql := 'DROP INDEX ' || ' IF EXISTS ' || v_index_name || '; CREATE INDEX ' || v_index_name || ' ON ' || v_table_name || '(' || v_column_names || ')'; + IF v_where_predicate = '' THEN + v_sql := v_sql || ';'; + ELSE + v_sql := v_sql || ' WHERE ' || v_where_predicate || ';'; + END IF; + EXECUTE v_sql; +END; $procedure$ +LANGUAGE plpgsql; + -- Unlocks a specific disk create or replace FUNCTION fn_db_unlock_disk(v_id UUID) returns void -- To view, visit http://gerrit.ovirt.org/35195 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6e6e2577ceac435e25030dfde6ff6c4c3f8a7278 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Yedidyah Bar David <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
