From e1d087579d7258b601af742070bdf1c06c468a93 Mon Sep 17 00:00:00 2001 From: David Blasby Date: Wed, 22 Jan 2003 17:07:39 +0000 Subject: [PATCH] applied Mark Cave-Ayland's new patch that is a bit cleaner and has a user-defined FETCH limit for creating a histogram. git-svn-id: http://svn.osgeo.org/postgis/trunk@232 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis_estimate.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/postgis_estimate.c b/postgis_estimate.c index 47c5fa3ab..4e487d576 100644 --- a/postgis_estimate.c +++ b/postgis_estimate.c @@ -302,6 +302,7 @@ Datum build_histogram2d(PG_FUNCTION_ARGS) int sum_area_numb_new =0; int bump=0; + int tuplimit = 500000; // No. of tuples returned on each cursor fetch bool moredata; void *SPIplan; void *SPIportal; @@ -336,8 +337,8 @@ Datum build_histogram2d(PG_FUNCTION_ARGS) columnname = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_DATUM(2)))); - elog(NOTICE,"Start build_histogram2d with %i items already existing", sum_area_numb); - elog(NOTICE,"table=\"%s\", column = \"%s\"", tablename, columnname); + //elog(NOTICE,"Start build_histogram2d with %i items already existing", sum_area_numb); + //elog(NOTICE,"table=\"%s\", column = \"%s\"", tablename, columnname); SPIcode = SPI_connect(); @@ -352,7 +353,6 @@ Datum build_histogram2d(PG_FUNCTION_ARGS) sprintf(sql,"SELECT box(\"%s\") FROM \"%s\"",columnname,tablename); //elog(NOTICE,"executing %s",sql); - //SPIcode = SPI_exec(sql, 2147483640 ); // max signed int32 SPIplan = SPI_prepare(sql, 0, NULL); if (SPIplan == NULL) @@ -368,19 +368,21 @@ Datum build_histogram2d(PG_FUNCTION_ARGS) PG_RETURN_NULL() ; } - //elog(NOTICE,"processing %i records",SPI_processed); + moredata = TRUE; - while (moredata==TRUE) { - SPI_cursor_fetch(SPIportal, TRUE, 50000); + //elog(NOTICE,"about to fetch..."); + SPI_cursor_fetch(SPIportal, TRUE, tuplimit); - tuptable = SPI_tuptable; - tupdesc = SPI_tuptable->tupdesc; ntuples = SPI_processed; + //elog(NOTICE,"processing %d records", ntuples); if (ntuples > 0) { + tuptable = SPI_tuptable; + tupdesc = SPI_tuptable->tupdesc; + cell_area = ( (xmax-xmin)*(ymax-ymin)/(histo->boxesPerSide*histo->boxesPerSide) ); for (t=0;t 0 @@ -473,7 +479,7 @@ Datum build_histogram2d(PG_FUNCTION_ARGS) PG_RETURN_NULL() ; } - // elog(NOTICE,"finishing up build_histogram2d "); + //elog(NOTICE,"finishing up build_histogram2d "); //pfree(tablename); //pfree(columnname);