Created
August 19, 2016 23:23
-
-
Save charmander/688ba405cdfdcbe62528053d808b4c5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test=> CREATE TABLE points (id serial PRIMARY KEY, p point NOT NULL); | |
CREATE TABLE | |
test=> CREATE INDEX ON points USING GIST (p); | |
CREATE INDEX | |
test=> INSERT INTO points (p) VALUES ('1,1'), ('1,0'), ('0,1'), ('0,0.5'), ('0,2'); | |
INSERT 0 5 | |
test=> SELECT * FROM points ORDER BY p <-> '0,0' LIMIT 3; | |
id | p | |
----+--------- | |
4 | (0,0.5) | |
2 | (1,0) | |
3 | (0,1) | |
(3 rows) | |
test=> EXPLAIN SELECT * FROM points ORDER BY p <-> '0,0' LIMIT 3; | |
QUERY PLAN | |
-------------------------------------------------------------------------------------- | |
Limit (cost=0.14..0.28 rows=3 width=20) | |
-> Index Scan using points_p_idx on points (cost=0.14..78.14 rows=1700 width=20) | |
Order By: (p <-> '(0,0)'::point) | |
(3 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment