From: Regina Obe Date: Sat, 5 Mar 2016 05:37:31 +0000 (+0000) Subject: Revise script generation to exclude SQL functions that are NOT STRICT. X-Git-Tag: 2.3.0beta1~183 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68ad685a85f9f45db9b4ced666bff4187de852fd;p=postgis Revise script generation to exclude SQL functions that are NOT STRICT. Integrate into testing Integrate into create extension References #3490 for PostGIS 2.3 git-svn-id: http://svn.osgeo.org/postgis/trunk@14750 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/extensions/postgis/Makefile.in b/extensions/postgis/Makefile.in index e7c93c512..53cb09c8d 100644 --- a/extensions/postgis/Makefile.in +++ b/extensions/postgis/Makefile.in @@ -37,7 +37,7 @@ ifeq ($(PG91),yes) all: sql/$(EXTENSION)--$(EXTVERSION).sql sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql sql/$(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql sql/$(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql sql_minor_upgrade -sql/$(EXTENSION).sql: sql_bits/postgis.sql sql_bits/postgis_comments.sql sql_bits/rtpostgis.sql sql_bits/spatial_ref_sys_config_dump.sql sql_bits/raster_comments.sql sql_bits/spatial_ref_sys.sql +sql/$(EXTENSION).sql: sql_bits/postgis.sql sql_bits/postgis_proc_set_search_path.sql sql_bits/postgis_comments.sql sql_bits/rtpostgis.sql sql_bits/rtpostgis_proc_set_search_path.sql sql_bits/spatial_ref_sys_config_dump.sql sql_bits/raster_comments.sql sql_bits/spatial_ref_sys.sql mkdir -p sql echo '\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \quit' > $@ cat $^ >> $@ @@ -70,6 +70,12 @@ sql_bits/postgis.sql: ../../postgis/postgis.sql sql_bits/postgis_comments.sql: ../../doc/postgis_comments.sql cp $< $@ + +sql_bits/postgis_proc_set_search_path.sql: ../../postgis/postgis_proc_set_search_path.sql + cp $< $@ + +sql_bits/rtpostgis_proc_set_search_path.sql: ../../raster/rt_pg/rtpostgis_proc_set_search_path.sql + cp $< $@ #strip BEGIN/COMMIT since these are not allowed in extensions sql_bits/rtpostgis.sql: ../../raster/rt_pg/rtpostgis.sql @@ -78,10 +84,10 @@ sql_bits/rtpostgis.sql: ../../raster/rt_pg/rtpostgis.sql sql_bits/spatial_ref_sys_config_dump.sql: ../../spatial_ref_sys.sql ../../utils/create_spatial_ref_sys_config_dump.pl ../../utils/create_spatial_ref_sys_config_dump.pl $< > $@ -sql_bits/rtpostgis_upgrade.sql: ../../raster/rt_pg/rtpostgis_upgrade.sql +sql_bits/rtpostgis_upgrade.sql: ../../raster/rt_pg/rtpostgis_upgrade.sql sql_bits/rtpostgis_proc_set_search_path.sql $(PERL) -pe "s/BEGIN\;//g ; s/COMMIT\;//g; s/^(DROP .*)\;/SELECT postgis_extension_drop_if_exists('$(EXTENSION)', '\1');\n\1\;/" $< > $@ -sql_bits/postgis_upgrade.sql: ../../postgis/postgis_upgrade.sql +sql_bits/postgis_upgrade.sql: ../../postgis/postgis_upgrade.sql sql_bits/postgis_proc_set_search_path.sql $(PERL) -pe "s/BEGIN\;//g ; s/COMMIT\;//g; s/^(DROP .*)\;/SELECT postgis_extension_drop_if_exists('$(EXTENSION)', '\1');\n\1\;/" $< > $@ diff --git a/postgis/Makefile.in b/postgis/Makefile.in index 603094bc4..6a176a1e7 100644 --- a/postgis/Makefile.in +++ b/postgis/Makefile.in @@ -27,7 +27,7 @@ MODULE_big=postgis-@POSTGIS_MAJOR_VERSION@.@POSTGIS_MINOR_VERSION@ MODULEDIR=contrib/$(MODULE_big) # Files to be copied to the contrib/ directory -SQL_built=postgis.sql uninstall_postgis.sql postgis_upgrade.sql legacy.sql uninstall_legacy.sql legacy_minimal.sql legacy_gist.sql +SQL_built=postgis.sql uninstall_postgis.sql postgis_upgrade.sql postgis_proc_set_search_path.sql legacy.sql uninstall_legacy.sql legacy_minimal.sql legacy_gist.sql DATA=../spatial_ref_sys.sql # SQL objects (files requiring pre-processing) @@ -173,6 +173,9 @@ $(PG_OBJS): ../liblwgeom/.libs/liblwgeom.a ../libpgcommon/libpgcommon.a ../postg postgis_upgrade.sql.in: postgis.sql ../utils/postgis_proc_upgrade.pl $(PERL) ../utils/postgis_proc_upgrade.pl $< UNUSED > $@ + +postgis_proc_set_search_path.sql: postgis.sql ../utils/postgis_proc_set_search_path.pl + $(PERL) ../utils/postgis_proc_set_search_path.pl $< UNUSED > $@ postgis_upgrade.sql: postgis_drop_before.sql postgis_upgrade.sql.in postgis_drop_after.sql echo "BEGIN;" > $@ diff --git a/raster/rt_pg/Makefile.in b/raster/rt_pg/Makefile.in index ce08dd4d1..9503caa81 100644 --- a/raster/rt_pg/Makefile.in +++ b/raster/rt_pg/Makefile.in @@ -24,7 +24,7 @@ MODULE_big=rtpostgis-@POSTGIS_MAJOR_VERSION@.@POSTGIS_MINOR_VERSION@ MODULEDIR=contrib/postgis-@POSTGIS_MAJOR_VERSION@.@POSTGIS_MINOR_VERSION@ # Files to be copied to the contrib/ directory -DATA_built=rtpostgis.sql rtpostgis_upgrade.sql uninstall_rtpostgis.sql rtpostgis_legacy.sql +DATA_built=rtpostgis.sql rtpostgis_upgrade.sql rtpostgis_proc_set_search_path.sql uninstall_rtpostgis.sql rtpostgis_legacy.sql DATA= # SQL preprocessor @@ -122,6 +122,9 @@ $(SQL_OBJS): ../../postgis/sqldefines.h ../../postgis_svn_revision.h rtpostgis_upgrade.sql.in: rtpostgis.sql ../../utils/postgis_proc_upgrade.pl $(PERL) ../../utils/postgis_proc_upgrade.pl $< UNUSED > $@ + +rtpostgis_proc_set_search_path.sql: rtpostgis.sql ../../utils/postgis_proc_set_search_path.pl + $(PERL) ../../utils/postgis_proc_set_search_path.pl $< UNUSED > $@ rtpostgis_upgrade.sql: rtpostgis_upgrade_cleanup.sql rtpostgis_upgrade.sql.in rtpostgis_drop.sql echo 'BEGIN;' > $@ diff --git a/regress/run_test.pl b/regress/run_test.pl index 05435f132..2613089c5 100755 --- a/regress/run_test.pl +++ b/regress/run_test.pl @@ -1317,6 +1317,7 @@ sub prepare_spatial # Load postgis.sql into the database load_sql_file("${STAGED_SCRIPTS_DIR}/postgis.sql", 1); load_sql_file("${STAGED_SCRIPTS_DIR}/postgis_comments.sql", 0); + load_sql_file("${STAGED_SCRIPTS_DIR}/postgis_proc_set_search_path.sql", 0); if ( $OPT_WITH_TOPO ) { @@ -1330,6 +1331,7 @@ sub prepare_spatial print "Loading Raster into '${DB}'\n"; load_sql_file("${STAGED_SCRIPTS_DIR}/rtpostgis.sql", 1); load_sql_file("${STAGED_SCRIPTS_DIR}/raster_comments.sql", 0); + load_sql_file("${STAGED_SCRIPTS_DIR}/rtpostgis_proc_set_search_path.sql", 0); } if ( $OPT_WITH_SFCGAL ) diff --git a/utils/postgis_proc_set_search_path.pl b/utils/postgis_proc_set_search_path.pl index 93c27b94d..206d3927b 100644 --- a/utils/postgis_proc_set_search_path.pl +++ b/utils/postgis_proc_set_search_path.pl @@ -98,6 +98,7 @@ while() my $funchead = $1; #contains function header except the end ) my $endhead = 0; my $endfunchead = $2; + my $search_path_safe = 0; # we can put a search path on it without disrupting spatial index use if ($2 eq ')') ## reached end of header { $endhead = 1; @@ -129,8 +130,25 @@ while() #strip off default args from the function header $funchead =~ s/(default\s+[A-Za-z\.\+\-0-9\'\[\]\:\s]*)//ig; + #check to see if function is STRICT or c or plpgsql + # we can't put search path on non-STRICT sql since search path breaks SQL inlining + # breaking sql inlining will break use of spatial index + my $endfunc = 0; + while() + { + $endfunc = 1 if /^\s*(\$\$\s*)?LANGUAGE /i; + if ( $endfunc == 1 ){ + $search_path_safe = 1 if /LANGUAGE\s+[\']*(c|plpgsql)/i; + $search_path_safe = 1 if /STRICT/i; + } + last if ( $endfunc && /\;/ ); + } - print "EXECUTE 'ALTER FUNCTION $funchead $endfunchead SET search_path=' || quote_ident(param_postgis_schema) || ';';\n"; + + if ($search_path_safe == 1) + { + print "EXECUTE 'ALTER FUNCTION $funchead $endfunchead SET search_path=' || quote_ident(param_postgis_schema) || ';';\n"; + } } } @@ -139,7 +157,7 @@ close( INPUT ); ## End of DO print 'END;'; -print '$$'; +print '$$;'; __END__