File: gist_support.sql

package info (click to toggle)
pgsphere 1.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,220 kB
  • sloc: ansic: 13,926; sql: 6,895; cpp: 853; makefile: 278; perl: 168; yacc: 145; python: 106; lex: 55; xml: 51; sh: 1
file content (26 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download | duplicates (3)
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
-- spoint_dwithin function selectivity
set jit = off; -- suppress extra planning output

select explain('select * from spoint10k where spoint_dwithin(star, spoint(1,1), 1)');
select explain('select * from spoint10k where spoint_dwithin(star, spoint(1,1), .1)');
select explain('select * from spoint10k where spoint_dwithin(star, spoint(1,1), .01)');

select explain('select * from spoint10k where spoint_dwithin(spoint(1,1), star, 1)');
select explain('select * from spoint10k where spoint_dwithin(spoint(1,1), star, .1)');
select explain('select * from spoint10k where spoint_dwithin(spoint(1,1), star, .01)');

select explain('select * from spoint10k a join spoint10k b on spoint_dwithin(a.star, b.star, 1)', do_analyze := 'false');
select explain('select * from spoint10k a join spoint10k b on spoint_dwithin(a.star, b.star, .1)');
select explain('select * from spoint10k a join spoint10k b on spoint_dwithin(a.star, b.star, .01)');

-- spoint_dwithin is symmetric in the first two arguments
select explain('select * from spoint10k a join spoint10k b on spoint_dwithin(a.star, b.star, .01)
  where spoint_dwithin(a.star, spoint(1,1), .1)');
select explain('select * from spoint10k a join spoint10k b on spoint_dwithin(b.star, a.star, .01)
  where spoint_dwithin(a.star, spoint(1,1), .1)');

-- both sides indexable, check if the planner figures out the better choice
select explain('select * from spoint10k a join spoint10k b on spoint_dwithin(a.star, b.star, .01)
  where spoint_dwithin(a.star, spoint(1,1), .1) and spoint_dwithin(b.star, spoint(1,1), .05)');
select explain('select * from spoint10k a join spoint10k b on spoint_dwithin(a.star, b.star, .01)
  where spoint_dwithin(a.star, spoint(1,1), .05) and spoint_dwithin(b.star, spoint(1,1), .1)');