-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_gist_indexes.sql
89 lines (85 loc) · 3.78 KB
/
create_gist_indexes.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
DO
$$DECLARE
v_database varchar := 'roads';
v_schema varchar := 'roads';
v_table varchar := 'motorwayjunction';
v_column varchar := 'geom';
v_type varchar := 'GIST';
v_index_name varchar := 'idx_geom_motorwayjunction';
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = v_index_name AND n.nspname = v_schema) THEN
RAISE INFO 'Adding index %', v_index_name;
-- E.g. CREATE INDEX idx_name_btree ON foo.bar USING btree(name);
EXECUTE 'CREATE INDEX ' || v_index_name || ' ON ' || v_schema || '.' || v_table || ' USING ' || v_type || '(' || v_column || ');';
ELSE
RAISE INFO 'INDEX % already exists on table %.%', v_index_name, v_schema, v_table;
END IF;
END$$;
DO
$$DECLARE
v_database varchar := 'roads';
v_schema varchar := 'roads';
v_table varchar := 'roadnode';
v_column varchar := 'geom';
v_type varchar := 'GIST';
v_index_name varchar := 'idx_geom_roadnode';
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = v_index_name AND n.nspname = v_schema) THEN
RAISE INFO 'Adding index %', v_index_name;
-- E.g. CREATE INDEX idx_name_btree ON foo.bar USING btree(name);
EXECUTE 'CREATE INDEX ' || v_index_name || ' ON ' || v_schema || '.' || v_table || ' USING ' || v_type || '(' || v_column || ');';
ELSE
RAISE INFO 'INDEX % already exists on table %.%', v_index_name, v_schema, v_table;
END IF;
END$$;
DO
$$DECLARE
v_database varchar := 'roads';
v_schema varchar := 'roads';
v_table varchar := 'roadlink';
v_column varchar := 'geom';
v_type varchar := 'GIST';
v_index_name varchar := 'idx_geom_roadlink';
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = v_index_name AND n.nspname = v_schema) THEN
RAISE INFO 'Adding index %', v_index_name;
-- E.g. CREATE INDEX idx_name_btree ON foo.bar USING btree(name);
EXECUTE 'CREATE INDEX ' || v_index_name || ' ON ' || v_schema || '.' || v_table || ' USING ' || v_type || '(' || v_column || ');';
ELSE
RAISE INFO 'INDEX % already exists on table %.%', v_index_name, v_schema, v_table;
END IF;
END$$;
DO
$$DECLARE
v_database varchar := 'roads';
v_schema varchar := 'roads';
v_table varchar := 'roadlink';
v_column varchar := 'identifier';
v_type varchar := 'btree';
v_index_name varchar := 'idx_identifier_roadlink';
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = v_index_name AND n.nspname = v_schema) THEN
RAISE INFO 'Adding index %', v_index_name;
-- E.g. CREATE INDEX idx_name_btree ON foo.bar USING btree(name);
EXECUTE 'CREATE INDEX ' || v_index_name || ' ON ' || v_schema || '.' || v_table || ' USING ' || v_type || '(' || v_column || ');';
ELSE
RAISE INFO 'INDEX % already exists on table %.%', v_index_name, v_schema, v_table;
END IF;
END$$;
DO
$$DECLARE
v_database varchar := 'roads';
v_schema varchar := 'roads';
v_table varchar := 'roadlink';
v_column varchar := 'name1';
v_type varchar := 'btree';
v_index_name varchar := 'idx_name1_roadlink';
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = v_index_name AND n.nspname = v_schema) THEN
RAISE INFO 'Adding index %', v_index_name;
-- E.g. CREATE INDEX idx_name_btree ON foo.bar USING btree(name);
EXECUTE 'CREATE INDEX ' || v_index_name || ' ON ' || v_schema || '.' || v_table || ' USING ' || v_type || '(' || v_column || ');';
ELSE
RAISE INFO 'INDEX % already exists on table %.%', v_index_name, v_schema, v_table;
END IF;
END$$;