[postgis-tickets] r14750 - Revise script generation to exclude SQL functions that are NOT STRICT.

Regina Obe lr at pcorp.us
Fri Mar 4 21:37:32 PST 2016


Author: robe
Date: 2016-03-04 21:37:31 -0800 (Fri, 04 Mar 2016)
New Revision: 14750

Modified:
   trunk/extensions/postgis/Makefile.in
   trunk/postgis/Makefile.in
   trunk/raster/rt_pg/Makefile.in
   trunk/regress/run_test.pl
   trunk/utils/postgis_proc_set_search_path.pl
Log:
Revise script generation to exclude SQL functions that are NOT STRICT.
Integrate into testing
Integrate into create extension
References #3490 for PostGIS 2.3

Modified: trunk/extensions/postgis/Makefile.in
===================================================================
--- trunk/extensions/postgis/Makefile.in	2016-03-05 01:53:49 UTC (rev 14749)
+++ trunk/extensions/postgis/Makefile.in	2016-03-05 05:37:31 UTC (rev 14750)
@@ -37,7 +37,7 @@
 	
 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_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/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\;/" $< > $@
 
 

Modified: trunk/postgis/Makefile.in
===================================================================
--- trunk/postgis/Makefile.in	2016-03-05 01:53:49 UTC (rev 14749)
+++ trunk/postgis/Makefile.in	2016-03-05 05:37:31 UTC (rev 14750)
@@ -27,7 +27,7 @@
 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 @@
 
 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;" > $@

Modified: trunk/raster/rt_pg/Makefile.in
===================================================================
--- trunk/raster/rt_pg/Makefile.in	2016-03-05 01:53:49 UTC (rev 14749)
+++ trunk/raster/rt_pg/Makefile.in	2016-03-05 05:37:31 UTC (rev 14750)
@@ -24,7 +24,7 @@
 MODULEDIR=contrib/postgis- at POSTGIS_MAJOR_VERSION@. at 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 @@
 
 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;' > $@

Modified: trunk/regress/run_test.pl
===================================================================
--- trunk/regress/run_test.pl	2016-03-05 01:53:49 UTC (rev 14749)
+++ trunk/regress/run_test.pl	2016-03-05 05:37:31 UTC (rev 14750)
@@ -1317,6 +1317,7 @@
 	# 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 @@
 		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 )

Modified: trunk/utils/postgis_proc_set_search_path.pl
===================================================================
--- trunk/utils/postgis_proc_set_search_path.pl	2016-03-05 01:53:49 UTC (rev 14749)
+++ trunk/utils/postgis_proc_set_search_path.pl	2016-03-05 05:37:31 UTC (rev 14750)
@@ -98,6 +98,7 @@
 		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 @@
 		#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(<INPUT>)
+		{
+			$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 @@
 
 ## End of DO
 print 'END;';
-print '$$';
+print '$$;';
 
 __END__
  



More information about the postgis-tickets mailing list