-
Notifications
You must be signed in to change notification settings - Fork 2
/
points.sql
106 lines (81 loc) · 2.64 KB
/
points.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
-- create table name variable
SELECT 'pts_' || :'npoints' AS table_name
\gset
-- create a first experiment
INSERT INTO
experiments(table_name, geom_type, ngeoms, test_area)
VALUES (
:'table_name', 'Point', :npoints, ST_GeomFromWKB(:'test_area', 4326)
)
RETURNING id AS exp_id
\gset
-- check how fast the point generation is
CALL create_point_test_wo_index(:exp_id);
-- create matching procedure name
SELECT 'st_intersects_' || :'table_name' AS avg_st_intersects_100_runs
\gset
-- how fast are queries without an index
CALL :"avg_st_intersects_100_runs"(:exp_id, NULL);
-- do tests with GIST index
SELECT :'table_name' || '_gist' AS gist_index
\gset
-- check GIST index creation speed on filled table
CALL create_spatial_index(:exp_id, 'gist');
-- test performance of this GIST index
\i test_gist.sql
-- check GIST index creation speed when inserting data
CALL create_point_test_w_index(:exp_id, 'gist');
-- test performance of this GIST index
\i test_gist.sql
-- do tests with sp-GIST index
SELECT :'table_name' || '_spgist' AS spgist_index
\gset
-- create table again for sp-GIST tests
CALL create_point_test_wo_index(:exp_id);
-- check sp-GIST index creation speed on filled table
CALL create_spatial_index(:exp_id, 'spgist');
-- test performance of this sp-GIST index
\i test_spgist.sql
-- check sp-GIST index creation speed when inserting data
CALL create_point_test_w_index(:exp_id, 'spgist');
-- test performance of this sp-GIST index
\i test_spgist.sql
-- recreate the table once more
CALL create_point_test_wo_index(:exp_id);
-- now cluster the database on behalf of a GeoHash ordering
-- first create the index
CALL create_spatial_index(:exp_id, 'btree', 'ST_GeoHash');
-- set BTREE name
SELECT :'table_name' || '_btree' AS geohash_index
\gset
-- remember starting time for clustering
SELECT extract(epoch FROM clock_timestamp()) AS start_time
\gset
CLUSTER :"table_name" USING :"geohash_index";
INSERT INTO
query_stats
VALUES (
nextval('query_stats_id_seq'),
'CLUSTER TABLE geohash',
NULL,
NULL,
NULL,
false,
true,
(extract(epoch FROM clock_timestamp()) - :start_time) * 1000,
:exp_id
);
-- do one more tests with a GIST index
CALL create_spatial_index(:exp_id, 'gist');
VACUUM ANALYSE :"table_name" (geom);
CALL :"avg_st_intersects_100_runs"(:exp_id, 'gist', NULL, true, true);
DROP INDEX :"gist_index";
-- do one more tests with a sp-GIST index
CALL create_spatial_index(:exp_id, 'spgist');
VACUUM ANALYSE :"table_name" (geom);
CALL :"avg_st_intersects_100_runs"(:exp_id, 'spgist', NULL, true, true);
DROP INDEX :"spgist_index";
-- now, test the BRIN index
\i test_brin.sql
-- time for next test, so drop table
DROP TABLE :"table_name" CASCADE;