-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueries
81 lines (47 loc) · 1.91 KB
/
queries
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
QUERIES
-------
select src,time,ST_AsText(position) from "PosReport"
where position && ST_MakeEnvelope(18.5, 69.38, 20.0, 69.88, 4326);
-------------------------------------------------
select r.src, r.time, position
from "AprsPacket" p, "PosReport" r
where p.src=r.src and p.time=r.rtime and substring(p.path, '([^,\*]+).*\*.*')='LD9TT';
-- May add limit on time span
-- May add limit on geographical area and index on position
-- Select distinct position
select distinct ST_AsText(position)
from "AprsPacket" p, "PosReport" r
where p.src=r.src
and p.time=r.rtime
and (substring(p.path, '([^,\*]+).*\*.*')='LD9TT' OR substring(p.ipath, 'qAR,([^,\*]+).*')='LD9TT')
AND position && ST_MakeEnvelope(18.5, 69.38, 20.0, 69.88, 4326)
and p.time > '2012-10-25 00:00:00';
---------------------------------------------------
create view igate as
select substring (ipath from '(q..),.*') as q, substring(ipath from 'q..,(.+),?.*') as igate, count(*)
from "AprsPacket"
group by q,igate;
---------------------------------------------------
create view firstdigi as
select src,substring(path from '([^,\*]+).*\*.*') as firstdigi, count(*)
from "AprsPacket"
group by src,firstdigi;
-- May add limit on time span
-- Last / first time heard?
INDEXES
-------
create index firstpath_idx on "AprsPacket" (substring(path, '([^,\*]+).*\*.*'));
-- Improvement 5-6 X
create index ipath_idx on "AprsPacket" (substring(ipath, 'qAR,([^,\*]+).*'));
-- Improvement > 20 X
create index posreport_time_src_idx on "PosReport" (time,src);
-- Great improvement > 20X. Similar index because of primary key constraint doesn't seem to help.
create index posreport_rtime_idx on "PosReport" (rtime);
-- Improvement > 10X.
create index geoindex on "PosReport" USING GIST (position);
-- Works!
To maintain it:
VACUUM ANALYZE "PosReport" (position);
FUNCTIONS
---------
ST_MakeEnvelope(xmin, ymin, xmax, ymax, SRID)