PostgreSQL 10 beta1 fails compile in gserialized_estimate
authorRegina Obe <lr@pcorp.us>
Sun, 21 May 2017 03:15:45 +0000 (03:15 +0000)
committerRegina Obe <lr@pcorp.us>
Sun, 21 May 2017 03:15:45 +0000 (03:15 +0000)
Revise to use new api for get_attstatsslot function for PostgreSQL >= 10
References #3758

git-svn-id: http://svn.osgeo.org/postgis/trunk@15398 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/gserialized_estimate.c

index 06180a7f1051e269745234ecba528a90dc541ded..760b521d290224dfafd064379e7e434ec8b32a97 100644 (file)
@@ -817,29 +817,50 @@ nd_increment(ND_IBOX *ibox, int ndims, int *counter)
 static ND_STATS*
 pg_nd_stats_from_tuple(HeapTuple stats_tuple, int mode)
 {
-  int stats_kind = STATISTIC_KIND_ND;
-  int rv, nvalues;
-       float4 *floatptr;
+       int stats_kind = STATISTIC_KIND_ND;
+       int rv;
        ND_STATS *nd_stats;
 
-  /* If we're in 2D mode, set the kind appropriately */
-  if ( mode == 2 ) stats_kind = STATISTIC_KIND_2D;
+       /* If we're in 2D mode, set the kind appropriately */
+       if ( mode == 2 ) stats_kind = STATISTIC_KIND_2D;
 
   /* Then read the geom status histogram from that */
-  rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid,
-                        NULL, NULL, NULL, &floatptr, &nvalues);
-  if ( ! rv ) {
-    POSTGIS_DEBUGF(2,
-            "no slot of kind %d in stats tuple", stats_kind);
-    return NULL;
-  }
+  
+#if POSTGIS_PGSQL_VERSION < 100
+       float4 *floatptr;
+       int nvalues;
        
-  /* Clone the stats here so we can release the attstatsslot immediately */
-  nd_stats = palloc(sizeof(float) * nvalues);
-  memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
-
-  /* Clean up */
-  free_attstatsslot(0, NULL, 0, floatptr, nvalues);
+       rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid,
+                                               NULL, NULL, NULL, &floatptr, &nvalues);
+       
+       if ( ! rv ) {
+               POSTGIS_DEBUGF(2,
+                               "no slot of kind %d in stats tuple", stats_kind);
+               return NULL;
+       }
+               
+       /* Clone the stats here so we can release the attstatsslot immediately */
+       nd_stats = palloc(sizeof(float) * nvalues);
+       memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
+       
+       /* Clean up */
+       free_attstatsslot(0, NULL, 0, floatptr, nvalues);
+#else /**10 or higher **/
+       AttStatsSlot sslot;
+       rv = get_attstatsslot(&sslot,stats_tuple, stats_kind, InvalidOid,
+                                                ATTSTATSSLOT_NUMBERS);
+       if ( ! rv ) {
+               POSTGIS_DEBUGF(2,
+                               "no slot of kind %d in stats tuple", stats_kind);
+               return NULL;
+       }
+       
+       /* Clone the stats here so we can release the attstatsslot immediately */
+       nd_stats = palloc(sizeof(float) * sslot.nnumbers);
+       memcpy(nd_stats,  sslot.numbers, sizeof(float) * sslot.nnumbers);
+       
+       free_attstatsslot(&sslot);
+#endif
 
   return nd_stats;
 }