From 81c3ebe03c229c980908502f3735cdf1636dd5cc Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 6 Aug 2021 00:15:40 +0100 Subject: [PATCH] Remove xid_to_int4 postgres function Fixes #3288 --- CONFIGURE.md | 1 - INSTALL.md | 1 - db/functions/Makefile | 2 +- db/functions/functions.sql | 31 ------------------------------- db/functions/xid_to_int4.c | 22 ---------------------- db/structure.sql | 28 ---------------------------- script/vagrant/setup/provision.sh | 1 - 7 files changed, 1 insertion(+), 85 deletions(-) delete mode 100644 db/functions/xid_to_int4.c diff --git a/CONFIGURE.md b/CONFIGURE.md index c165c6d46..f7638a49a 100644 --- a/CONFIGURE.md +++ b/CONFIGURE.md @@ -129,5 +129,4 @@ If you want to deploy The Rails Port for production use, you'll need to make a f * The included version of the map call is quite slow and eats a lot of memory. You should consider using [CGIMap](https://github.com/zerebubuth/openstreetmap-cgimap) instead. * Make sure you generate the i18n files and precompile the production assets: `RAILS_ENV=production rake i18n:js:export assets:precompile` * Make sure the web server user as well as the rails user can read, write and create directories in `tmp/`. -* If you want to use diff replication then you might want to consider installing the shared library special SQL functions for the `xid_to_int4` function. A pure SQL version is available, but may become a performance issue on large databases with a high rate of changes. Note that you will need a version of PostgreSQL < 9.6 (yes, _less than_) to use `xid` indexing, whether pure SQL or shared library. * If you expect to serve a lot of `/changes` API calls, then you might also want to install the shared library versions of the SQL functions. diff --git a/INSTALL.md b/INSTALL.md index c317c8a9d..1faf4bf22 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -278,7 +278,6 @@ Then we create the functions within each database. We're using `pwd` to substitu ``` psql -d openstreetmap -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '`pwd`/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT" -psql -d openstreetmap -c "CREATE FUNCTION xid_to_int4(xid) RETURNS int4 AS '`pwd`/db/functions/libpgosm', 'xid_to_int4' LANGUAGE C STRICT" ``` # Ruby development install and versions (optional) diff --git a/db/functions/Makefile b/db/functions/Makefile index 3fa4ae526..9388e2d23 100644 --- a/db/functions/Makefile +++ b/db/functions/Makefile @@ -16,7 +16,7 @@ all: ${DESTDIR}/libpgosm.so clean: $(RM) ${DESTDIR}/*.so ${DESTDIR}/*.o -${DESTDIR}/libpgosm.so: ${DESTDIR}/quadtile.o ${DESTDIR}/xid_to_int4.o +${DESTDIR}/libpgosm.so: ${DESTDIR}/quadtile.o cc ${LDFLAGS} -o $@ $^ ${DESTDIR}/%.o: %.c diff --git a/db/functions/functions.sql b/db/functions/functions.sql index 5e3d4bcb3..97e44f0ce 100644 --- a/db/functions/functions.sql +++ b/db/functions/functions.sql @@ -40,34 +40,3 @@ BEGIN RETURN (x << 1) | y; END; $$ LANGUAGE plpgsql IMMUTABLE; - - --- xid_to_int4 converts a PostgreSQL transaction ID (xid) to a 32-bit integer --- which can then be used to efficiently find rows which have changed between --- two given transactions. This is currently used by Osmosis to extract a --- stream of edits for "diff replication" **HOWEVER** this is a pain point, as --- (ab)using the xid in this way is _not_ supported or recommended by Postgres --- devs. It is preventing us upgrading to PostgreSQL version 10+, and will --- hopefully be replaced Real Soon Now. --- --- From the Osmosis distribution by Brett Henderson: --- https://github.com/openstreetmap/osmosis/blob/master/package/script/contrib/apidb_0.6_osmosis_xid_indexing.sql -CREATE OR REPLACE FUNCTION xid_to_int4(t xid) - RETURNS integer - AS -$$ -DECLARE - tl bigint; - ti int; -BEGIN - tl := t; - - IF tl >= 2147483648 THEN - tl := tl - 4294967296; - END IF; - - ti := tl; - - RETURN ti; -END; -$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; diff --git a/db/functions/xid_to_int4.c b/db/functions/xid_to_int4.c deleted file mode 100644 index e312b5f15..000000000 --- a/db/functions/xid_to_int4.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -Datum -xid_to_int4(PG_FUNCTION_ARGS) -{ - TransactionId xid = PG_GETARG_INT32(0); - - PG_RETURN_INT32(xid); -} - -PG_FUNCTION_INFO_V1(xid_to_int4); - -/* - * To bind this into PGSQL, try something like: - * - * CREATE FUNCTION xid_to_int4(xid) RETURNS int4 - * AS '/path/to/rails-port/db/functions/libpgosm', 'xid_to_int4' - * LANGUAGE C IMMUTABLE STRICT; - * - * (without all the *s) - */ diff --git a/db/structure.sql b/db/structure.sql index a45bb0a70..ccef53e17 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -147,34 +147,6 @@ END; $$; --- --- Name: xid_to_int4(xid); Type: FUNCTION; Schema: public; Owner: - --- - -CREATE FUNCTION public.xid_to_int4(t xid) RETURNS integer - LANGUAGE plpgsql IMMUTABLE STRICT - AS $$ -DECLARE - tl bigint; - ti int; -BEGIN - tl := t; - - IF tl >= 2147483648 THEN - tl := tl - 4294967296; - END IF; - - ti := tl; - - RETURN ti; -END; -$$; - - -SET default_tablespace = ''; - -SET default_table_access_method = heap; - -- -- Name: acls; Type: TABLE; Schema: public; Owner: - -- diff --git a/script/vagrant/setup/provision.sh b/script/vagrant/setup/provision.sh index e2cacfff3..680c17bc8 100644 --- a/script/vagrant/setup/provision.sh +++ b/script/vagrant/setup/provision.sh @@ -53,7 +53,6 @@ sudo -u vagrant psql -d openstreetmap -f db/functions/functions.sql #pushd db/functions #sudo -u vagrant make #sudo -u vagrant psql openstreetmap -c "CREATE OR REPLACE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'tile_for_point' LANGUAGE C STRICT" -#sudo -u vagrant psql openstreetmap -c "CREATE OR REPLACE FUNCTION xid_to_int4(xid) RETURNS int4 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'xid_to_int4' LANGUAGE C STRICT" #popd -- 2.43.2