source: other-projects/tipple-android/osmosis/script/contrib/apidb_0.6_osmosis_xid_indexing.sql@ 26899

Last change on this file since 26899 was 26899, checked in by davidb, 11 years ago

Tipple reborn after Chris's Summer of Code 2013

File size: 775 bytes
Line 
1-- This script creates a function and indexes that allow osmosis to efficiently query based on transaction ids.
2CREATE OR REPLACE FUNCTION xid_to_int4(t xid)
3 RETURNS integer AS
4$BODY$
5 DECLARE
6 tl bigint;
7 ti int;
8 BEGIN
9 tl := t;
10
11 IF tl >= 2147483648 THEN
12 tl := tl - 4294967296;
13 END IF;
14
15 ti := tl;
16
17 RETURN ti;
18 END;
19$BODY$
20LANGUAGE 'plpgsql' IMMUTABLE STRICT;
21
22
23DROP INDEX IF EXISTS nodes_xmin_idx;
24DROP INDEX IF EXISTS ways_xmin_idx;
25DROP INDEX IF EXISTS relations_xmin_idx;
26CREATE INDEX nodes_xmin_idx ON nodes USING btree ((xid_to_int4(xmin)));
27CREATE INDEX ways_xmin_idx ON ways USING btree ((xid_to_int4(xmin)));
28CREATE INDEX relations_xmin_idx ON relations USING btree ((xid_to_int4(xmin)));
Note: See TracBrowser for help on using the repository browser.